From 83460279c0217096f95225b6ceff5393c8a439d4 Mon Sep 17 00:00:00 2001 From: piuvas Date: Mon, 23 Dec 2024 10:50:31 -0300 Subject: populate myreaction on replies for streams. --- packages/backend/src/server/api/stream/channels/bubble-timeline.ts | 7 +++++++ packages/backend/src/server/api/stream/channels/global-timeline.ts | 7 +++++++ packages/backend/src/server/api/stream/channels/home-timeline.ts | 7 +++++++ packages/backend/src/server/api/stream/channels/hybrid-timeline.ts | 7 +++++++ packages/backend/src/server/api/stream/channels/local-timeline.ts | 7 +++++++ 5 files changed, 35 insertions(+) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index 8693f0c6ac..b8cbe4f283 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -72,6 +72,13 @@ class BubbleTimelineChannel extends Channel { } } + if (this.user && note.reply) { + if (Object.keys(note.reply.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myRenoteReaction; + } + } + this.connection.cacheNote(note); this.send('note', note); diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index 6fe76747ee..43aa99e8c4 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -67,6 +67,13 @@ class GlobalTimelineChannel extends Channel { } } + if (this.user && note.reply) { + if (Object.keys(note.reply.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myRenoteReaction; + } + } + this.connection.cacheNote(note); this.send('note', note); diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index 359ab3e223..05040b9099 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -88,6 +88,13 @@ class HomeTimelineChannel extends Channel { } } + if (this.user && note.reply) { + if (Object.keys(note.reply.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myRenoteReaction; + } + } + this.connection.cacheNote(note); this.send('note', note); diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 01645fe657..b268904f04 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -106,6 +106,13 @@ class HybridTimelineChannel extends Channel { } } + if (this.user && note.reply) { + if (Object.keys(note.reply.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myRenoteReaction; + } + } + this.connection.cacheNote(note); this.send('note', note); diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 1f9d25b44d..8d75a0c3a2 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -77,6 +77,13 @@ class LocalTimelineChannel extends Channel { } } + if (this.user && note.reply) { + if (Object.keys(note.reply.reactions).length > 0) { + const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myRenoteReaction; + } + } + this.connection.cacheNote(note); this.send('note', note); -- cgit v1.2.3-freya From 94c3a71e499f8d508dfd1e49727d6a2d04031873 Mon Sep 17 00:00:00 2001 From: piuvas Date: Mon, 23 Dec 2024 20:42:21 -0300 Subject: improvements. --- .../backend/src/server/api/stream/channels/bubble-timeline.ts | 10 ++++++++-- .../backend/src/server/api/stream/channels/global-timeline.ts | 10 ++++++++-- .../backend/src/server/api/stream/channels/home-timeline.ts | 10 ++++++++-- .../backend/src/server/api/stream/channels/hybrid-timeline.ts | 10 ++++++++-- .../backend/src/server/api/stream/channels/local-timeline.ts | 10 ++++++++-- 5 files changed, 40 insertions(+), 10 deletions(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index b8cbe4f283..41b7b7cd3c 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -70,12 +70,18 @@ class BubbleTimelineChannel extends Channel { const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); note.renote.myReaction = myRenoteReaction; } + if (note.renote && note.renote.reply) { + if (Object.keys(note.renote.reply.reactions).length > 0) { + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); + note.renote.reply.myReaction = myReplyReaction; + } + } } if (this.user && note.reply) { if (Object.keys(note.reply.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myRenoteReaction; + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myReplyReaction; } } diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index 43aa99e8c4..6da21ac72c 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -65,12 +65,18 @@ class GlobalTimelineChannel extends Channel { const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); note.renote.myReaction = myRenoteReaction; } + if (note.renote && note.renote.reply) { + if (Object.keys(note.renote.reply.reactions).length > 0) { + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); + note.renote.reply.myReaction = myReplyReaction; + } + } } if (this.user && note.reply) { if (Object.keys(note.reply.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myRenoteReaction; + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myReplyReaction; } } diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index 05040b9099..d4b65222a0 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -86,12 +86,18 @@ class HomeTimelineChannel extends Channel { const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); note.renote.myReaction = myRenoteReaction; } + if (note.renote && note.renote.reply) { + if (Object.keys(note.renote.reply.reactions).length > 0) { + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); + note.renote.reply.myReaction = myReplyReaction; + } + } } if (this.user && note.reply) { if (Object.keys(note.reply.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myRenoteReaction; + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myReplyReaction; } } diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index b268904f04..c989721463 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -104,12 +104,18 @@ class HybridTimelineChannel extends Channel { const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); note.renote.myReaction = myRenoteReaction; } + if (note.renote && note.renote.reply) { + if (Object.keys(note.renote.reply.reactions).length > 0) { + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); + note.renote.reply.myReaction = myReplyReaction; + } + } } if (this.user && note.reply) { if (Object.keys(note.reply.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myRenoteReaction; + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myReplyReaction; } } diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 8d75a0c3a2..2f1720f8fe 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -75,12 +75,18 @@ class LocalTimelineChannel extends Channel { const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); note.renote.myReaction = myRenoteReaction; } + if (note.renote && note.renote.reply) { + if (Object.keys(note.renote.reply.reactions).length > 0) { + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); + note.renote.reply.myReaction = myReplyReaction; + } + } } if (this.user && note.reply) { if (Object.keys(note.reply.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myRenoteReaction; + const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); + note.reply.myReaction = myReplyReaction; } } -- cgit v1.2.3-freya From 64abef8be9897db493670a63817ee2876db079b8 Mon Sep 17 00:00:00 2001 From: piuvas Date: Wed, 25 Dec 2024 16:41:40 -0300 Subject: turn task into a function --- packages/backend/src/server/api/stream/channel.ts | 9 ++++++++ .../server/api/stream/channels/bubble-timeline.ts | 22 +++++++------------ .../server/api/stream/channels/global-timeline.ts | 22 +++++++------------ .../server/api/stream/channels/home-timeline.ts | 22 +++++++------------ .../server/api/stream/channels/hybrid-timeline.ts | 25 ++++++++-------------- .../server/api/stream/channels/local-timeline.ts | 22 +++++++------------ 6 files changed, 50 insertions(+), 72 deletions(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channel.ts b/packages/backend/src/server/api/stream/channel.ts index ae9c7e3e99..cded294bf4 100644 --- a/packages/backend/src/server/api/stream/channel.ts +++ b/packages/backend/src/server/api/stream/channel.ts @@ -10,6 +10,7 @@ import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js'; import type { Packed } from '@/misc/json-schema.js'; import type { JsonObject, JsonValue } from '@/misc/json-value.js'; import type Connection from './Connection.js'; +import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; /** * Stream channel @@ -101,6 +102,14 @@ export default abstract class Channel { public dispose?(): void; public onMessage?(type: string, body: JsonValue): void; + + public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService) { + if (this.user === undefined) { return; } + if (Object.keys(note.reactions).length > 0) { + const myReaction = await noteEntityService.populateMyReaction(note, this.user.id); + note.myReaction = myReaction; + } + } } export type MiChannelService = { diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index 41b7b7cd3c..a0875288a2 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -65,25 +65,19 @@ class BubbleTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; + const reactionsToFetch = []; if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - if (note.renote && note.renote.reply) { - if (Object.keys(note.renote.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); - note.renote.reply.myReaction = myReplyReaction; + if (note.renote) { + reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); + if (note.renote.reply) { + reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } + } else if (this.user && note.reply) { + reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } - if (this.user && note.reply) { - if (Object.keys(note.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myReplyReaction; - } - } + await Promise.all(reactionsToFetch); this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index 6da21ac72c..d133d84c09 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -60,25 +60,19 @@ class GlobalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; + const reactionsToFetch = []; if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - if (note.renote && note.renote.reply) { - if (Object.keys(note.renote.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); - note.renote.reply.myReaction = myReplyReaction; + if (note.renote) { + reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); + if (note.renote.reply) { + reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } + } else if (this.user && note.reply) { + reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } - if (this.user && note.reply) { - if (Object.keys(note.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myReplyReaction; - } - } + await Promise.all(reactionsToFetch); this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index d4b65222a0..8c059e2405 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -81,25 +81,19 @@ class HomeTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; + const reactionsToFetch = []; if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - if (note.renote && note.renote.reply) { - if (Object.keys(note.renote.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); - note.renote.reply.myReaction = myReplyReaction; + if (note.renote) { + reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); + if (note.renote.reply) { + reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } + } else if (this.user && note.reply) { + reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } - if (this.user && note.reply) { - if (Object.keys(note.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myReplyReaction; - } - } + await Promise.all(reactionsToFetch); this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index c989721463..8eedcdbd59 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -98,26 +98,19 @@ class HybridTimelineChannel extends Channel { } } - if (this.user && note.renoteId && !note.text) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - console.log(note.renote.reactionAndUserPairCache); - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - if (note.renote && note.renote.reply) { - if (Object.keys(note.renote.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); - note.renote.reply.myReaction = myReplyReaction; + const reactionsToFetch = []; + if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { + if (note.renote) { + reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); + if (note.renote.reply) { + reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } + } else if (this.user && note.reply) { + reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } - if (this.user && note.reply) { - if (Object.keys(note.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myReplyReaction; - } - } + await Promise.all(reactionsToFetch); this.connection.cacheNote(note); diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 2f1720f8fe..89187c49fd 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -70,25 +70,19 @@ class LocalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; + const reactionsToFetch = []; if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - if (note.renote && note.renote.reply) { - if (Object.keys(note.renote.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); - note.renote.reply.myReaction = myReplyReaction; + if (note.renote) { + reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); + if (note.renote.reply) { + reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } + } else if (this.user && note.reply) { + reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } - if (this.user && note.reply) { - if (Object.keys(note.reply.reactions).length > 0) { - const myReplyReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); - note.reply.myReaction = myReplyReaction; - } - } + await Promise.all(reactionsToFetch); this.connection.cacheNote(note); -- cgit v1.2.3-freya From 2c742d6e82d98776f28558253f9f5ca3e814de2a Mon Sep 17 00:00:00 2001 From: piuvas Date: Thu, 26 Dec 2024 14:49:22 -0300 Subject: requested change. --- packages/backend/src/server/api/stream/channels/bubble-timeline.ts | 3 ++- packages/backend/src/server/api/stream/channels/global-timeline.ts | 3 ++- packages/backend/src/server/api/stream/channels/home-timeline.ts | 3 ++- packages/backend/src/server/api/stream/channels/hybrid-timeline.ts | 3 ++- packages/backend/src/server/api/stream/channels/local-timeline.ts | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index a0875288a2..b2745db92d 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -73,7 +73,8 @@ class BubbleTimelineChannel extends Channel { reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } - } else if (this.user && note.reply) { + } + if (this.user && note.reply) { reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index d133d84c09..8df59d906d 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -68,7 +68,8 @@ class GlobalTimelineChannel extends Channel { reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } - } else if (this.user && note.reply) { + } + if (this.user && note.reply) { reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index 8c059e2405..f48eff85c9 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -89,7 +89,8 @@ class HomeTimelineChannel extends Channel { reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } - } else if (this.user && note.reply) { + } + if (this.user && note.reply) { reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 8eedcdbd59..8c58b2518e 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -106,7 +106,8 @@ class HybridTimelineChannel extends Channel { reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } - } else if (this.user && note.reply) { + } + if (this.user && note.reply) { reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 89187c49fd..cb832bd3c2 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -78,7 +78,8 @@ class LocalTimelineChannel extends Channel { reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); } } - } else if (this.user && note.reply) { + } + if (this.user && note.reply) { reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); } -- cgit v1.2.3-freya From 5fc9c1c8cdebec868440cd8ed4b3ad84f214e117 Mon Sep 17 00:00:00 2001 From: piuvas Date: Wed, 8 Jan 2025 12:51:46 -0300 Subject: shallow clone --- packages/backend/src/server/api/stream/channel.ts | 37 +++++++++++++++++++--- .../server/api/stream/channels/bubble-timeline.ts | 23 +++----------- .../server/api/stream/channels/global-timeline.ts | 23 +++----------- .../server/api/stream/channels/home-timeline.ts | 19 ++--------- .../server/api/stream/channels/hybrid-timeline.ts | 19 ++--------- .../server/api/stream/channels/local-timeline.ts | 19 ++--------- 6 files changed, 51 insertions(+), 89 deletions(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channel.ts b/packages/backend/src/server/api/stream/channel.ts index 93d5046902..ed6e41c4bb 100644 --- a/packages/backend/src/server/api/stream/channel.ts +++ b/packages/backend/src/server/api/stream/channel.ts @@ -9,8 +9,8 @@ import { isUserRelated } from '@/misc/is-user-related.js'; import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js'; import type { Packed } from '@/misc/json-schema.js'; import type { JsonObject, JsonValue } from '@/misc/json-value.js'; -import type Connection from './Connection.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; +import type Connection from './Connection.js'; /** * Stream channel @@ -103,14 +103,41 @@ export default abstract class Channel { public onMessage?(type: string, body: JsonValue): void; - public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService) { - if (this.user && Object.keys(note.reactions).length > 0) { - const myReaction = await noteEntityService.populateMyReaction(note, this.user.id); - note.myReaction = myReaction; + public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService): Promise> { + let changed = false; + const clonedNote = { ...note }; + if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { + if (note.renote && Object.keys(note.renote.reactions).length > 0) { + const myReaction = await noteEntityService.populateMyReaction(note.renote, this.user.id); + if (myReaction) { + changed = true; + clonedNote.renote = { ...note.renote }; + clonedNote.renote.myReaction = myReaction; + } + } + } + if (this.user && note.renote?.reply && Object.keys(note.renote.reply.reactions).length > 0) { + const myReaction = await noteEntityService.populateMyReaction(note.renote.reply, this.user.id); + if (myReaction) { + changed = true; + clonedNote.renote = { ...note.renote }; + clonedNote.renote.reply = { ...note.renote.reply }; + clonedNote.renote.reply.myReaction = myReaction; + } } + if (this.user && note.reply && Object.keys(note.reply.reactions).length > 0) { + const myReaction = await noteEntityService.populateMyReaction(note.reply, this.user.id); + if (myReaction) { + changed = true; + clonedNote.reply = { ...note.reply }; + clonedNote.reply.myReaction = myReaction; + } + } + return changed ? clonedNote : note; } } + export type MiChannelService = { shouldShare: boolean; requireCredential: T; diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index b2745db92d..98ecf16a83 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -65,24 +65,11 @@ class BubbleTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const reactionsToFetch = []; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote) { - reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); - if (note.renote.reply) { - reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); - } - } - } - if (this.user && note.reply) { - reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); - } - - await Promise.all(reactionsToFetch); - - this.connection.cacheNote(note); - - this.send('note', note); + const clonedNote = await this.assignMyReaction(note, this.noteEntityService); + + this.connection.cacheNote(clonedNote); + + this.send('note', clonedNote); } @bindThis diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index 8df59d906d..4443b20bed 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -60,24 +60,11 @@ class GlobalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const reactionsToFetch = []; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote) { - reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); - if (note.renote.reply) { - reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); - } - } - } - if (this.user && note.reply) { - reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); - } - - await Promise.all(reactionsToFetch); - - this.connection.cacheNote(note); - - this.send('note', note); + const clonedNote = await this.assignMyReaction(note, this.noteEntityService); + + this.connection.cacheNote(clonedNote); + + this.send('note', clonedNote); } @bindThis diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index f48eff85c9..af1b17b533 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -81,24 +81,11 @@ class HomeTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const reactionsToFetch = []; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote) { - reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); - if (note.renote.reply) { - reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); - } - } - } - if (this.user && note.reply) { - reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); - } - - await Promise.all(reactionsToFetch); + const clonedNote = await this.assignMyReaction(note, this.noteEntityService); - this.connection.cacheNote(note); + this.connection.cacheNote(clonedNote); - this.send('note', note); + this.send('note', clonedNote); } @bindThis diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 8c58b2518e..7c604c0b58 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -98,24 +98,11 @@ class HybridTimelineChannel extends Channel { } } - const reactionsToFetch = []; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote) { - reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); - if (note.renote.reply) { - reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); - } - } - } - if (this.user && note.reply) { - reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); - } - - await Promise.all(reactionsToFetch); + const clonedNote = await this.assignMyReaction(note, this.noteEntityService); - this.connection.cacheNote(note); + this.connection.cacheNote(clonedNote); - this.send('note', note); + this.send('note', clonedNote); } @bindThis diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index cb832bd3c2..2d48b6ecfb 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -70,24 +70,11 @@ class LocalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const reactionsToFetch = []; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote) { - reactionsToFetch.push(this.assignMyReaction(note.renote, this.noteEntityService)); - if (note.renote.reply) { - reactionsToFetch.push(this.assignMyReaction(note.renote.reply, this.noteEntityService)); - } - } - } - if (this.user && note.reply) { - reactionsToFetch.push(this.assignMyReaction(note.reply, this.noteEntityService)); - } - - await Promise.all(reactionsToFetch); + const clonedNote = await this.assignMyReaction(note, this.noteEntityService); - this.connection.cacheNote(note); + this.connection.cacheNote(clonedNote); - this.send('note', note); + this.send('note', clonedNote); } @bindThis -- cgit v1.2.3-freya From 8ee315a82bfed23b44c4d7788b15d30a2bd5d45a Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Tue, 4 Feb 2025 10:41:03 -0500 Subject: fix lint errors in stream/channel/bubble-timeline.ts --- packages/backend/src/server/api/stream/channels/bubble-timeline.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index 98ecf16a83..6b6aa80797 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -3,8 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { Inject, Injectable } from '@nestjs/common'; -import { DI } from '@/di-symbols.js'; +import { Injectable } from '@nestjs/common'; import type { Packed } from '@/misc/json-schema.js'; import { MetaService } from '@/core/MetaService.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; @@ -33,7 +32,6 @@ class BubbleTimelineChannel extends Channel { connection: Channel['connection'], ) { super(id, connection); - //this.onNote = this.onNote.bind(this); } @bindThis -- cgit v1.2.3-freya From 019e60d9a43fc442252cb3ecb0e86b3d425ae37d Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Tue, 25 Feb 2025 20:52:14 -0500 Subject: pass NoteEntityService through Channel constructor instead of method args --- packages/backend/src/server/api/stream/channel.ts | 11 +++++++---- packages/backend/src/server/api/stream/channels/admin.ts | 3 +++ packages/backend/src/server/api/stream/channels/antenna.ts | 4 ++-- .../backend/src/server/api/stream/channels/bubble-timeline.ts | 6 +++--- packages/backend/src/server/api/stream/channels/channel.ts | 4 ++-- packages/backend/src/server/api/stream/channels/drive.ts | 3 +++ .../backend/src/server/api/stream/channels/global-timeline.ts | 6 +++--- packages/backend/src/server/api/stream/channels/hashtag.ts | 4 ++-- .../backend/src/server/api/stream/channels/home-timeline.ts | 6 +++--- .../backend/src/server/api/stream/channels/hybrid-timeline.ts | 6 +++--- .../backend/src/server/api/stream/channels/local-timeline.ts | 6 +++--- packages/backend/src/server/api/stream/channels/main.ts | 4 ++-- .../backend/src/server/api/stream/channels/queue-stats.ts | 7 +++++-- .../backend/src/server/api/stream/channels/reversi-game.ts | 6 +++++- packages/backend/src/server/api/stream/channels/reversi.ts | 6 +++++- .../backend/src/server/api/stream/channels/role-timeline.ts | 4 ++-- .../backend/src/server/api/stream/channels/server-stats.ts | 7 +++++-- packages/backend/src/server/api/stream/channels/user-list.ts | 4 ++-- 18 files changed, 60 insertions(+), 37 deletions(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channel.ts b/packages/backend/src/server/api/stream/channel.ts index dbbb1ee348..06afc221c8 100644 --- a/packages/backend/src/server/api/stream/channel.ts +++ b/packages/backend/src/server/api/stream/channel.ts @@ -17,6 +17,7 @@ import type Connection from './Connection.js'; */ // eslint-disable-next-line import/no-default-export export default abstract class Channel { + protected readonly noteEntityService: NoteEntityService; protected connection: Connection; public id: string; public abstract readonly chName: string; @@ -82,8 +83,10 @@ export default abstract class Channel { } constructor(id: string, connection: Connection) { + constructor(id: string, connection: Connection, noteEntityService: NoteEntityService) { this.id = id; this.connection = connection; + this.noteEntityService = noteEntityService; } public send(payload: { type: string, body: JsonValue }): void @@ -106,7 +109,7 @@ export default abstract class Channel { public onMessage?(type: string, body: JsonValue): void; - public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService): Promise> { + public async assignMyReaction(note: Packed<'Note'>): Promise> { let changed = false; // StreamingApiServerService creates a single EventEmitter per server process, // so a new note arriving from redis gets de-serialised once per server process, @@ -116,7 +119,7 @@ export default abstract class Channel { const clonedNote = { ...note }; if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myReaction = await noteEntityService.populateMyReaction(note.renote, this.user.id); + const myReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); if (myReaction) { changed = true; clonedNote.renote = { ...note.renote }; @@ -124,7 +127,7 @@ export default abstract class Channel { } } if (note.renote?.reply && Object.keys(note.renote.reply.reactions).length > 0) { - const myReaction = await noteEntityService.populateMyReaction(note.renote.reply, this.user.id); + const myReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id); if (myReaction) { changed = true; clonedNote.renote = { ...note.renote }; @@ -134,7 +137,7 @@ export default abstract class Channel { } } if (this.user && note.reply && Object.keys(note.reply.reactions).length > 0) { - const myReaction = await noteEntityService.populateMyReaction(note.reply, this.user.id); + const myReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id); if (myReaction) { changed = true; clonedNote.reply = { ...note.reply }; diff --git a/packages/backend/src/server/api/stream/channels/admin.ts b/packages/backend/src/server/api/stream/channels/admin.ts index 355d5dba21..a0140d395d 100644 --- a/packages/backend/src/server/api/stream/channels/admin.ts +++ b/packages/backend/src/server/api/stream/channels/admin.ts @@ -6,6 +6,7 @@ import { Injectable } from '@nestjs/common'; import { bindThis } from '@/decorators.js'; import type { JsonObject } from '@/misc/json-value.js'; +import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import Channel, { type MiChannelService } from '../channel.js'; class AdminChannel extends Channel { @@ -30,6 +31,7 @@ export class AdminChannelService implements MiChannelService { public readonly kind = AdminChannel.kind; constructor( + private readonly noteEntityService: NoteEntityService, ) { } @@ -38,6 +40,7 @@ export class AdminChannelService implements MiChannelService { return new AdminChannel( id, connection, + this.noteEntityService, ); } } diff --git a/packages/backend/src/server/api/stream/channels/antenna.ts b/packages/backend/src/server/api/stream/channels/antenna.ts index 53dc7f18b6..a73d158b7f 100644 --- a/packages/backend/src/server/api/stream/channels/antenna.ts +++ b/packages/backend/src/server/api/stream/channels/antenna.ts @@ -18,12 +18,12 @@ class AntennaChannel extends Channel { private antennaId: string; constructor( - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onEvent = this.onEvent.bind(this); } diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index 6b6aa80797..c33245ef1e 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -26,12 +26,12 @@ class BubbleTimelineChannel extends Channel { constructor( private metaService: MetaService, private roleService: RoleService, - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); } @bindThis @@ -63,7 +63,7 @@ class BubbleTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const clonedNote = await this.assignMyReaction(note, this.noteEntityService); + const clonedNote = await this.assignMyReaction(note); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/channel.ts b/packages/backend/src/server/api/stream/channels/channel.ts index 9939aa49ee..de4dd784ee 100644 --- a/packages/backend/src/server/api/stream/channels/channel.ts +++ b/packages/backend/src/server/api/stream/channels/channel.ts @@ -20,12 +20,12 @@ class ChannelChannel extends Channel { private withRenotes: boolean; constructor( - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onNote = this.onNote.bind(this); } diff --git a/packages/backend/src/server/api/stream/channels/drive.ts b/packages/backend/src/server/api/stream/channels/drive.ts index 03768f3d23..fa097fdc35 100644 --- a/packages/backend/src/server/api/stream/channels/drive.ts +++ b/packages/backend/src/server/api/stream/channels/drive.ts @@ -6,6 +6,7 @@ import { Injectable } from '@nestjs/common'; import { bindThis } from '@/decorators.js'; import type { JsonObject } from '@/misc/json-value.js'; +import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import Channel, { type MiChannelService } from '../channel.js'; class DriveChannel extends Channel { @@ -30,6 +31,7 @@ export class DriveChannelService implements MiChannelService { public readonly kind = DriveChannel.kind; constructor( + private readonly noteEntityService: NoteEntityService, ) { } @@ -38,6 +40,7 @@ export class DriveChannelService implements MiChannelService { return new DriveChannel( id, connection, + this.noteEntityService, ); } } diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index 4443b20bed..868592b433 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -24,12 +24,12 @@ class GlobalTimelineChannel extends Channel { constructor( private metaService: MetaService, private roleService: RoleService, - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onNote = this.onNote.bind(this); } @@ -60,7 +60,7 @@ class GlobalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const clonedNote = await this.assignMyReaction(note, this.noteEntityService); + const clonedNote = await this.assignMyReaction(note); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/hashtag.ts b/packages/backend/src/server/api/stream/channels/hashtag.ts index 8105f15cb1..81e3188b0e 100644 --- a/packages/backend/src/server/api/stream/channels/hashtag.ts +++ b/packages/backend/src/server/api/stream/channels/hashtag.ts @@ -19,12 +19,12 @@ class HashtagChannel extends Channel { private q: string[][]; constructor( - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onNote = this.onNote.bind(this); } diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index af1b17b533..105f966461 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -20,12 +20,12 @@ class HomeTimelineChannel extends Channel { private withFiles: boolean; constructor( - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onNote = this.onNote.bind(this); } @@ -81,7 +81,7 @@ class HomeTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const clonedNote = await this.assignMyReaction(note, this.noteEntityService); + const clonedNote = await this.assignMyReaction(note); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 7c604c0b58..4b26fcf667 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -26,12 +26,12 @@ class HybridTimelineChannel extends Channel { constructor( private metaService: MetaService, private roleService: RoleService, - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onNote = this.onNote.bind(this); } @@ -98,7 +98,7 @@ class HybridTimelineChannel extends Channel { } } - const clonedNote = await this.assignMyReaction(note, this.noteEntityService); + const clonedNote = await this.assignMyReaction(note); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 2d48b6ecfb..1e656def9a 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -25,12 +25,12 @@ class LocalTimelineChannel extends Channel { constructor( private metaService: MetaService, private roleService: RoleService, - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onNote = this.onNote.bind(this); } @@ -70,7 +70,7 @@ class LocalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - const clonedNote = await this.assignMyReaction(note, this.noteEntityService); + const clonedNote = await this.assignMyReaction(note); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/main.ts b/packages/backend/src/server/api/stream/channels/main.ts index 863d7f4c4e..6b144e43e4 100644 --- a/packages/backend/src/server/api/stream/channels/main.ts +++ b/packages/backend/src/server/api/stream/channels/main.ts @@ -17,12 +17,12 @@ class MainChannel extends Channel { public static kind = 'read:account'; constructor( - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); } @bindThis diff --git a/packages/backend/src/server/api/stream/channels/queue-stats.ts b/packages/backend/src/server/api/stream/channels/queue-stats.ts index 91b62255b4..a4006ab752 100644 --- a/packages/backend/src/server/api/stream/channels/queue-stats.ts +++ b/packages/backend/src/server/api/stream/channels/queue-stats.ts @@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common'; import { bindThis } from '@/decorators.js'; import { isJsonObject } from '@/misc/json-value.js'; import type { JsonObject, JsonValue } from '@/misc/json-value.js'; +import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import Channel, { type MiChannelService } from '../channel.js'; const ev = new Xev(); @@ -17,8 +18,8 @@ class QueueStatsChannel extends Channel { public static shouldShare = true; public static requireCredential = false as const; - constructor(id: string, connection: Channel['connection']) { - super(id, connection); + constructor(id: string, connection: Channel['connection'], noteEntityService: NoteEntityService) { + super(id, connection, noteEntityService); //this.onStats = this.onStats.bind(this); //this.onMessage = this.onMessage.bind(this); } @@ -64,6 +65,7 @@ export class QueueStatsChannelService implements MiChannelService { public readonly kind = QueueStatsChannel.kind; constructor( + private readonly noteEntityService: NoteEntityService, ) { } @@ -72,6 +74,7 @@ export class QueueStatsChannelService implements MiChannelService { return new QueueStatsChannel( id, connection, + this.noteEntityService, ); } } diff --git a/packages/backend/src/server/api/stream/channels/reversi-game.ts b/packages/backend/src/server/api/stream/channels/reversi-game.ts index 7597a1cfa3..b7fffbe844 100644 --- a/packages/backend/src/server/api/stream/channels/reversi-game.ts +++ b/packages/backend/src/server/api/stream/channels/reversi-game.ts @@ -11,6 +11,7 @@ import { ReversiService } from '@/core/ReversiService.js'; import { ReversiGameEntityService } from '@/core/entities/ReversiGameEntityService.js'; import { isJsonObject } from '@/misc/json-value.js'; import type { JsonObject, JsonValue } from '@/misc/json-value.js'; +import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import Channel, { type MiChannelService } from '../channel.js'; import { reversiUpdateKeys } from 'misskey-js'; @@ -23,11 +24,12 @@ class ReversiGameChannel extends Channel { constructor( private reversiService: ReversiService, private reversiGameEntityService: ReversiGameEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); } @bindThis @@ -116,6 +118,7 @@ export class ReversiGameChannelService implements MiChannelService { constructor( private reversiService: ReversiService, private reversiGameEntityService: ReversiGameEntityService, + private noteEntityService: NoteEntityService, ) { } @@ -124,6 +127,7 @@ export class ReversiGameChannelService implements MiChannelService { return new ReversiGameChannel( this.reversiService, this.reversiGameEntityService, + this.noteEntityService, id, connection, ); diff --git a/packages/backend/src/server/api/stream/channels/reversi.ts b/packages/backend/src/server/api/stream/channels/reversi.ts index 6e88939724..dc73d3a3d8 100644 --- a/packages/backend/src/server/api/stream/channels/reversi.ts +++ b/packages/backend/src/server/api/stream/channels/reversi.ts @@ -6,6 +6,7 @@ import { Injectable } from '@nestjs/common'; import { bindThis } from '@/decorators.js'; import type { JsonObject } from '@/misc/json-value.js'; +import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import Channel, { type MiChannelService } from '../channel.js'; class ReversiChannel extends Channel { @@ -17,8 +18,9 @@ class ReversiChannel extends Channel { constructor( id: string, connection: Channel['connection'], + noteEntityService: NoteEntityService, ) { - super(id, connection); + super(id, connection, noteEntityService); } @bindThis @@ -40,6 +42,7 @@ export class ReversiChannelService implements MiChannelService { public readonly kind = ReversiChannel.kind; constructor( + private readonly noteEntityService: NoteEntityService, ) { } @@ -48,6 +51,7 @@ export class ReversiChannelService implements MiChannelService { return new ReversiChannel( id, connection, + this.noteEntityService, ); } } diff --git a/packages/backend/src/server/api/stream/channels/role-timeline.ts b/packages/backend/src/server/api/stream/channels/role-timeline.ts index fcfa26c38b..f8c9283c25 100644 --- a/packages/backend/src/server/api/stream/channels/role-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/role-timeline.ts @@ -18,13 +18,13 @@ class RoleTimelineChannel extends Channel { private roleId: string; constructor( - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, private roleservice: RoleService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.onNote = this.onNote.bind(this); } diff --git a/packages/backend/src/server/api/stream/channels/server-stats.ts b/packages/backend/src/server/api/stream/channels/server-stats.ts index ec5352d12d..43cbf65110 100644 --- a/packages/backend/src/server/api/stream/channels/server-stats.ts +++ b/packages/backend/src/server/api/stream/channels/server-stats.ts @@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common'; import { bindThis } from '@/decorators.js'; import { isJsonObject } from '@/misc/json-value.js'; import type { JsonObject, JsonValue } from '@/misc/json-value.js'; +import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import Channel, { type MiChannelService } from '../channel.js'; const ev = new Xev(); @@ -17,8 +18,8 @@ class ServerStatsChannel extends Channel { public static shouldShare = true; public static requireCredential = false as const; - constructor(id: string, connection: Channel['connection']) { - super(id, connection); + constructor(id: string, connection: Channel['connection'], noteEntityService: NoteEntityService) { + super(id, connection, noteEntityService); //this.onStats = this.onStats.bind(this); //this.onMessage = this.onMessage.bind(this); } @@ -62,6 +63,7 @@ export class ServerStatsChannelService implements MiChannelService { public readonly kind = ServerStatsChannel.kind; constructor( + private readonly noteEntityService: NoteEntityService, ) { } @@ -70,6 +72,7 @@ export class ServerStatsChannelService implements MiChannelService { return new ServerStatsChannel( id, connection, + this.noteEntityService, ); } } diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts index 4f38351e94..8f6d1d8b83 100644 --- a/packages/backend/src/server/api/stream/channels/user-list.ts +++ b/packages/backend/src/server/api/stream/channels/user-list.ts @@ -26,12 +26,12 @@ class UserListChannel extends Channel { constructor( private userListsRepository: UserListsRepository, private userListMembershipsRepository: UserListMembershipsRepository, - private noteEntityService: NoteEntityService, + noteEntityService: NoteEntityService, id: string, connection: Channel['connection'], ) { - super(id, connection); + super(id, connection, noteEntityService); //this.updateListUsers = this.updateListUsers.bind(this); //this.onNote = this.onNote.bind(this); } -- cgit v1.2.3-freya From 30b2bfb184160e0d5e347372c6907a3baf193426 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Tue, 25 Feb 2025 20:54:54 -0500 Subject: use assignMyReaction in channel, hashtag, role-timeline, and user-list channels --- packages/backend/src/server/api/stream/channels/channel.ts | 12 +++--------- packages/backend/src/server/api/stream/channels/hashtag.ts | 12 +++--------- .../backend/src/server/api/stream/channels/role-timeline.ts | 6 +++++- packages/backend/src/server/api/stream/channels/user-list.ts | 11 +++-------- 4 files changed, 14 insertions(+), 27 deletions(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channels/channel.ts b/packages/backend/src/server/api/stream/channels/channel.ts index de4dd784ee..d5cfd3a0d9 100644 --- a/packages/backend/src/server/api/stream/channels/channel.ts +++ b/packages/backend/src/server/api/stream/channels/channel.ts @@ -7,7 +7,6 @@ import { Injectable } from '@nestjs/common'; import type { Packed } from '@/misc/json-schema.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { bindThis } from '@/decorators.js'; -import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js'; import type { JsonObject } from '@/misc/json-value.js'; import Channel, { type MiChannelService } from '../channel.js'; @@ -50,16 +49,11 @@ class ChannelChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - } + const clonedNote = await this.assignMyReaction(note); - this.connection.cacheNote(note); + this.connection.cacheNote(clonedNote); - this.send('note', note); + this.send('note', clonedNote); } @bindThis diff --git a/packages/backend/src/server/api/stream/channels/hashtag.ts b/packages/backend/src/server/api/stream/channels/hashtag.ts index 81e3188b0e..b5d1e034be 100644 --- a/packages/backend/src/server/api/stream/channels/hashtag.ts +++ b/packages/backend/src/server/api/stream/channels/hashtag.ts @@ -8,7 +8,6 @@ import { normalizeForSearch } from '@/misc/normalize-for-search.js'; import type { Packed } from '@/misc/json-schema.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import { bindThis } from '@/decorators.js'; -import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js'; import type { JsonObject } from '@/misc/json-value.js'; import Channel, { type MiChannelService } from '../channel.js'; @@ -46,16 +45,11 @@ class HashtagChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - } + const clonedNote = await this.assignMyReaction(note); - this.connection.cacheNote(note); + this.connection.cacheNote(clonedNote); - this.send('note', note); + this.send('note', clonedNote); } @bindThis diff --git a/packages/backend/src/server/api/stream/channels/role-timeline.ts b/packages/backend/src/server/api/stream/channels/role-timeline.ts index f8c9283c25..5d33108821 100644 --- a/packages/backend/src/server/api/stream/channels/role-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/role-timeline.ts @@ -48,7 +48,11 @@ class RoleTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - this.send('note', note); + const clonedNote = await this.assignMyReaction(note); + + this.connection.cacheNote(clonedNote); + + this.send('note', clonedNote); } else { this.send(data.type, data.body); } diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts index 8f6d1d8b83..8561ce11b3 100644 --- a/packages/backend/src/server/api/stream/channels/user-list.ts +++ b/packages/backend/src/server/api/stream/channels/user-list.ts @@ -111,16 +111,11 @@ class UserListChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; - if (this.user && isRenotePacked(note) && !isQuotePacked(note)) { - if (note.renote && Object.keys(note.renote.reactions).length > 0) { - const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id); - note.renote.myReaction = myRenoteReaction; - } - } + const clonedNote = await this.assignMyReaction(note); - this.connection.cacheNote(note); + this.connection.cacheNote(clonedNote); - this.send('note', note); + this.send('note', clonedNote); } @bindThis -- cgit v1.2.3-freya From 18f211e3bc828cd282975b99185a0e8e17a8b650 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Tue, 25 Feb 2025 20:55:24 -0500 Subject: call NoteEntityService.hideNote from streaming API --- packages/backend/src/server/api/stream/channel.ts | 14 +++++++++++++- .../src/server/api/stream/channels/bubble-timeline.ts | 1 + packages/backend/src/server/api/stream/channels/channel.ts | 1 + .../src/server/api/stream/channels/global-timeline.ts | 1 + packages/backend/src/server/api/stream/channels/hashtag.ts | 1 + .../src/server/api/stream/channels/home-timeline.ts | 1 + .../src/server/api/stream/channels/hybrid-timeline.ts | 1 + .../src/server/api/stream/channels/local-timeline.ts | 1 + .../src/server/api/stream/channels/role-timeline.ts | 1 + .../backend/src/server/api/stream/channels/user-list.ts | 1 + 10 files changed, 22 insertions(+), 1 deletion(-) (limited to 'packages/backend/src/server/api/stream/channels') diff --git a/packages/backend/src/server/api/stream/channel.ts b/packages/backend/src/server/api/stream/channel.ts index 06afc221c8..7a6193ccfc 100644 --- a/packages/backend/src/server/api/stream/channel.ts +++ b/packages/backend/src/server/api/stream/channel.ts @@ -82,7 +82,19 @@ export default abstract class Channel { return false; } - constructor(id: string, connection: Connection) { + protected async hideNote(note: Packed<'Note'>): Promise { + if (note.renote) { + await this.hideNote(note.renote); + } + + if (note.reply) { + await this.hideNote(note.reply); + } + + const meId = this.user?.id ?? null; + await this.noteEntityService.hideNote(note, meId); + } + constructor(id: string, connection: Connection, noteEntityService: NoteEntityService) { this.id = id; this.connection = connection; diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts index c33245ef1e..5ebbdcbb86 100644 --- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts @@ -64,6 +64,7 @@ class BubbleTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/channel.ts b/packages/backend/src/server/api/stream/channels/channel.ts index d5cfd3a0d9..ec0bc7e13a 100644 --- a/packages/backend/src/server/api/stream/channels/channel.ts +++ b/packages/backend/src/server/api/stream/channels/channel.ts @@ -50,6 +50,7 @@ class ChannelChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts index 868592b433..72a8a8b156 100644 --- a/packages/backend/src/server/api/stream/channels/global-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts @@ -61,6 +61,7 @@ class GlobalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/hashtag.ts b/packages/backend/src/server/api/stream/channels/hashtag.ts index b5d1e034be..7c8df87721 100644 --- a/packages/backend/src/server/api/stream/channels/hashtag.ts +++ b/packages/backend/src/server/api/stream/channels/hashtag.ts @@ -46,6 +46,7 @@ class HashtagChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts index 105f966461..c87a21be82 100644 --- a/packages/backend/src/server/api/stream/channels/home-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts @@ -82,6 +82,7 @@ class HomeTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts index 4b26fcf667..95b762e2b7 100644 --- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts @@ -99,6 +99,7 @@ class HybridTimelineChannel extends Channel { } const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts index 1e656def9a..b9e0a4c234 100644 --- a/packages/backend/src/server/api/stream/channels/local-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts @@ -71,6 +71,7 @@ class LocalTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/role-timeline.ts b/packages/backend/src/server/api/stream/channels/role-timeline.ts index 5d33108821..14c4d96479 100644 --- a/packages/backend/src/server/api/stream/channels/role-timeline.ts +++ b/packages/backend/src/server/api/stream/channels/role-timeline.ts @@ -49,6 +49,7 @@ class RoleTimelineChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts index 8561ce11b3..d09a9b8d9f 100644 --- a/packages/backend/src/server/api/stream/channels/user-list.ts +++ b/packages/backend/src/server/api/stream/channels/user-list.ts @@ -112,6 +112,7 @@ class UserListChannel extends Channel { if (this.isNoteMutedOrBlocked(note)) return; const clonedNote = await this.assignMyReaction(note); + await this.hideNote(clonedNote); this.connection.cacheNote(clonedNote); -- cgit v1.2.3-freya