2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-02-16 15:09:41 +01:00
|
|
|
import { Injectable } from '@nestjs/common';
|
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';
|
2024-04-17 14:23:41 +09:00
|
|
|
import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
|
2023-12-27 15:08:59 +09:00
|
|
|
import Channel, { type MiChannelService } 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';
|
2023-10-08 13:46:02 +09:00
|
|
|
public static shouldShare = false;
|
2023-12-27 15:08:59 +09:00
|
|
|
public static requireCredential = true as const;
|
|
|
|
public static kind = 'read:account';
|
2023-09-28 11:41:41 +09:00
|
|
|
private withRenotes: boolean;
|
2023-10-09 17:48:09 +09:00
|
|
|
private withFiles: 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-10-09 17:48:09 +09:00
|
|
|
this.withFiles = params.withFiles ?? false;
|
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'>) {
|
2023-10-20 08:02:32 +09:00
|
|
|
const isMe = this.user!.id === note.userId;
|
|
|
|
|
2023-10-09 17:48:09 +09:00
|
|
|
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
|
|
|
|
|
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-20 08:02:32 +09:00
|
|
|
if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
|
2020-08-18 22:44:21 +09:00
|
|
|
}
|
2019-04-07 21:50:36 +09:00
|
|
|
|
2023-10-15 10:36:22 +09:00
|
|
|
if (note.visibility === 'followers') {
|
2023-10-20 08:02:32 +09:00
|
|
|
if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
|
2023-10-15 10:36:22 +09:00
|
|
|
} else if (note.visibility === 'specified') {
|
2023-10-31 15:27:20 +09:00
|
|
|
if (!isMe && !note.visibleUserIds!.includes(this.user!.id)) return;
|
2018-10-07 11:06:17 +09:00
|
|
|
}
|
|
|
|
|
2023-10-23 15:29:42 +09:00
|
|
|
if (note.reply) {
|
2021-09-12 01:12:23 +09:00
|
|
|
const reply = note.reply;
|
2023-10-23 15:29:42 +09:00
|
|
|
if (this.following[note.userId]?.withReplies) {
|
|
|
|
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
|
|
|
|
if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId)) return;
|
|
|
|
} else {
|
|
|
|
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
|
|
|
|
if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
|
|
|
|
}
|
2020-02-13 22:13:24 +09:00
|
|
|
}
|
|
|
|
|
2024-02-28 17:43:17 +09:00
|
|
|
// 純粋なリノート(引用リノートでないリノート)の場合
|
2024-04-17 14:23:41 +09:00
|
|
|
if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
|
2024-02-28 17:43:17 +09:00
|
|
|
if (!this.withRenotes) return;
|
|
|
|
if (note.renote.reply) {
|
|
|
|
const reply = note.renote.reply;
|
|
|
|
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
|
|
|
|
if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId)) return;
|
|
|
|
}
|
|
|
|
}
|
2023-09-28 11:41:41 +09:00
|
|
|
|
2024-04-17 14:23:41 +09:00
|
|
|
if (this.isNoteMutedOrBlocked(note)) return;
|
2023-03-08 08:56:09 +09:00
|
|
|
|
2024-04-17 14:23:41 +09:00
|
|
|
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
|
2023-10-19 07:56:25 +09:00
|
|
|
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
2023-10-19 09:20:19 +09:00
|
|
|
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
2023-10-19 07:59:58 +09:00
|
|
|
note.renote.myReaction = myRenoteReaction;
|
2023-10-19 07:56:25 +09:00
|
|
|
}
|
2023-10-15 10:36:22 +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()
|
2023-12-27 15:08:59 +09:00
|
|
|
export class HomeTimelineChannelService implements MiChannelService<true> {
|
2022-09-18 03:27:08 +09:00
|
|
|
public readonly shouldShare = HomeTimelineChannel.shouldShare;
|
|
|
|
public readonly requireCredential = HomeTimelineChannel.requireCredential;
|
2023-12-27 15:08:59 +09:00
|
|
|
public readonly kind = HomeTimelineChannel.kind;
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|