signal-desktop/ts/util/callLinks.ts

87 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-02-22 21:19:50 +00:00
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2024-07-24 21:35:36 +00:00
import { v4 as generateUuid } from 'uuid';
2024-06-10 15:23:43 +00:00
import * as RemoteConfig from '../RemoteConfig';
2024-04-01 19:19:35 +00:00
import * as Bytes from '../Bytes';
import type { CallLinkConversationType, CallLinkType } from '../types/CallLink';
import { CallLinkRestrictions } from '../types/CallLink';
2024-02-22 21:19:50 +00:00
import type { LocalizerType } from '../types/Util';
2024-06-10 15:23:43 +00:00
import { isTestOrMockEnvironment } from '../environment';
import { getColorForCallLink } from './getColorForCallLink';
2024-07-24 21:35:36 +00:00
import {
AdhocCallStatus,
CallDirection,
CallType,
type CallHistoryDetails,
CallMode,
2024-07-24 21:35:36 +00:00
} from '../types/CallDisposition';
2024-02-22 21:19:50 +00:00
2024-04-25 17:09:05 +00:00
export const CALL_LINK_DEFAULT_STATE = {
name: '',
restrictions: CallLinkRestrictions.Unknown,
revoked: false,
expiration: null,
};
2024-06-10 15:23:43 +00:00
export function isCallLinksCreateEnabled(): boolean {
if (isTestOrMockEnvironment()) {
return true;
}
return RemoteConfig.getValue('desktop.calling.adhoc.create') === 'TRUE';
}
2024-02-22 21:19:50 +00:00
export function callLinkToConversation(
callLink: CallLinkType,
i18n: LocalizerType
): CallLinkConversationType {
const { roomId, name, rootKey } = callLink;
2024-02-22 21:19:50 +00:00
return {
id: roomId,
type: 'callLink',
color: getColorForCallLink(rootKey),
2024-02-22 21:19:50 +00:00
isMe: false,
title: name || i18n('icu:calling__call-link-default-title'),
sharedGroupNames: [],
acceptedMessageRequest: true,
badges: [],
};
}
2024-04-01 19:19:35 +00:00
2024-04-25 17:09:05 +00:00
export function getPlaceholderCallLinkConversation(
roomId: string,
i18n: LocalizerType
): CallLinkConversationType {
return {
id: roomId,
type: 'callLink',
isMe: false,
title: i18n('icu:calling__call-link-default-title'),
sharedGroupNames: [],
acceptedMessageRequest: true,
badges: [],
};
}
2024-06-10 15:23:43 +00:00
export function toAdminKeyBytes(adminKey: string): Buffer {
return Buffer.from(adminKey, 'base64');
2024-04-25 17:09:05 +00:00
}
export function fromAdminKeyBytes(adminKey: Uint8Array): string {
return Bytes.toBase64(adminKey);
}
2024-07-24 21:35:36 +00:00
export function toCallHistoryFromUnusedCallLink(
callLink: CallLinkType
): CallHistoryDetails {
return {
callId: generateUuid(),
peerId: callLink.roomId,
ringerId: null,
mode: CallMode.Adhoc,
type: CallType.Adhoc,
direction: CallDirection.Incoming,
timestamp: Date.now(),
status: AdhocCallStatus.Pending,
};
}