Files
Desktop/ts/util/enqueuePollCreateForSend.dom.ts
automated-signal 7e47676b90 Polls: Support sending polls in 1:1 conversations
Co-authored-by: yash-signal <yash@signal.org>
2026-02-25 08:18:18 +10:00

40 lines
938 B
TypeScript

// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationModel } from '../models/conversations.preload.js';
import { isDirectConversation } from './whatTypeOfConversation.dom.js';
import {
isPollSend1to1Enabled,
isPollSendEnabled,
type PollCreateType,
} from '../types/Polls.dom.js';
export async function enqueuePollCreateForSend(
conversation: ConversationModel,
poll: PollCreateType
): Promise<void> {
if (!isPollSendEnabled()) {
throw new Error('enqueuePollCreateForSend: poll sending is not enabled');
}
if (
isDirectConversation(conversation.attributes) &&
!isPollSend1to1Enabled()
) {
throw new Error(
'enqueuePollCreateForSend: 1:1 poll sending is not enabled'
);
}
await conversation.enqueueMessageForSend(
{
attachments: [],
body: undefined,
poll,
},
{
timestamp: Date.now(),
}
);
}