Files
Desktop/ts/util/enqueuePollCreateForSend.dom.ts
2026-03-30 12:42:37 -07:00

35 lines
804 B
TypeScript

// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationModel } from '../models/conversations.preload.ts';
import { isDirectConversation } from './whatTypeOfConversation.dom.ts';
import {
isPollSend1to1Enabled,
type PollCreateType,
} from '../types/Polls.dom.ts';
export async function enqueuePollCreateForSend(
conversation: ConversationModel,
poll: PollCreateType
): Promise<void> {
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(),
}
);
}