2020-01-29 20:37:25 +01:00
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import Channel from '../channel';
|
|
|
|
import { Notes } from '../../../../models';
|
2020-07-28 02:36:43 +02:00
|
|
|
import { isMutedUserRelated } from '../../../../misc/is-muted-user-related';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export default class extends Channel {
|
|
|
|
public readonly chName = 'antenna';
|
|
|
|
public static shouldShare = false;
|
|
|
|
public static requireCredential = false;
|
|
|
|
private antennaId: string;
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
public async init(params: any) {
|
|
|
|
this.antennaId = params.antennaId as string;
|
|
|
|
|
|
|
|
// Subscribe stream
|
|
|
|
this.subscriber.on(`antennaStream:${this.antennaId}`, this.onEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
private async onEvent(data: any) {
|
|
|
|
const { type, body } = data;
|
|
|
|
|
|
|
|
if (type === 'note') {
|
|
|
|
const note = await Notes.pack(body.id, this.user, { detail: true });
|
|
|
|
|
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2020-07-28 02:36:43 +02:00
|
|
|
if (isMutedUserRelated(note, this.muting)) return;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
this.send('note', note);
|
|
|
|
} else {
|
|
|
|
this.send(type, body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
|
|
|
this.subscriber.off(`antennaStream:${this.antennaId}`, this.onEvent);
|
|
|
|
}
|
|
|
|
}
|