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

@ -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_,

View File

@ -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<Note>;
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,

View File

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