Matrix: accept messageId alias for poll votes
This commit is contained in:
parent
20728e1035
commit
7f86be1037
@ -119,6 +119,25 @@ describe("handleMatrixAction pollVote", () => {
|
||||
).rejects.toThrow("pollId required");
|
||||
});
|
||||
|
||||
it("accepts messageId as a pollId alias for poll votes", async () => {
|
||||
const cfg = {} as CoreConfig;
|
||||
await handleMatrixAction(
|
||||
{
|
||||
action: "pollVote",
|
||||
roomId: "!room:example",
|
||||
messageId: "$poll",
|
||||
pollOptionIndex: 1,
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
|
||||
expect(mocks.voteMatrixPoll).toHaveBeenCalledWith("!room:example", "$poll", {
|
||||
cfg,
|
||||
optionIds: [],
|
||||
optionIndexes: [1],
|
||||
});
|
||||
});
|
||||
|
||||
it("passes account-scoped opts to add reactions", async () => {
|
||||
const cfg = { channels: { matrix: { actions: { reactions: true } } } } as CoreConfig;
|
||||
await handleMatrixAction(
|
||||
|
||||
@ -97,6 +97,27 @@ function readRawParam(params: Record<string, unknown>, key: string): unknown {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function readStringAliasParam(
|
||||
params: Record<string, unknown>,
|
||||
keys: string[],
|
||||
options: { required?: boolean } = {},
|
||||
): string | undefined {
|
||||
for (const key of keys) {
|
||||
const raw = readRawParam(params, key);
|
||||
if (typeof raw !== "string") {
|
||||
continue;
|
||||
}
|
||||
const trimmed = raw.trim();
|
||||
if (trimmed) {
|
||||
return trimmed;
|
||||
}
|
||||
}
|
||||
if (options.required) {
|
||||
throw new Error(`${keys[0]} required`);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function readNumericArrayParam(
|
||||
params: Record<string, unknown>,
|
||||
key: string,
|
||||
@ -169,7 +190,10 @@ export async function handleMatrixAction(
|
||||
|
||||
if (pollActions.has(action)) {
|
||||
const roomId = readRoomId(params);
|
||||
const pollId = readStringParam(params, "pollId", { required: true });
|
||||
const pollId = readStringAliasParam(params, ["pollId", "messageId"], { required: true });
|
||||
if (!pollId) {
|
||||
throw new Error("pollId required");
|
||||
}
|
||||
const optionId = readStringParam(params, "pollOptionId");
|
||||
const optionIndex = readNumberParam(params, "pollOptionIndex", { integer: true });
|
||||
const optionIds = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user