mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-27 03:43:27 +01:00
Initial Poll message receive support
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { isNumber } from 'lodash';
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { createLogger } from '../logging/log.js';
|
||||
import * as Errors from '../types/errors.js';
|
||||
@@ -56,6 +57,8 @@ import {
|
||||
} from '../util/modifyTargetMessage.js';
|
||||
import { saveAndNotify } from './saveAndNotify.js';
|
||||
import { MessageModel } from '../models/messages.js';
|
||||
import { safeParsePartial } from '../util/schemas.js';
|
||||
import { PollCreateSchema, isPollReceiveEnabled } from '../types/Polls.js';
|
||||
|
||||
import type { SentEventData } from '../textsecure/messageReceiverEvents.js';
|
||||
import type {
|
||||
@@ -481,6 +484,35 @@ export async function handleDataMessage(
|
||||
}
|
||||
}
|
||||
|
||||
let validatedPollCreate: z.infer<typeof PollCreateSchema> | undefined;
|
||||
if (initialMessage.pollCreate) {
|
||||
if (!isPollReceiveEnabled()) {
|
||||
log.warn(`${idLog}: Dropping PollCreate because flag is not enabled`);
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
if (!isGroup(conversation.attributes)) {
|
||||
log.warn(
|
||||
`${idLog}: Dropping PollCreate in non-group conversation ${conversation.idForLogging()}`
|
||||
);
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
const result = safeParsePartial(
|
||||
PollCreateSchema,
|
||||
initialMessage.pollCreate
|
||||
);
|
||||
if (!result.success) {
|
||||
log.warn(
|
||||
`${idLog}: Dropping invalid PollCreate:`,
|
||||
result.error.flatten()
|
||||
);
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
validatedPollCreate = result.data;
|
||||
}
|
||||
|
||||
const withQuoteReference = {
|
||||
...message.attributes,
|
||||
...initialMessage,
|
||||
@@ -576,6 +608,14 @@ export async function handleDataMessage(
|
||||
quote: dataMessage.quote,
|
||||
schemaVersion: dataMessage.schemaVersion,
|
||||
sticker: dataMessage.sticker,
|
||||
poll: validatedPollCreate
|
||||
? {
|
||||
question: validatedPollCreate.question,
|
||||
options: validatedPollCreate.options,
|
||||
allowMultiple: Boolean(validatedPollCreate.allowMultiple),
|
||||
votes: [],
|
||||
}
|
||||
: undefined,
|
||||
storyId: dataMessage.storyId,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user