2023-07-27 14:31:52 +09: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-02-27 11:07:39 +09:00
|
|
|
import { checkWordMute } from '@/misc/check-word-mute.js';
|
2022-06-27 14:48:10 +02:00
|
|
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { isInstanceMuted } from '@/misc/is-instance-muted.js';
|
2023-03-10 14:22:37 +09:00
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
2022-12-04 15:03:09 +09:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import Channel from '../channel.js';
|
2018-10-07 11:06:17 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
class HomeTimelineChannel extends Channel {
|
2018-10-11 23:01:57 +09:00
|
|
|
public readonly chName = 'homeTimeline';
|
2018-10-11 23:07:20 +09:00
|
|
|
public static shouldShare = true;
|
2018-11-11 02:22:34 +09:00
|
|
|
public static requireCredential = true;
|
2023-09-28 11:41:41 +09:00
|
|
|
private withRenotes: boolean;
|
2018-10-11 23:01:57 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
|
|
|
|
id: string,
|
|
|
|
connection: Channel['connection'],
|
|
|
|
) {
|
2022-02-27 11:07:39 +09:00
|
|
|
super(id, connection);
|
2022-12-04 15:03:09 +09:00
|
|
|
//this.onNote = this.onNote.bind(this);
|
2022-02-27 11:07:39 +09:00
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2018-10-07 11:06:17 +09:00
|
|
|
public async init(params: any) {
|
2023-09-28 11:41:41 +09:00
|
|
|
this.withRenotes = params.withRenotes ?? true;
|
2023-07-08 07:08:16 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
this.subscriber.on('notesStream', this.onNote);
|
2018-10-07 11:06:17 +09:00
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2021-09-22 22:35:55 +09:00
|
|
|
private async onNote(note: Packed<'Note'>) {
|
2020-08-18 22:44:21 +09:00
|
|
|
if (note.channelId) {
|
2021-01-30 05:39:46 +03:30
|
|
|
if (!this.followingChannels.has(note.channelId)) return;
|
2020-08-18 22:44:21 +09:00
|
|
|
} else {
|
|
|
|
// その投稿のユーザーをフォローしていなかったら弾く
|
2023-10-03 20:26:11 +09:00
|
|
|
if ((this.user!.id !== note.userId) && !Object.hasOwn(this.following, note.userId)) return;
|
2020-08-18 22:44:21 +09:00
|
|
|
}
|
2019-04-07 21:50:36 +09:00
|
|
|
|
2021-12-09 12:38:56 +00:00
|
|
|
// Ignore notes from instances the user has muted
|
2023-04-05 10:21:10 +09:00
|
|
|
if (isInstanceMuted(note, new Set<string>(this.userProfile!.mutedInstances ?? []))) return;
|
2021-12-09 12:38:56 +00:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
if (['followers', 'specified'].includes(note.visibility)) {
|
2022-09-18 03:27:08 +09:00
|
|
|
note = await this.noteEntityService.pack(note.id, this.user!, {
|
2021-12-09 23:58:30 +09:00
|
|
|
detail: true,
|
2018-10-07 11:06:17 +09:00
|
|
|
});
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
if (note.isHidden) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// リプライなら再pack
|
|
|
|
if (note.replyId != null) {
|
2022-09-18 03:27:08 +09:00
|
|
|
note.reply = await this.noteEntityService.pack(note.replyId, this.user!, {
|
2021-12-09 23:58:30 +09:00
|
|
|
detail: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Renoteなら再pack
|
|
|
|
if (note.renoteId != null) {
|
2022-09-18 03:27:08 +09:00
|
|
|
note.renote = await this.noteEntityService.pack(note.renoteId, this.user!, {
|
2021-12-09 23:58:30 +09:00
|
|
|
detail: true,
|
2019-04-07 21:50:36 +09:00
|
|
|
});
|
|
|
|
}
|
2018-10-07 11:06:17 +09:00
|
|
|
}
|
|
|
|
|
2020-02-13 22:13:24 +09:00
|
|
|
// 関係ない返信は除外
|
2023-10-03 20:26:11 +09:00
|
|
|
if (note.reply && !this.following[note.userId]?.withReplies) {
|
2021-09-12 01:12:23 +09:00
|
|
|
const reply = note.reply;
|
2020-02-13 22:13:24 +09:00
|
|
|
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
|
2021-03-24 11:05:37 +09:00
|
|
|
if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
|
2020-02-13 22:13:24 +09:00
|
|
|
}
|
|
|
|
|
2023-09-28 11:41:41 +09:00
|
|
|
if (note.renote && note.text == null && (note.fileIds == null || note.fileIds.length === 0) && !this.withRenotes) return;
|
|
|
|
|
2018-10-07 11:06:17 +09:00
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
|
2023-04-05 10:21:10 +09:00
|
|
|
if (isUserRelated(note, this.userIdsWhoMeMuting)) return;
|
2021-08-17 21:48:59 +09:00
|
|
|
// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
|
2023-04-05 10:21:10 +09:00
|
|
|
if (isUserRelated(note, this.userIdsWhoBlockingMe)) return;
|
2018-10-07 11:06:17 +09:00
|
|
|
|
2023-04-05 10:21:10 +09:00
|
|
|
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
2023-03-08 08:56:09 +09:00
|
|
|
|
2021-03-21 17:38:09 +09:00
|
|
|
this.connection.cacheNote(note);
|
|
|
|
|
2018-10-07 11:06:17 +09:00
|
|
|
this.send('note', note);
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2018-10-07 11:06:17 +09:00
|
|
|
public dispose() {
|
|
|
|
// Unsubscribe events
|
2019-04-07 21:50:36 +09:00
|
|
|
this.subscriber.off('notesStream', this.onNote);
|
2018-10-07 11:06:17 +09:00
|
|
|
}
|
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class HomeTimelineChannelService {
|
|
|
|
public readonly shouldShare = HomeTimelineChannel.shouldShare;
|
|
|
|
public readonly requireCredential = HomeTimelineChannel.requireCredential;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2022-09-18 03:27:08 +09:00
|
|
|
public create(id: string, connection: Channel['connection']): HomeTimelineChannel {
|
|
|
|
return new HomeTimelineChannel(
|
|
|
|
this.noteEntityService,
|
|
|
|
id,
|
|
|
|
connection,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|