fix poll voting causing edit revisions.

This commit is contained in:
Kaity A 2023-05-01 03:17:38 +10:00
parent 627a71701f
commit 6eed038028
No known key found for this signature in database
GPG Key ID: 5A797B97C2A490AD
3 changed files with 16 additions and 4 deletions

View File

@ -586,7 +586,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
() => undefined, () => undefined,
); );
const choices = poll?.choices.map((choice) => mfm.parse(choice)).flat() ?? []; const choices = poll?.choices.flatMap((choice) => mfm.parse(choice)) ?? [];
const tokens = mfm const tokens = mfm
.parse(text || "") .parse(text || "")
@ -617,6 +617,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
}); });
let updating = false; let updating = false;
let publishing = false;
const update = {} as Partial<Note>; const update = {} as Partial<Note>;
if (text && text !== note.text) { if (text && text !== note.text) {
update.text = text; update.text = text;
@ -671,7 +672,6 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
dbPoll.multiple !== poll.multiple || dbPoll.multiple !== poll.multiple ||
dbPoll.expiresAt !== poll.expiresAt || dbPoll.expiresAt !== poll.expiresAt ||
dbPoll.noteVisibility !== note.visibility || dbPoll.noteVisibility !== note.visibility ||
dbPoll.votes.length !== poll.votes?.length ||
JSON.stringify(dbPoll.choices) !== JSON.stringify(poll.choices) JSON.stringify(dbPoll.choices) !== JSON.stringify(poll.choices)
) { ) {
await Polls.update( await Polls.update(
@ -685,6 +685,14 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) {
}, },
); );
updating = true; 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, updatedAt: update.updatedAt,
}); });
publishing = true;
}
if (publishing) {
// Publish update event for the updated note details // Publish update event for the updated note details
publishNoteStream(note.id, "updated", { publishNoteStream(note.id, "updated", {
updatedAt: update.updatedAt, updatedAt: update.updatedAt,

View File

@ -146,7 +146,7 @@ export interface NoteStreamTypes {
id: Note["id"]; id: Note["id"];
}; };
updated: { updated: {
updatedAt: Note["updatedAt"]; updatedAt?: Note["updatedAt"];
}; };
} }
type NoteStreamEventTypes = { type NoteStreamEventTypes = {