mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
merge: fix: always clone the note before hideNote (!931)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/931 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Hazelnoot <acomputerdog@gmail.com>
This commit is contained in:
commit
7d61bf7304
1 changed files with 6 additions and 5 deletions
|
@ -82,6 +82,11 @@ export default abstract class Channel {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function modifies {@link note}, please make sure it has been shallow cloned.
|
||||||
|
* See Dakkar's comment of {@link assignMyReaction} for more
|
||||||
|
* @param note The note to change
|
||||||
|
*/
|
||||||
protected async hideNote(note: Packed<'Note'>): Promise<void> {
|
protected async hideNote(note: Packed<'Note'>): Promise<void> {
|
||||||
if (note.renote) {
|
if (note.renote) {
|
||||||
await this.hideNote(note.renote);
|
await this.hideNote(note.renote);
|
||||||
|
@ -122,7 +127,6 @@ export default abstract class Channel {
|
||||||
public onMessage?(type: string, body: JsonValue): void;
|
public onMessage?(type: string, body: JsonValue): void;
|
||||||
|
|
||||||
public async assignMyReaction(note: Packed<'Note'>): Promise<Packed<'Note'>> {
|
public async assignMyReaction(note: Packed<'Note'>): Promise<Packed<'Note'>> {
|
||||||
let changed = false;
|
|
||||||
// StreamingApiServerService creates a single EventEmitter per server process,
|
// StreamingApiServerService creates a single EventEmitter per server process,
|
||||||
// so a new note arriving from redis gets de-serialised once 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.
|
// and then that single object is passed to all active channels on each connection.
|
||||||
|
@ -133,7 +137,6 @@ export default abstract class Channel {
|
||||||
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
|
||||||
const myReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
const myReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||||
if (myReaction) {
|
if (myReaction) {
|
||||||
changed = true;
|
|
||||||
clonedNote.renote = { ...note.renote };
|
clonedNote.renote = { ...note.renote };
|
||||||
clonedNote.renote.myReaction = myReaction;
|
clonedNote.renote.myReaction = myReaction;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +144,6 @@ export default abstract class Channel {
|
||||||
if (note.renote?.reply && Object.keys(note.renote.reply.reactions).length > 0) {
|
if (note.renote?.reply && Object.keys(note.renote.reply.reactions).length > 0) {
|
||||||
const myReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
|
const myReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
|
||||||
if (myReaction) {
|
if (myReaction) {
|
||||||
changed = true;
|
|
||||||
clonedNote.renote = { ...note.renote };
|
clonedNote.renote = { ...note.renote };
|
||||||
clonedNote.renote.reply = { ...note.renote.reply };
|
clonedNote.renote.reply = { ...note.renote.reply };
|
||||||
clonedNote.renote.reply.myReaction = myReaction;
|
clonedNote.renote.reply.myReaction = myReaction;
|
||||||
|
@ -151,12 +153,11 @@ export default abstract class Channel {
|
||||||
if (this.user && note.reply && Object.keys(note.reply.reactions).length > 0) {
|
if (this.user && note.reply && Object.keys(note.reply.reactions).length > 0) {
|
||||||
const myReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
|
const myReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
|
||||||
if (myReaction) {
|
if (myReaction) {
|
||||||
changed = true;
|
|
||||||
clonedNote.reply = { ...note.reply };
|
clonedNote.reply = { ...note.reply };
|
||||||
clonedNote.reply.myReaction = myReaction;
|
clonedNote.reply.myReaction = myReaction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return changed ? clonedNote : note;
|
return clonedNote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue