fix: handle legacy matrix polls (#1088) (thanks @sibbl)
This commit is contained in:
@@ -7,6 +7,9 @@ Docs: https://docs.clawd.bot
|
|||||||
### Changes
|
### Changes
|
||||||
- macOS: strip prerelease/build suffixes when parsing gateway semver patches. (#1110) — thanks @zerone0x.
|
- macOS: strip prerelease/build suffixes when parsing gateway semver patches. (#1110) — thanks @zerone0x.
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Matrix: send voice/image-specific media payloads and keep legacy poll parsing. (#1088) — thanks @sibbl.
|
||||||
|
|
||||||
## 2026.1.16-2
|
## 2026.1.16-2
|
||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
|
|||||||
22
extensions/matrix/src/matrix/poll-types.test.ts
Normal file
22
extensions/matrix/src/matrix/poll-types.test.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { parsePollStartContent } from "./poll-types.js";
|
||||||
|
|
||||||
|
describe("parsePollStartContent", () => {
|
||||||
|
it("parses legacy m.poll payloads", () => {
|
||||||
|
const summary = parsePollStartContent({
|
||||||
|
"m.poll": {
|
||||||
|
question: { "m.text": "Lunch?" },
|
||||||
|
kind: "m.poll.disclosed",
|
||||||
|
max_selections: 1,
|
||||||
|
answers: [
|
||||||
|
{ id: "answer1", "m.text": "Yes" },
|
||||||
|
{ id: "answer2", "m.text": "No" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(summary?.question).toBe("Lunch?");
|
||||||
|
expect(summary?.answers).toEqual(["Yes", "No"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -42,7 +42,18 @@ export type PollAnswer = {
|
|||||||
id: string;
|
id: string;
|
||||||
} & TextContent;
|
} & TextContent;
|
||||||
|
|
||||||
export type PollStartContent = TimelineEvents[typeof M_POLL_START];
|
export type PollStartSubtype = {
|
||||||
|
question: TextContent;
|
||||||
|
kind?: PollKind;
|
||||||
|
max_selections?: number;
|
||||||
|
answers: PollAnswer[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LegacyPollStartContent = {
|
||||||
|
"m.poll"?: PollStartSubtype;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PollStartContent = TimelineEvents[typeof M_POLL_START] | LegacyPollStartContent;
|
||||||
|
|
||||||
export type PollSummary = {
|
export type PollSummary = {
|
||||||
eventId: string;
|
eventId: string;
|
||||||
@@ -65,7 +76,9 @@ export function getTextContent(text?: TextContent): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function parsePollStartContent(content: PollStartContent): PollSummary | null {
|
export function parsePollStartContent(content: PollStartContent): PollSummary | null {
|
||||||
const poll = content[M_POLL_START] ?? content[ORG_POLL_START];
|
const poll = (content as Record<string, PollStartSubtype | undefined>)[M_POLL_START]
|
||||||
|
?? (content as Record<string, PollStartSubtype | undefined>)[ORG_POLL_START]
|
||||||
|
?? (content as Record<string, PollStartSubtype | undefined>)["m.poll"];
|
||||||
if (!poll) return null;
|
if (!poll) return null;
|
||||||
|
|
||||||
const question = getTextContent(poll.question);
|
const question = getTextContent(poll.question);
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ vi.mock("../../../../src/web/media.js", () => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock("../../../../src/media/image-ops.js", () => ({
|
||||||
|
getImageMetadata: vi.fn().mockResolvedValue(null),
|
||||||
|
resizeToJpeg: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
let sendMessageMatrix: typeof import("./send.js").sendMessageMatrix;
|
let sendMessageMatrix: typeof import("./send.js").sendMessageMatrix;
|
||||||
|
|
||||||
const makeClient = () => {
|
const makeClient = () => {
|
||||||
@@ -65,13 +70,13 @@ describe("sendMessageMatrix media", () => {
|
|||||||
const uploadArg = uploadContent.mock.calls[0]?.[0];
|
const uploadArg = uploadContent.mock.calls[0]?.[0];
|
||||||
expect(Buffer.isBuffer(uploadArg)).toBe(true);
|
expect(Buffer.isBuffer(uploadArg)).toBe(true);
|
||||||
|
|
||||||
const content = sendMessage.mock.calls[0]?.[2] as {
|
const content = sendMessage.mock.calls[0]?.[1] as {
|
||||||
url?: string;
|
url?: string;
|
||||||
msgtype?: string;
|
msgtype?: string;
|
||||||
format?: string;
|
format?: string;
|
||||||
formatted_body?: string;
|
formatted_body?: string;
|
||||||
};
|
};
|
||||||
expect(content.msgtype).toBe("m.file");
|
expect(content.msgtype).toBe("m.image");
|
||||||
expect(content.format).toBe("org.matrix.custom.html");
|
expect(content.format).toBe("org.matrix.custom.html");
|
||||||
expect(content.formatted_body).toContain("caption");
|
expect(content.formatted_body).toContain("caption");
|
||||||
expect(content.url).toBe("mxc://example/file");
|
expect(content.url).toBe("mxc://example/file");
|
||||||
|
|||||||
Reference in New Issue
Block a user