2023-07-27 05:31:52 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-16 14:09:41 +00:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { checkWordMute } from '@/misc/check-word-mute.js';
|
2022-06-27 12:48:10 +00:00
|
|
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
2023-03-10 05:22:37 +00:00
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import { MetaService } from '@/core/MetaService.js';
|
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
2022-12-04 06:03:09 +00:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-01-12 12:02:26 +00:00
|
|
|
import { RoleService } from '@/core/RoleService.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
import Channel from '../channel.js';
|
2018-10-07 02:06:17 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
class LocalTimelineChannel extends Channel {
|
2018-10-11 14:01:57 +00:00
|
|
|
public readonly chName = 'localTimeline';
|
2018-10-11 14:07:20 +00:00
|
|
|
public static shouldShare = true;
|
2018-11-10 17:22:34 +00:00
|
|
|
public static requireCredential = false;
|
2023-05-16 03:16:37 +00:00
|
|
|
private withReplies: boolean;
|
2023-09-28 02:41:41 +00:00
|
|
|
private withRenotes: boolean;
|
2018-10-11 14:01:57 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
constructor(
|
|
|
|
private metaService: MetaService,
|
2023-01-12 12:02:26 +00:00
|
|
|
private roleService: RoleService,
|
2022-09-17 18:27:08 +00:00
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
|
|
|
|
id: string,
|
|
|
|
connection: Channel['connection'],
|
|
|
|
) {
|
2022-02-27 02:07:39 +00:00
|
|
|
super(id, connection);
|
2022-12-04 06:03:09 +00:00
|
|
|
//this.onNote = this.onNote.bind(this);
|
2022-02-27 02:07:39 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2018-10-07 02:06:17 +00:00
|
|
|
public async init(params: any) {
|
2023-01-15 11:52:53 +00:00
|
|
|
const policies = await this.roleService.getUserPolicies(this.user ? this.user.id : null);
|
|
|
|
if (!policies.ltlAvailable) return;
|
2019-01-15 17:30:55 +00:00
|
|
|
|
2023-09-28 02:41:41 +00:00
|
|
|
this.withReplies = params.withReplies ?? false;
|
|
|
|
this.withRenotes = params.withRenotes ?? true;
|
2023-05-16 03:16:37 +00:00
|
|
|
|
2018-10-07 02:06:17 +00:00
|
|
|
// Subscribe events
|
2019-04-07 12:50:36 +00:00
|
|
|
this.subscriber.on('notesStream', this.onNote);
|
2018-10-07 02:06:17 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2021-09-22 13:35:55 +00:00
|
|
|
private async onNote(note: Packed<'Note'>) {
|
2021-09-11 16:12:23 +00:00
|
|
|
if (note.user.host !== null) return;
|
2019-11-23 23:31:57 +00:00
|
|
|
if (note.visibility !== 'public') return;
|
2021-01-30 02:09:46 +00:00
|
|
|
if (note.channelId != null && !this.followingChannels.has(note.channelId)) return;
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2019-11-23 23:31:57 +00:00
|
|
|
// リプライなら再pack
|
|
|
|
if (note.replyId != null) {
|
2022-09-17 18:27:08 +00:00
|
|
|
note.reply = await this.noteEntityService.pack(note.replyId, this.user, {
|
2021-12-09 14:58:30 +00:00
|
|
|
detail: true,
|
2019-11-23 23:31:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Renoteなら再pack
|
|
|
|
if (note.renoteId != null) {
|
2022-09-17 18:27:08 +00:00
|
|
|
note.renote = await this.noteEntityService.pack(note.renoteId, this.user, {
|
2021-12-09 14:58:30 +00:00
|
|
|
detail: true,
|
2018-10-07 02:06:17 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-13 13:13:24 +00:00
|
|
|
// 関係ない返信は除外
|
2023-05-16 03:16:37 +00:00
|
|
|
if (note.reply && this.user && !this.withReplies) {
|
2021-09-11 16:12:23 +00:00
|
|
|
const reply = note.reply;
|
2020-02-13 13:13:24 +00:00
|
|
|
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
|
2023-04-09 08:01:03 +00:00
|
|
|
if (reply.userId !== this.user.id && note.userId !== this.user.id && reply.userId !== note.userId) return;
|
2020-02-13 13:13:24 +00:00
|
|
|
}
|
|
|
|
|
2023-09-28 02:41:41 +00:00
|
|
|
if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
|
|
|
|
|
2018-10-07 02:06:17 +00:00
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2023-04-05 01:21:10 +00:00
|
|
|
if (isUserRelated(note, this.userIdsWhoMeMuting)) return;
|
2021-08-17 12:48:59 +00:00
|
|
|
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
|
2023-04-05 01:21:10 +00:00
|
|
|
if (isUserRelated(note, this.userIdsWhoBlockingMe)) return;
|
2018-10-07 02:06:17 +00:00
|
|
|
|
2023-04-05 01:21:10 +00:00
|
|
|
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
2023-03-07 23:56:09 +00:00
|
|
|
|
2020-07-27 04:34:20 +00:00
|
|
|
// 流れてきたNoteがミュートすべきNoteだったら無視する
|
|
|
|
// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)
|
|
|
|
// 現状では、ワードミュートにおけるMutedNoteレコードの追加処理はストリーミングに流す処理と並列で行われるため、
|
|
|
|
// レコードが追加されるNoteでも追加されるより先にここのストリーミングの処理に到達することが起こる。
|
|
|
|
// そのためレコードが存在するかのチェックでは不十分なので、改めてcheckWordMuteを呼んでいる
|
|
|
|
if (this.userProfile && await checkWordMute(note, this.user, this.userProfile.mutedWords)) return;
|
|
|
|
|
2021-03-21 08:38:09 +00:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
|
2018-10-07 02:06:17 +00:00
|
|
|
this.send('note', note);
|
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2018-10-07 02:06:17 +00:00
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
2019-04-07 12:50:36 +00:00
|
|
|
this.subscriber.off('notesStream', this.onNote);
|
2018-10-07 02:06:17 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-17 18:27:08 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class LocalTimelineChannelService {
|
|
|
|
public readonly shouldShare = LocalTimelineChannel.shouldShare;
|
|
|
|
public readonly requireCredential = LocalTimelineChannel.requireCredential;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private metaService: MetaService,
|
2023-01-12 12:02:26 +00:00
|
|
|
private roleService: RoleService,
|
2022-09-17 18:27:08 +00:00
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
public create(id: string, connection: Channel['connection']): LocalTimelineChannel {
|
|
|
|
return new LocalTimelineChannel(
|
|
|
|
this.metaService,
|
2023-01-12 12:02:26 +00:00
|
|
|
this.roleService,
|
2022-09-17 18:27:08 +00:00
|
|
|
this.noteEntityService,
|
|
|
|
id,
|
|
|
|
connection,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|