mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-20 00:18:45 +01:00
Sync call link call history
This commit is contained in:
82
ts/util/sendCallLinkUpdateSync.ts
Normal file
82
ts/util/sendCallLinkUpdateSync.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import * as Bytes from '../Bytes';
|
||||
import { CallLinkUpdateSyncType } from '../types/CallLink';
|
||||
import * as log from '../logging/log';
|
||||
import * as Errors from '../types/errors';
|
||||
import { SignalService as Proto } from '../protobuf';
|
||||
import { singleProtoJobQueue } from '../jobs/singleProtoJobQueue';
|
||||
import MessageSender from '../textsecure/SendMessage';
|
||||
import { toAdminKeyBytes, toRootKeyBytes } from './callLinks';
|
||||
|
||||
export type sendCallLinkUpdateSyncCallLinkType = {
|
||||
rootKey: string;
|
||||
adminKey: string | null;
|
||||
};
|
||||
|
||||
export async function sendCallLinkUpdateSync(
|
||||
callLink: sendCallLinkUpdateSyncCallLinkType
|
||||
): Promise<void> {
|
||||
return _sendCallLinkUpdateSync(callLink, CallLinkUpdateSyncType.Update);
|
||||
}
|
||||
|
||||
/**
|
||||
* Underlying sync message is CallLinkUpdate with type set to DELETE.
|
||||
*/
|
||||
export async function sendCallLinkDeleteSync(
|
||||
callLink: sendCallLinkUpdateSyncCallLinkType
|
||||
): Promise<void> {
|
||||
return _sendCallLinkUpdateSync(callLink, CallLinkUpdateSyncType.Delete);
|
||||
}
|
||||
|
||||
async function _sendCallLinkUpdateSync(
|
||||
callLink: sendCallLinkUpdateSyncCallLinkType,
|
||||
type: CallLinkUpdateSyncType
|
||||
): Promise<void> {
|
||||
let protoType: Proto.SyncMessage.CallLinkUpdate.Type;
|
||||
if (type === CallLinkUpdateSyncType.Update) {
|
||||
protoType = Proto.SyncMessage.CallLinkUpdate.Type.UPDATE;
|
||||
} else if (type === CallLinkUpdateSyncType.Delete) {
|
||||
protoType = Proto.SyncMessage.CallLinkUpdate.Type.DELETE;
|
||||
} else {
|
||||
throw new Error(`sendCallLinkUpdateSync: unknown type ${type}`);
|
||||
}
|
||||
|
||||
log.info(`sendCallLinkUpdateSync: Sending CallLinkUpdate type=${type}`);
|
||||
|
||||
try {
|
||||
const ourAci = window.textsecure.storage.user.getCheckedAci();
|
||||
|
||||
const callLinkUpdate = new Proto.SyncMessage.CallLinkUpdate({
|
||||
type: protoType,
|
||||
rootKey: toRootKeyBytes(callLink.rootKey),
|
||||
adminPasskey: callLink.adminKey
|
||||
? toAdminKeyBytes(callLink.adminKey)
|
||||
: null,
|
||||
});
|
||||
|
||||
const syncMessage = MessageSender.createSyncMessage();
|
||||
syncMessage.callLinkUpdate = callLinkUpdate;
|
||||
|
||||
const contentMessage = new Proto.Content();
|
||||
contentMessage.syncMessage = syncMessage;
|
||||
|
||||
const { ContentHint } = Proto.UnidentifiedSenderMessage.Message;
|
||||
|
||||
await singleProtoJobQueue.add({
|
||||
contentHint: ContentHint.RESENDABLE,
|
||||
serviceId: ourAci,
|
||||
isSyncMessage: true,
|
||||
protoBase64: Bytes.toBase64(
|
||||
Proto.Content.encode(contentMessage).finish()
|
||||
),
|
||||
type: 'callLinkUpdateSync',
|
||||
urgent: false,
|
||||
});
|
||||
} catch (error) {
|
||||
log.error(
|
||||
'sendCallLinkUpdateSync: Failed to queue sync message:',
|
||||
Errors.toLogFormat(error)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user