2022-02-27 02:07:39 +00:00
|
|
|
import { Notes } from '@/models/index.js';
|
2022-06-27 12:48:10 +00:00
|
|
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
2022-05-24 08:00:46 +00:00
|
|
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
2022-08-03 11:18:33 +00:00
|
|
|
import { StreamMessages } from '../types.js';
|
|
|
|
import Channel from '../channel.js';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
|
|
|
export default class extends Channel {
|
|
|
|
public readonly chName = 'antenna';
|
|
|
|
public static shouldShare = false;
|
|
|
|
public static requireCredential = false;
|
|
|
|
private antennaId: string;
|
|
|
|
|
2022-02-27 02:07:39 +00:00
|
|
|
constructor(id: string, connection: Channel['connection']) {
|
|
|
|
super(id, connection);
|
|
|
|
this.onEvent = this.onEvent.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
public async init(params: any) {
|
|
|
|
this.antennaId = params.antennaId as string;
|
|
|
|
|
|
|
|
// Subscribe stream
|
|
|
|
this.subscriber.on(`antennaStream:${this.antennaId}`, this.onEvent);
|
|
|
|
}
|
|
|
|
|
2021-10-20 16:04:10 +00:00
|
|
|
private async onEvent(data: StreamMessages['antenna']['payload']) {
|
|
|
|
if (data.type === 'note') {
|
2022-05-24 08:00:46 +00:00
|
|
|
try {
|
|
|
|
const note = await Notes.pack(data.body.id, this.user, { detail: true });
|
|
|
|
|
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
|
|
|
if (isUserRelated(note, this.muting)) return;
|
|
|
|
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
|
|
|
|
if (isUserRelated(note, this.blocking)) return;
|
2022-10-07 19:45:28 +00:00
|
|
|
if (note.renote && this.renoteMuting.has(note.userId)) return;
|
2022-10-06 23:20:38 +00:00
|
|
|
|
2022-05-24 08:00:46 +00:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
|
|
|
|
this.send('note', note);
|
|
|
|
} catch (e) {
|
|
|
|
if (e instanceof IdentifiableError && e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') {
|
|
|
|
// skip: note not visible to user
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
} else {
|
2021-10-20 16:04:10 +00:00
|
|
|
this.send(data.type, data.body);
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
|
|
|
this.subscriber.off(`antennaStream:${this.antennaId}`, this.onEvent);
|
|
|
|
}
|
|
|
|
}
|