Fix polls not rendering properly in Schedule List

This commit is contained in:
Marie 2025-05-08 01:26:56 +02:00
parent b66a486036
commit cfad5999b2
No known key found for this signature in database
GPG key ID: 7ADF6C9CD9A28555

View file

@ -133,6 +133,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
renote, reply, renote, reply,
renoteId: item.note.renote, renoteId: item.note.renote,
replyId: item.note.reply, replyId: item.note.reply,
poll: item.note.poll ? await this.fillPoll(item.note.poll) : undefined,
}, },
}; };
})); }));
@ -155,4 +156,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} }
return null; return null;
} }
// Pulled from NoteEntityService and modified to work with MiNoteSchedule
// originally planned to use directly from NoteEntityService but since the poll doesn't actually exist yet that doesn't work
@bindThis
private async fillPoll(poll: { multiple: boolean; choices: string[]; expiresAt: string | null }) {
const choices = poll.choices.map(c => ({
text: c,
votes: 0, // Default to 0 as there will never be any registered votes while scheduled
isVoted: false, // Default to false as the author can't vote anyways since the poll does not exist in the repo yet
}));
return {
multiple: poll.multiple,
expiresAt: poll.expiresAt ? new Date(poll.expiresAt).toISOString() : null,
choices,
};
}
} }