2023-07-27 14:31:52 +09:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-16 23:09:41 +09:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-06-27 21:48:10 +09:00
|
|
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
2022-12-04 15:03:09 +09:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import Channel from '../channel.js';
|
|
|
|
import type { StreamMessages } from '../types.js';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
class AntennaChannel extends Channel {
|
2020-01-30 04:37:25 +09:00
|
|
|
public readonly chName = 'antenna';
|
|
|
|
public static shouldShare = false;
|
|
|
|
public static requireCredential = false;
|
|
|
|
private antennaId: string;
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
|
|
|
|
id: string,
|
|
|
|
connection: Channel['connection'],
|
|
|
|
) {
|
2022-02-27 11:07:39 +09:00
|
|
|
super(id, connection);
|
2022-12-04 15:03:09 +09:00
|
|
|
//this.onEvent = this.onEvent.bind(this);
|
2022-02-27 11:07:39 +09:00
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2020-01-30 04:37:25 +09:00
|
|
|
public async init(params: any) {
|
|
|
|
this.antennaId = params.antennaId as string;
|
|
|
|
|
|
|
|
// Subscribe stream
|
|
|
|
this.subscriber.on(`antennaStream:${this.antennaId}`, this.onEvent);
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2021-10-21 01:04:10 +09:00
|
|
|
private async onEvent(data: StreamMessages['antenna']['payload']) {
|
|
|
|
if (data.type === 'note') {
|
2022-09-18 03:27:08 +09:00
|
|
|
const note = await this.noteEntityService.pack(data.body.id, this.user, { detail: true });
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2023-04-05 10:21:10 +09:00
|
|
|
if (isUserRelated(note, this.userIdsWhoMeMuting)) return;
|
2021-08-17 21:48:59 +09:00
|
|
|
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
|
2023-04-05 10:21:10 +09:00
|
|
|
if (isUserRelated(note, this.userIdsWhoBlockingMe)) return;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-04-05 10:21:10 +09:00
|
|
|
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
2023-03-08 08:56:09 +09:00
|
|
|
|
2021-03-21 17:38:09 +09:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
this.send('note', note);
|
|
|
|
} else {
|
2021-10-21 01:04:10 +09:00
|
|
|
this.send(data.type, data.body);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2020-01-30 04:37:25 +09:00
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
|
|
|
this.subscriber.off(`antennaStream:${this.antennaId}`, this.onEvent);
|
|
|
|
}
|
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AntennaChannelService {
|
|
|
|
public readonly shouldShare = AntennaChannel.shouldShare;
|
|
|
|
public readonly requireCredential = AntennaChannel.requireCredential;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2022-09-18 03:27:08 +09:00
|
|
|
public create(id: string, connection: Channel['connection']): AntennaChannel {
|
|
|
|
return new AntennaChannel(
|
|
|
|
this.noteEntityService,
|
|
|
|
id,
|
|
|
|
connection,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|