summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpiuvas <piuvas@proton.me>2025-01-08 12:51:46 -0300
committerpiuvas <piuvas@proton.me>2025-01-08 12:51:46 -0300
commit5fc9c1c8cdebec868440cd8ed4b3ad84f214e117 (patch)
tree0187f26df8f14631a6fa7510e1aedfdd7425ae17
parentmerge: fix: populate myreaction on replies for streams. (!839) (diff)
downloadsharkey-5fc9c1c8cdebec868440cd8ed4b3ad84f214e117.tar.gz
sharkey-5fc9c1c8cdebec868440cd8ed4b3ad84f214e117.tar.bz2
sharkey-5fc9c1c8cdebec868440cd8ed4b3ad84f214e117.zip
shallow clone
-rw-r--r--packages/backend/src/server/api/stream/channel.ts37
-rw-r--r--packages/backend/src/server/api/stream/channels/bubble-timeline.ts19
-rw-r--r--packages/backend/src/server/api/stream/channels/global-timeline.ts19
-rw-r--r--packages/backend/src/server/api/stream/channels/home-timeline.ts19
-rw-r--r--packages/backend/src/server/api/stream/channels/hybrid-timeline.ts19
-rw-r--r--packages/backend/src/server/api/stream/channels/local-timeline.ts19
6 files changed, 47 insertions, 85 deletions
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<Packed<'Note'>> {
+ 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<T extends boolean> = {
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));
- }
+ const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
- await Promise.all(reactionsToFetch);
+ this.connection.cacheNote(clonedNote);
- this.connection.cacheNote(note);
-
- this.send('note', note);
+ 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));
- }
+ const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
- await Promise.all(reactionsToFetch);
+ this.connection.cacheNote(clonedNote);
- this.connection.cacheNote(note);
-
- this.send('note', note);
+ 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