iceshrimp/src/server/api/stream/channels/antenna.ts

47 lines
1.4 KiB
TypeScript
Raw Normal View History

import autobind from 'autobind-decorator';
import Channel from '../channel.js';
import { Notes } from '@/models/index.js';
import { isMutedUserRelated } from '@/misc/is-muted-user-related.js';
import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js';
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 09:36:43 +09:00
if (isMutedUserRelated(note, this.muting)) return;
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
if (isBlockerUserRelated(note, this.blocking)) return;
2021-03-21 17:38:09 +09:00
this.connection.cacheNote(note);
this.send('note', note);
} else {
this.send(type, body);
}
}
@autobind
public dispose() {
// Unsubscribe events
this.subscriber.off(`antennaStream:${this.antennaId}`, this.onEvent);
}
}