parent
037837b551
commit
0e4a111f81
1714 changed files with 20803 additions and 11751 deletions
45
packages/backend/src/server/api/stream/channels/antenna.ts
Normal file
45
packages/backend/src/server/api/stream/channels/antenna.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import autobind from 'autobind-decorator';
|
||||
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';
|
||||
import { StreamMessages } from '../types';
|
||||
|
||||
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: StreamMessages['antenna']['payload']) {
|
||||
if (data.type === 'note') {
|
||||
const note = await Notes.pack(data.body.id, this.user, { detail: true });
|
||||
|
||||
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
||||
if (isMutedUserRelated(note, this.muting)) return;
|
||||
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
|
||||
if (isBlockerUserRelated(note, this.blocking)) return;
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
||||
this.send('note', note);
|
||||
} else {
|
||||
this.send(data.type, data.body);
|
||||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
public dispose() {
|
||||
// Unsubscribe events
|
||||
this.subscriber.off(`antennaStream:${this.antennaId}`, this.onEvent);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue