2021-01-14 18:07:05 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
2020-12-07 20:43:19 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../types/Util';
|
2020-12-07 20:43:19 +00:00
|
|
|
import { CallMode } from '../types/Calling';
|
|
|
|
import { missingCaseError } from './missingCaseError';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../logging/log';
|
2020-12-07 20:43:19 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
type DirectCallNotificationType = {
|
2020-12-07 20:43:19 +00:00
|
|
|
callMode: CallMode.Direct;
|
|
|
|
wasIncoming: boolean;
|
|
|
|
wasVideoCall: boolean;
|
|
|
|
wasDeclined: boolean;
|
|
|
|
acceptedTime?: number;
|
|
|
|
endedTime: number;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-12-07 20:43:19 +00:00
|
|
|
|
2021-01-14 18:07:05 +00:00
|
|
|
type GroupCallNotificationType = {
|
2020-12-07 20:43:19 +00:00
|
|
|
activeCallConversationId?: string;
|
|
|
|
callMode: CallMode.Group;
|
|
|
|
conversationId: string;
|
|
|
|
creator?: {
|
|
|
|
firstName?: string;
|
|
|
|
isMe?: boolean;
|
|
|
|
title: string;
|
|
|
|
};
|
|
|
|
ended: boolean;
|
|
|
|
deviceCount: number;
|
|
|
|
maxDevices: number;
|
|
|
|
startedTime: number;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-12-07 20:43:19 +00:00
|
|
|
|
|
|
|
export type CallingNotificationType =
|
|
|
|
| DirectCallNotificationType
|
|
|
|
| GroupCallNotificationType;
|
|
|
|
|
|
|
|
function getDirectCallNotificationText(
|
|
|
|
{
|
|
|
|
wasIncoming,
|
|
|
|
wasVideoCall,
|
|
|
|
wasDeclined,
|
|
|
|
acceptedTime,
|
|
|
|
}: DirectCallNotificationType,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): string {
|
|
|
|
const wasAccepted = Boolean(acceptedTime);
|
|
|
|
|
|
|
|
if (wasIncoming) {
|
|
|
|
if (wasDeclined) {
|
|
|
|
if (wasVideoCall) {
|
|
|
|
return i18n('declinedIncomingVideoCall');
|
|
|
|
}
|
|
|
|
return i18n('declinedIncomingAudioCall');
|
|
|
|
}
|
|
|
|
if (wasAccepted) {
|
|
|
|
if (wasVideoCall) {
|
|
|
|
return i18n('acceptedIncomingVideoCall');
|
|
|
|
}
|
|
|
|
return i18n('acceptedIncomingAudioCall');
|
|
|
|
}
|
|
|
|
if (wasVideoCall) {
|
|
|
|
return i18n('missedIncomingVideoCall');
|
|
|
|
}
|
|
|
|
return i18n('missedIncomingAudioCall');
|
|
|
|
}
|
|
|
|
if (wasAccepted) {
|
|
|
|
if (wasVideoCall) {
|
|
|
|
return i18n('acceptedOutgoingVideoCall');
|
|
|
|
}
|
|
|
|
return i18n('acceptedOutgoingAudioCall');
|
|
|
|
}
|
|
|
|
if (wasVideoCall) {
|
|
|
|
return i18n('missedOrDeclinedOutgoingVideoCall');
|
|
|
|
}
|
|
|
|
return i18n('missedOrDeclinedOutgoingAudioCall');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getGroupCallNotificationText(
|
|
|
|
notification: GroupCallNotificationType,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): string {
|
|
|
|
if (notification.ended) {
|
|
|
|
return i18n('calling__call-notification__ended');
|
|
|
|
}
|
|
|
|
if (!notification.creator) {
|
|
|
|
return i18n('calling__call-notification__started-by-someone');
|
|
|
|
}
|
|
|
|
if (notification.creator.isMe) {
|
|
|
|
return i18n('calling__call-notification__started-by-you');
|
|
|
|
}
|
|
|
|
return i18n('calling__call-notification__started', [
|
|
|
|
notification.creator.firstName || notification.creator.title,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCallingNotificationText(
|
|
|
|
notification: CallingNotificationType,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): string {
|
|
|
|
switch (notification.callMode) {
|
|
|
|
case CallMode.Direct:
|
|
|
|
return getDirectCallNotificationText(notification, i18n);
|
|
|
|
case CallMode.Group:
|
|
|
|
return getGroupCallNotificationText(notification, i18n);
|
|
|
|
default:
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error(
|
2021-05-19 22:00:57 +00:00
|
|
|
`getCallingNotificationText: missing case ${missingCaseError(
|
|
|
|
notification
|
|
|
|
)}`
|
|
|
|
);
|
2020-12-07 20:43:19 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 20:51:55 +00:00
|
|
|
|
|
|
|
type CallingIconType =
|
|
|
|
| 'audio-incoming'
|
|
|
|
| 'audio-missed'
|
|
|
|
| 'audio-outgoing'
|
|
|
|
| 'phone'
|
|
|
|
| 'video'
|
|
|
|
| 'video-incoming'
|
|
|
|
| 'video-missed'
|
|
|
|
| 'video-outgoing';
|
|
|
|
|
|
|
|
function getDirectCallingIcon({
|
|
|
|
wasIncoming,
|
|
|
|
wasVideoCall,
|
|
|
|
acceptedTime,
|
|
|
|
}: DirectCallNotificationType): CallingIconType {
|
|
|
|
const wasAccepted = Boolean(acceptedTime);
|
|
|
|
|
|
|
|
// video
|
|
|
|
if (wasVideoCall) {
|
|
|
|
if (wasAccepted) {
|
|
|
|
return wasIncoming ? 'video-incoming' : 'video-outgoing';
|
|
|
|
}
|
|
|
|
return 'video-missed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wasAccepted) {
|
|
|
|
return wasIncoming ? 'audio-incoming' : 'audio-outgoing';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'audio-missed';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCallingIcon(
|
|
|
|
notification: CallingNotificationType
|
|
|
|
): CallingIconType {
|
|
|
|
switch (notification.callMode) {
|
|
|
|
case CallMode.Direct:
|
|
|
|
return getDirectCallingIcon(notification);
|
|
|
|
case CallMode.Group:
|
|
|
|
return 'video';
|
|
|
|
default:
|
2021-09-17 18:27:53 +00:00
|
|
|
log.error(
|
2021-08-26 20:51:55 +00:00
|
|
|
`getCallingNotificationText: missing case ${missingCaseError(
|
|
|
|
notification
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
return 'phone';
|
|
|
|
}
|
|
|
|
}
|