2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2023-02-16 15:09:41 +01:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-06-27 14:48:10 +02:00
|
|
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
2023-03-10 06:22:37 +01:00
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
2022-12-04 07:03:09 +01:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import Channel from '../channel.js';
|
2020-08-18 15:44:21 +02:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
class ChannelChannel extends Channel {
|
2020-08-18 15:44:21 +02:00
|
|
|
public readonly chName = 'channel';
|
|
|
|
|
public static shouldShare = false;
|
|
|
|
|
public static requireCredential = false;
|
|
|
|
|
private channelId: string;
|
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
constructor(
|
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
|
|
|
|
|
|
id: string,
|
|
|
|
|
connection: Channel['connection'],
|
|
|
|
|
) {
|
2022-02-27 03:07:39 +01:00
|
|
|
super(id, connection);
|
2022-12-04 07:03:09 +01:00
|
|
|
//this.onNote = this.onNote.bind(this);
|
2022-02-27 03:07:39 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2020-08-18 15:44:21 +02:00
|
|
|
public async init(params: any) {
|
|
|
|
|
this.channelId = params.channelId as string;
|
|
|
|
|
|
|
|
|
|
// Subscribe stream
|
|
|
|
|
this.subscriber.on('notesStream', this.onNote);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2021-09-22 15:35:55 +02:00
|
|
|
private async onNote(note: Packed<'Note'>) {
|
2020-08-18 15:44:21 +02:00
|
|
|
if (note.channelId !== this.channelId) return;
|
|
|
|
|
|
|
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2023-04-05 03:21:10 +02:00
|
|
|
if (isUserRelated(note, this.userIdsWhoMeMuting)) return;
|
2021-08-17 14:48:59 +02:00
|
|
|
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
|
2023-04-05 03:21:10 +02:00
|
|
|
if (isUserRelated(note, this.userIdsWhoBlockingMe)) return;
|
2020-08-18 15:44:21 +02:00
|
|
|
|
2023-04-05 03:21:10 +02:00
|
|
|
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
2023-03-08 00:56:09 +01:00
|
|
|
|
2023-10-15 03:36:22 +02:00
|
|
|
if (this.user && note.renoteId && !note.text) {
|
2023-10-19 00:56:25 +02:00
|
|
|
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
|
|
|
|
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
|
|
|
|
note.renote!.myReaction = myRenoteReaction;
|
|
|
|
|
}
|
2023-10-15 03:36:22 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-21 09:38:09 +01:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
|
|
2020-08-18 15:44:21 +02:00
|
|
|
this.send('note', note);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2020-08-18 15:44:21 +02:00
|
|
|
public dispose() {
|
|
|
|
|
// Unsubscribe events
|
|
|
|
|
this.subscriber.off('notesStream', this.onNote);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class ChannelChannelService {
|
|
|
|
|
public readonly shouldShare = ChannelChannel.shouldShare;
|
|
|
|
|
public readonly requireCredential = ChannelChannel.requireCredential;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2022-09-17 20:27:08 +02:00
|
|
|
public create(id: string, connection: Channel['connection']): ChannelChannel {
|
|
|
|
|
return new ChannelChannel(
|
|
|
|
|
this.noteEntityService,
|
|
|
|
|
id,
|
|
|
|
|
connection,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|