2020-01-29 20:37:25 +01:00
|
|
|
import autobind from 'autobind-decorator';
|
2021-08-19 14:55:45 +02:00
|
|
|
import Channel from '../channel';
|
|
|
|
import { Notes } from '@/models/index';
|
|
|
|
import { isMutedUserRelated } from '@/misc/is-muted-user-related';
|
|
|
|
import { isBlockerUserRelated } from '@/misc/is-blocker-user-related';
|
2021-10-20 18:04:10 +02:00
|
|
|
import { StreamMessages } from '../types';
|
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
|
2021-10-20 18:04:10 +02:00
|
|
|
private async onEvent(data: StreamMessages['antenna']['payload']) {
|
|
|
|
if (data.type === 'note') {
|
|
|
|
const note = await Notes.pack(data.body.id, this.user, { detail: true });
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2020-07-28 02:36:43 +02:00
|
|
|
if (isMutedUserRelated(note, this.muting)) return;
|
2021-08-17 14:48:59 +02:00
|
|
|
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
|
|
|
|
if (isBlockerUserRelated(note, this.blocking)) return;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2021-03-21 09:38:09 +01:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
this.send('note', note);
|
|
|
|
} else {
|
2021-10-20 18:04:10 +02:00
|
|
|
this.send(data.type, data.body);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
|
|
|
this.subscriber.off(`antennaStream:${this.antennaId}`, this.onEvent);
|
|
|
|
}
|
|
|
|
}
|