2020-10-30 15:34:04 -05:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-11-01 23:55:30 +01:00
|
|
|
import React from 'react';
|
2023-07-13 21:06:42 +02:00
|
|
|
|
2021-10-06 16:27:14 -04:00
|
|
|
import { Button, ButtonVariant } from './Button';
|
2023-07-13 21:06:42 +02:00
|
|
|
import { QrCode } from './QrCode';
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { ConversationType } from '../state/ducks/conversations';
|
2020-07-23 18:35:32 -07:00
|
|
|
import { Intl } from './Intl';
|
2023-07-13 21:06:42 +02:00
|
|
|
import { Emojify } from './conversation/Emojify';
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { LocalizerType } from '../types/Util';
|
2023-07-13 21:06:42 +02:00
|
|
|
import type { SafetyNumberType } from '../types/safetyNumber';
|
2023-11-01 23:55:30 +01:00
|
|
|
import { SAFETY_NUMBER_URL } from '../types/support';
|
2020-06-25 20:08:58 -04:00
|
|
|
|
2020-10-06 17:49:22 -07:00
|
|
|
export type PropsType = {
|
2022-03-02 13:24:28 -05:00
|
|
|
contact: ConversationType;
|
2020-06-25 20:08:58 -04:00
|
|
|
generateSafetyNumber: (contact: ConversationType) => void;
|
|
|
|
i18n: LocalizerType;
|
2022-03-02 13:24:28 -05:00
|
|
|
onClose: () => void;
|
2024-03-14 12:35:03 -07:00
|
|
|
safetyNumber: SafetyNumberType | null;
|
2020-06-25 20:08:58 -04:00
|
|
|
toggleVerified: (contact: ConversationType) => void;
|
2024-03-14 12:35:03 -07:00
|
|
|
verificationDisabled: boolean | null;
|
2020-06-25 20:08:58 -04:00
|
|
|
};
|
|
|
|
|
2022-11-17 16:45:19 -08:00
|
|
|
export function SafetyNumberViewer({
|
2020-06-25 20:08:58 -04:00
|
|
|
contact,
|
|
|
|
generateSafetyNumber,
|
|
|
|
i18n,
|
|
|
|
onClose,
|
2023-11-01 23:55:30 +01:00
|
|
|
safetyNumber,
|
2020-06-25 20:08:58 -04:00
|
|
|
toggleVerified,
|
|
|
|
verificationDisabled,
|
2022-11-17 16:45:19 -08:00
|
|
|
}: PropsType): JSX.Element | null {
|
2020-09-11 17:46:52 -07:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (!contact) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
generateSafetyNumber(contact);
|
2023-07-13 21:06:42 +02:00
|
|
|
}, [contact, generateSafetyNumber]);
|
|
|
|
|
2023-09-19 19:08:36 +02:00
|
|
|
// Keyboard navigation
|
|
|
|
|
2023-11-01 23:55:30 +01:00
|
|
|
if (!contact) {
|
2020-06-25 20:08:58 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-11-01 23:55:30 +01:00
|
|
|
if (!safetyNumber) {
|
2020-10-06 17:49:22 -07:00
|
|
|
return (
|
2021-04-27 12:29:59 -07:00
|
|
|
<div className="module-SafetyNumberViewer">
|
2023-03-29 17:03:25 -07:00
|
|
|
<div>{i18n('icu:cannotGenerateSafetyNumber')}</div>
|
2022-03-02 13:24:28 -05:00
|
|
|
<div className="module-SafetyNumberViewer__buttons">
|
|
|
|
<Button
|
|
|
|
className="module-SafetyNumberViewer__button"
|
|
|
|
onClick={() => onClose?.()}
|
|
|
|
variant={ButtonVariant.Primary}
|
|
|
|
>
|
2023-03-29 17:03:25 -07:00
|
|
|
{i18n('icu:ok')}
|
2022-03-02 13:24:28 -05:00
|
|
|
</Button>
|
|
|
|
</div>
|
2020-10-06 17:49:22 -07:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-29 16:20:05 -07:00
|
|
|
const boldName = (
|
2023-07-13 21:06:42 +02:00
|
|
|
<span className="module-SafetyNumberViewer__bold-name">
|
|
|
|
<Emojify text={contact.title} />
|
|
|
|
</span>
|
2020-07-23 18:35:32 -07:00
|
|
|
);
|
|
|
|
|
2020-09-11 17:46:52 -07:00
|
|
|
const { isVerified } = contact;
|
2023-02-03 18:32:17 -08:00
|
|
|
const verifyButtonText = isVerified
|
|
|
|
? i18n('icu:SafetyNumberViewer__clearVerification')
|
|
|
|
: i18n('icu:SafetyNumberViewer__markAsVerified');
|
2020-06-25 20:08:58 -04:00
|
|
|
|
2023-11-01 23:55:30 +01:00
|
|
|
const numberBlocks = safetyNumber.numberBlocks.join(' ');
|
2023-07-13 21:06:42 +02:00
|
|
|
|
|
|
|
const safetyNumberCard = (
|
|
|
|
<div className="module-SafetyNumberViewer__card-container">
|
2023-11-01 23:55:30 +01:00
|
|
|
<div className="module-SafetyNumberViewer__card">
|
2023-07-13 21:06:42 +02:00
|
|
|
<QrCode
|
|
|
|
className="module-SafetyNumberViewer__card__qr"
|
2023-11-01 23:55:30 +01:00
|
|
|
data={safetyNumber.qrData}
|
2023-07-13 21:06:42 +02:00
|
|
|
alt={i18n('icu:Install__scan-this-code')}
|
|
|
|
/>
|
|
|
|
<div className="module-SafetyNumberViewer__card__number">
|
|
|
|
{numberBlocks}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-06-25 20:08:58 -04:00
|
|
|
return (
|
2021-04-27 12:29:59 -07:00
|
|
|
<div className="module-SafetyNumberViewer">
|
2023-07-13 21:06:42 +02:00
|
|
|
{safetyNumberCard}
|
|
|
|
|
|
|
|
<div className="module-SafetyNumberViewer__help">
|
2023-11-01 21:35:55 +01:00
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
2023-11-01 23:55:30 +01:00
|
|
|
id="icu:SafetyNumberViewer__hint"
|
2023-11-01 21:35:55 +01:00
|
|
|
components={{ name: boldName }}
|
|
|
|
/>
|
2023-07-13 21:06:42 +02:00
|
|
|
<br />
|
2023-11-01 23:55:30 +01:00
|
|
|
<a href={SAFETY_NUMBER_URL} rel="noreferrer" target="_blank">
|
|
|
|
<Intl i18n={i18n} id="icu:SafetyNumberViewer__learn_more" />
|
2023-07-13 21:06:42 +02:00
|
|
|
</a>
|
2020-06-25 20:08:58 -04:00
|
|
|
</div>
|
2023-07-13 21:06:42 +02:00
|
|
|
|
2021-10-06 16:27:14 -04:00
|
|
|
<div className="module-SafetyNumberViewer__button">
|
|
|
|
<Button
|
2024-03-14 12:35:03 -07:00
|
|
|
disabled={verificationDisabled ?? false}
|
2020-06-25 20:08:58 -04:00
|
|
|
onClick={() => {
|
|
|
|
toggleVerified(contact);
|
|
|
|
}}
|
2021-10-06 16:27:14 -04:00
|
|
|
variant={ButtonVariant.Secondary}
|
2020-06-25 20:08:58 -04:00
|
|
|
>
|
|
|
|
{verifyButtonText}
|
2021-10-06 16:27:14 -04:00
|
|
|
</Button>
|
2020-06-25 20:08:58 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2022-11-17 16:45:19 -08:00
|
|
|
}
|