Skip to content

Commit 64307a3

Browse files
committed
fix: parse stable poll response payloads
1 parent 901cd66 commit 64307a3

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/app/features/room/poll/PollEvent.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function extractPollData(mEvent: MatrixEvent): {
6262
'm.text'?: { body: string }[];
6363
}[] = pollData.answers ?? [];
6464
const answers: PollAnswer[] = rawAnswers.slice(0, 20).map((a) => ({
65-
id: String(a['m.id'] ?? a.id ?? ''),
65+
id: a['m.id'] ?? a.id ?? '',
6666
text:
6767
(a['m.text'] as { body: string }[] | undefined)?.[0]?.body ??
6868
a['org.matrix.msc1767.text'] ??
@@ -84,11 +84,12 @@ export function extractPollData(mEvent: MatrixEvent): {
8484

8585
export function extractVoteSelections(responseEvent: MatrixEvent): string[] {
8686
const content = responseEvent.getContent();
87-
const unstablePayload = content['org.matrix.msc3381.poll.response'];
87+
const responsePayload =
88+
content[M_POLL_RESPONSE.name] ?? content[M_POLL_RESPONSE.altName ?? 'm.poll.response'];
8889
const selections: unknown =
8990
content['m.selections'] ??
90-
(typeof unstablePayload === 'object' && unstablePayload !== null
91-
? (unstablePayload as { answers?: unknown }).answers
91+
(typeof responsePayload === 'object' && responsePayload !== null
92+
? (responsePayload as { answers?: unknown }).answers
9293
: undefined);
9394
if (!Array.isArray(selections)) return [];
9495
return selections.filter((s): s is string => typeof s === 'string');

0 commit comments

Comments
 (0)