2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-26 00:08:58 +00:00
|
|
|
import * as React from 'react';
|
2020-07-24 01:35:32 +00:00
|
|
|
|
2020-06-26 00:08:58 +00:00
|
|
|
import { Avatar } from './Avatar';
|
|
|
|
import { ConfirmationModal } from './ConfirmationModal';
|
2020-07-24 01:35:32 +00:00
|
|
|
import { InContactsIcon } from './InContactsIcon';
|
|
|
|
|
2020-06-26 00:08:58 +00:00
|
|
|
import { ConversationType } from '../state/ducks/conversations';
|
|
|
|
import { LocalizerType } from '../types/Util';
|
|
|
|
|
|
|
|
type SafetyNumberProps = {
|
|
|
|
contactID: string;
|
|
|
|
onClose?: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Props = {
|
2020-08-26 20:30:10 +00:00
|
|
|
readonly confirmText?: string;
|
2020-06-26 00:08:58 +00:00
|
|
|
readonly contacts: Array<ConversationType>;
|
|
|
|
readonly i18n: LocalizerType;
|
|
|
|
readonly onCancel: () => void;
|
|
|
|
readonly onConfirm: () => void;
|
|
|
|
readonly renderSafetyNumber: (props: SafetyNumberProps) => JSX.Element;
|
|
|
|
};
|
|
|
|
|
|
|
|
type SafetyDialogContentProps = Props & {
|
|
|
|
readonly onView: (contact: ConversationType) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
const SafetyDialogContents = ({
|
2020-08-26 20:30:10 +00:00
|
|
|
confirmText,
|
2020-06-26 00:08:58 +00:00
|
|
|
contacts,
|
|
|
|
i18n,
|
|
|
|
onCancel,
|
|
|
|
onConfirm,
|
|
|
|
onView,
|
|
|
|
}: SafetyDialogContentProps): JSX.Element => {
|
|
|
|
const cancelButtonRef = React.createRef<HTMLButtonElement>();
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (cancelButtonRef && cancelButtonRef.current) {
|
|
|
|
cancelButtonRef.current.focus();
|
|
|
|
}
|
2020-09-12 00:46:52 +00:00
|
|
|
}, [cancelButtonRef, contacts]);
|
2020-06-26 00:08:58 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h1 className="module-sfn-dialog__title">
|
|
|
|
{i18n('safetyNumberChanges')}
|
|
|
|
</h1>
|
|
|
|
<div className="module-sfn-dialog__message">
|
|
|
|
{i18n('changedVerificationWarning')}
|
|
|
|
</div>
|
|
|
|
<ul className="module-sfn-dialog__contacts">
|
2020-07-24 01:35:32 +00:00
|
|
|
{contacts.map((contact: ConversationType) => {
|
|
|
|
const shouldShowNumber = Boolean(contact.name || contact.profileName);
|
|
|
|
|
|
|
|
return (
|
2020-07-29 23:20:05 +00:00
|
|
|
<li className="module-sfn-dialog__contact" key={contact.id}>
|
2020-07-24 01:35:32 +00:00
|
|
|
<Avatar
|
|
|
|
avatarPath={contact.avatarPath}
|
|
|
|
color={contact.color}
|
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
|
|
|
name={contact.name}
|
|
|
|
phoneNumber={contact.phoneNumber}
|
|
|
|
profileName={contact.profileName}
|
|
|
|
title={contact.title}
|
|
|
|
size={52}
|
|
|
|
/>
|
|
|
|
<div className="module-sfn-dialog__contact--wrapper">
|
|
|
|
<div className="module-sfn-dialog__contact--name">
|
|
|
|
{contact.title}
|
|
|
|
{contact.name ? (
|
|
|
|
<span>
|
|
|
|
{' '}
|
|
|
|
<InContactsIcon i18n={i18n} />
|
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
{shouldShowNumber ? (
|
2020-06-26 00:08:58 +00:00
|
|
|
<div className="module-sfn-dialog__contact--number">
|
|
|
|
{contact.phoneNumber}
|
|
|
|
</div>
|
2020-07-24 01:35:32 +00:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
className="module-sfn-dialog__contact--view"
|
|
|
|
onClick={() => {
|
|
|
|
onView(contact);
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
2020-09-12 00:46:52 +00:00
|
|
|
type="button"
|
2020-07-24 01:35:32 +00:00
|
|
|
>
|
|
|
|
{i18n('view')}
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
2020-06-26 00:08:58 +00:00
|
|
|
</ul>
|
|
|
|
<div className="module-sfn-dialog__actions">
|
|
|
|
<button
|
|
|
|
className="module-sfn-dialog__actions--cancel"
|
|
|
|
onClick={onCancel}
|
|
|
|
ref={cancelButtonRef}
|
|
|
|
tabIndex={0}
|
2020-09-12 00:46:52 +00:00
|
|
|
type="button"
|
2020-06-26 00:08:58 +00:00
|
|
|
>
|
|
|
|
{i18n('cancel')}
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
className="module-sfn-dialog__actions--confirm"
|
|
|
|
onClick={onConfirm}
|
|
|
|
tabIndex={0}
|
2020-09-12 00:46:52 +00:00
|
|
|
type="button"
|
2020-06-26 00:08:58 +00:00
|
|
|
>
|
2020-08-26 20:30:10 +00:00
|
|
|
{confirmText || i18n('sendMessageToContact')}
|
2020-06-26 00:08:58 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SafetyNumberChangeDialog = (props: Props): JSX.Element => {
|
|
|
|
const { i18n, onCancel, renderSafetyNumber } = props;
|
|
|
|
const [contact, setViewSafetyNumber] = React.useState<
|
|
|
|
ConversationType | undefined
|
|
|
|
>(undefined);
|
|
|
|
|
|
|
|
const onClose = contact
|
|
|
|
? () => {
|
|
|
|
setViewSafetyNumber(undefined);
|
|
|
|
}
|
|
|
|
: onCancel;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConfirmationModal actions={[]} i18n={i18n} onClose={onClose}>
|
|
|
|
{contact && renderSafetyNumber({ contactID: contact.id, onClose })}
|
|
|
|
{!contact && (
|
|
|
|
<SafetyDialogContents
|
|
|
|
{...props}
|
|
|
|
onView={selectedContact => {
|
|
|
|
setViewSafetyNumber(selectedContact);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</ConfirmationModal>
|
|
|
|
);
|
|
|
|
};
|