diff --git a/packages/backend/src/models/repositories/note.ts b/packages/backend/src/models/repositories/note.ts index 74696f8517..1310c14b02 100644 --- a/packages/backend/src/models/repositories/note.ts +++ b/packages/backend/src/models/repositories/note.ts @@ -239,7 +239,7 @@ export const NoteRepository = db.getRepository(Note).extend({ ...(opts.detail ? { - reply: note.replyId + reply: note.replyId ? this.pack(note.reply || note.replyId, me, { detail: false, _hint_: options?._hint_, diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index 6508d01e90..5464c8a896 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -586,7 +586,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { () => undefined, ); - const choices = poll?.choices.map((choice) => mfm.parse(choice)).flat() ?? []; + const choices = poll?.choices.flatMap((choice) => mfm.parse(choice)) ?? []; const tokens = mfm .parse(text || "") @@ -617,6 +617,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { }); let updating = false; + let publishing = false; const update = {} as Partial; if (text && text !== note.text) { update.text = text; @@ -671,7 +672,6 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { dbPoll.multiple !== poll.multiple || dbPoll.expiresAt !== poll.expiresAt || dbPoll.noteVisibility !== note.visibility || - dbPoll.votes.length !== poll.votes?.length || JSON.stringify(dbPoll.choices) !== JSON.stringify(poll.choices) ) { await Polls.update( @@ -685,6 +685,14 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { }, ); updating = true; + } else { + for (let i = 0; i < poll.choices.length; i++) { + if (dbPoll.votes[i] !== poll.votes?.[i]) { + await Polls.update({ noteId: note.id }, { votes: poll?.votes }); + publishing = true; + break; + } + } } } @@ -705,6 +713,10 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { updatedAt: update.updatedAt, }); + publishing = true; + } + + if (publishing) { // Publish update event for the updated note details publishNoteStream(note.id, "updated", { updatedAt: update.updatedAt, diff --git a/packages/backend/src/server/api/stream/types.ts b/packages/backend/src/server/api/stream/types.ts index 2c59d51d1f..91095a46d3 100644 --- a/packages/backend/src/server/api/stream/types.ts +++ b/packages/backend/src/server/api/stream/types.ts @@ -146,7 +146,7 @@ export interface NoteStreamTypes { id: Note["id"]; }; updated: { - updatedAt: Note["updatedAt"]; + updatedAt?: Note["updatedAt"]; }; } type NoteStreamEventTypes = {