signal-desktop/ts/shims/textsecure.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-04-08 16:24:21 +00:00
// Copyright 2019-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import { handleMessageSend } from '../util/handleMessageSend';
import { getSendOptions } from '../util/getSendOptions';
2021-04-08 16:24:21 +00:00
export async function sendStickerPackSync(
packId: string,
packKey: string,
installed: boolean
2021-04-08 16:24:21 +00:00
): Promise<void> {
const { ConversationController, textsecure, log } = window;
const ourConversation = ConversationController.getOurConversationOrThrow();
const sendOptions = await getSendOptions(ourConversation.attributes, {
syncMessage: true,
});
if (!textsecure.messaging) {
log.error(
'shim: Cannot call sendStickerPackSync, textsecure.messaging is falsey'
);
return;
}
if (window.ConversationController.areWePrimaryDevice()) {
window.log.warn(
'shims/sendStickerPackSync: We are primary device; not sending sync'
);
return;
}
handleMessageSend(
textsecure.messaging.sendStickerPackSync(
[
{
packId,
packKey,
installed,
},
],
sendOptions
),
{ messageIds: [], sendType: 'otherSync' }
).catch(error => {
log.error(
'shim: Error calling sendStickerPackSync:',
error && error.stack ? error.stack : error
);
});
}