summaryrefslogtreecommitdiff
path: root/packages/backend/src/server
diff options
context:
space:
mode:
authorLhc_fl <lhcfl@outlook.com>2025-03-03 18:17:13 +0800
committerLhc_fl <lhcfl@outlook.com>2025-03-03 23:03:20 +0800
commit381046a6b1f7be0ef3e36488d37180e4e32d1f18 (patch)
tree11f0494a2b0c5552ffbdf46481ba865ca0b905a2 /packages/backend/src/server
parentmerge: Bump develop version (!928) (diff)
downloadsharkey-381046a6b1f7be0ef3e36488d37180e4e32d1f18.tar.gz
sharkey-381046a6b1f7be0ef3e36488d37180e4e32d1f18.tar.bz2
sharkey-381046a6b1f7be0ef3e36488d37180e4e32d1f18.zip
fix: always clone the note before hideNote
Diffstat (limited to 'packages/backend/src/server')
-rw-r--r--packages/backend/src/server/api/stream/channel.ts12
1 files changed, 7 insertions, 5 deletions
diff --git a/packages/backend/src/server/api/stream/channel.ts b/packages/backend/src/server/api/stream/channel.ts
index 7a6193ccfc..b4a722e763 100644
--- a/packages/backend/src/server/api/stream/channel.ts
+++ b/packages/backend/src/server/api/stream/channel.ts
@@ -82,6 +82,12 @@ export default abstract class Channel {
return false;
}
+ /**
+ * Please make sure you did `assignMyReaction` before this function.
+ * See Dakker's comment regarding the same object will leading to wrong value.
+ * @param note The note to **CHANGE**
+ * @see assignMyReaction
+ */
protected async hideNote(note: Packed<'Note'>): Promise<void> {
if (note.renote) {
await this.hideNote(note.renote);
@@ -122,7 +128,6 @@ export default abstract class Channel {
public onMessage?(type: string, body: JsonValue): void;
public async assignMyReaction(note: Packed<'Note'>): Promise<Packed<'Note'>> {
- 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,
// and then that single object is passed to all active channels on each connection.
@@ -133,7 +138,6 @@ export default abstract class Channel {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
if (myReaction) {
- changed = true;
clonedNote.renote = { ...note.renote };
clonedNote.renote.myReaction = myReaction;
}
@@ -141,7 +145,6 @@ export default abstract class Channel {
if (note.renote?.reply && Object.keys(note.renote.reply.reactions).length > 0) {
const myReaction = await this.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;
@@ -151,12 +154,11 @@ export default abstract class Channel {
if (this.user && note.reply && Object.keys(note.reply.reactions).length > 0) {
const myReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
if (myReaction) {
- changed = true;
clonedNote.reply = { ...note.reply };
clonedNote.reply.myReaction = myReaction;
}
}
- return changed ? clonedNote : note;
+ return clonedNote;
}
}