2021-08-17 21:45:18 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import React from 'react';
|
2021-08-17 21:45:18 +00:00
|
|
|
import type { ConversationType } from '../state/ducks/conversations';
|
|
|
|
import type { LocalizerType } from '../types/Util';
|
|
|
|
import { Avatar, AvatarSize } from './Avatar';
|
|
|
|
import { Emojify } from './conversation/Emojify';
|
2021-08-20 16:06:15 +00:00
|
|
|
import { getParticipantName } from '../util/callingGetParticipantName';
|
2021-08-17 21:45:18 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
|
|
|
|
2021-08-25 21:42:51 +00:00
|
|
|
export enum RingMode {
|
|
|
|
WillNotRing,
|
|
|
|
WillRing,
|
|
|
|
IsRinging,
|
|
|
|
}
|
|
|
|
|
2021-08-17 21:45:18 +00:00
|
|
|
type PropsType = {
|
|
|
|
conversation: Pick<
|
|
|
|
ConversationType,
|
|
|
|
| 'acceptedMessageRequest'
|
|
|
|
| 'avatarPath'
|
|
|
|
| 'color'
|
|
|
|
| 'isMe'
|
|
|
|
| 'phoneNumber'
|
|
|
|
| 'profileName'
|
|
|
|
| 'sharedGroupNames'
|
|
|
|
| 'title'
|
|
|
|
| 'type'
|
|
|
|
| 'unblurredAvatarPath'
|
|
|
|
>;
|
|
|
|
i18n: LocalizerType;
|
2021-08-25 21:42:51 +00:00
|
|
|
me: Pick<ConversationType, 'id' | 'uuid'>;
|
|
|
|
ringMode: RingMode;
|
2021-08-17 21:45:18 +00:00
|
|
|
|
|
|
|
// The following should only be set for group conversations.
|
2021-08-25 21:42:51 +00:00
|
|
|
groupMembers?: Array<Pick<ConversationType, 'id' | 'firstName' | 'title'>>;
|
2021-08-17 21:45:18 +00:00
|
|
|
isCallFull?: boolean;
|
|
|
|
peekedParticipants?: Array<
|
|
|
|
Pick<ConversationType, 'firstName' | 'title' | 'uuid'>
|
|
|
|
>;
|
|
|
|
};
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function CallingPreCallInfo({
|
2021-08-17 21:45:18 +00:00
|
|
|
conversation,
|
|
|
|
groupMembers = [],
|
|
|
|
i18n,
|
|
|
|
isCallFull = false,
|
|
|
|
me,
|
|
|
|
peekedParticipants = [],
|
2021-08-25 21:42:51 +00:00
|
|
|
ringMode,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2021-08-17 21:45:18 +00:00
|
|
|
let subtitle: string;
|
2021-08-25 21:42:51 +00:00
|
|
|
if (ringMode === RingMode.IsRinging) {
|
|
|
|
subtitle = i18n('outgoingCallRinging');
|
|
|
|
} else if (isCallFull) {
|
2021-08-17 21:45:18 +00:00
|
|
|
subtitle = i18n('calling__call-is-full');
|
|
|
|
} else if (peekedParticipants.length) {
|
|
|
|
// It should be rare to see yourself in this list, but it's possible if (1) you rejoin
|
|
|
|
// quickly, causing the server to return stale state (2) you have joined on another
|
|
|
|
// device.
|
|
|
|
let hasYou = false;
|
|
|
|
const participantNames = peekedParticipants.map(participant => {
|
|
|
|
if (participant.uuid === me.uuid) {
|
|
|
|
hasYou = true;
|
|
|
|
return i18n('you');
|
|
|
|
}
|
|
|
|
return getParticipantName(participant);
|
|
|
|
});
|
|
|
|
|
|
|
|
switch (participantNames.length) {
|
|
|
|
case 1:
|
|
|
|
subtitle = hasYou
|
|
|
|
? i18n('calling__pre-call-info--another-device-in-call')
|
|
|
|
: i18n('calling__pre-call-info--1-person-in-call', participantNames);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
subtitle = i18n('calling__pre-call-info--2-people-in-call', {
|
|
|
|
first: participantNames[0],
|
|
|
|
second: participantNames[1],
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
subtitle = i18n('calling__pre-call-info--3-people-in-call', {
|
|
|
|
first: participantNames[0],
|
|
|
|
second: participantNames[1],
|
|
|
|
third: participantNames[2],
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
subtitle = i18n('calling__pre-call-info--many-people-in-call', {
|
|
|
|
first: participantNames[0],
|
|
|
|
second: participantNames[1],
|
|
|
|
others: String(participantNames.length - 2),
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2021-08-25 21:42:51 +00:00
|
|
|
} else {
|
|
|
|
let memberNames: Array<string>;
|
|
|
|
switch (conversation.type) {
|
|
|
|
case 'direct':
|
|
|
|
memberNames = [getParticipantName(conversation)];
|
|
|
|
break;
|
|
|
|
case 'group':
|
|
|
|
memberNames = groupMembers
|
|
|
|
.filter(member => member.id !== me.id)
|
|
|
|
.map(getParticipantName);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw missingCaseError(conversation.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ring = ringMode === RingMode.WillRing;
|
2021-08-17 21:45:18 +00:00
|
|
|
|
|
|
|
switch (memberNames.length) {
|
|
|
|
case 0:
|
|
|
|
subtitle = i18n('calling__pre-call-info--empty-group');
|
|
|
|
break;
|
2021-08-25 21:42:51 +00:00
|
|
|
case 1: {
|
|
|
|
const i18nValues = [memberNames[0]];
|
|
|
|
subtitle = ring
|
|
|
|
? i18n('calling__pre-call-info--will-ring-1', i18nValues)
|
|
|
|
: i18n('calling__pre-call-info--will-notify-1', i18nValues);
|
2021-08-17 21:45:18 +00:00
|
|
|
break;
|
2021-08-25 21:42:51 +00:00
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
const i18nValues = {
|
2021-08-17 21:45:18 +00:00
|
|
|
first: memberNames[0],
|
|
|
|
second: memberNames[1],
|
2021-08-25 21:42:51 +00:00
|
|
|
};
|
|
|
|
subtitle = ring
|
|
|
|
? i18n('calling__pre-call-info--will-ring-2', i18nValues)
|
|
|
|
: i18n('calling__pre-call-info--will-notify-2', i18nValues);
|
2021-08-17 21:45:18 +00:00
|
|
|
break;
|
2021-08-25 21:42:51 +00:00
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
const i18nValues = {
|
2021-08-17 21:45:18 +00:00
|
|
|
first: memberNames[0],
|
|
|
|
second: memberNames[1],
|
|
|
|
third: memberNames[2],
|
2021-08-25 21:42:51 +00:00
|
|
|
};
|
|
|
|
subtitle = ring
|
|
|
|
? i18n('calling__pre-call-info--will-ring-3', i18nValues)
|
|
|
|
: i18n('calling__pre-call-info--will-notify-3', i18nValues);
|
2021-08-17 21:45:18 +00:00
|
|
|
break;
|
2021-08-25 21:42:51 +00:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
const i18nValues = {
|
2021-08-17 21:45:18 +00:00
|
|
|
first: memberNames[0],
|
|
|
|
second: memberNames[1],
|
|
|
|
others: String(memberNames.length - 2),
|
2021-08-25 21:42:51 +00:00
|
|
|
};
|
|
|
|
subtitle = ring
|
|
|
|
? i18n('calling__pre-call-info--will-ring-many', i18nValues)
|
|
|
|
: i18n('calling__pre-call-info--will-notify-many', i18nValues);
|
2021-08-17 21:45:18 +00:00
|
|
|
break;
|
2021-08-25 21:42:51 +00:00
|
|
|
}
|
2021-08-17 21:45:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="module-CallingPreCallInfo">
|
|
|
|
<Avatar
|
|
|
|
avatarPath={conversation.avatarPath}
|
2021-12-01 17:24:00 +00:00
|
|
|
badge={undefined}
|
2021-08-17 21:45:18 +00:00
|
|
|
color={conversation.color}
|
|
|
|
acceptedMessageRequest={conversation.acceptedMessageRequest}
|
|
|
|
conversationType={conversation.type}
|
|
|
|
isMe={conversation.isMe}
|
|
|
|
noteToSelf={false}
|
|
|
|
phoneNumber={conversation.phoneNumber}
|
|
|
|
profileName={conversation.profileName}
|
|
|
|
sharedGroupNames={conversation.sharedGroupNames}
|
|
|
|
size={AvatarSize.ONE_HUNDRED_TWELVE}
|
|
|
|
title={conversation.title}
|
|
|
|
unblurredAvatarPath={conversation.unblurredAvatarPath}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
<div className="module-CallingPreCallInfo__title">
|
|
|
|
<Emojify text={conversation.title} />
|
|
|
|
</div>
|
|
|
|
<div className="module-CallingPreCallInfo__subtitle">{subtitle}</div>
|
|
|
|
</div>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|