2021-05-28 16:15:17 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-23 00:41:45 +00:00
|
|
|
import React from 'react';
|
2021-11-12 01:17:29 +00:00
|
|
|
import type {
|
2023-02-27 22:34:43 +00:00
|
|
|
AuthorizeArtCreatorDataType,
|
2023-03-27 23:48:57 +00:00
|
|
|
ContactModalStateType,
|
2023-04-10 21:38:34 +00:00
|
|
|
DeleteMessagesPropsType,
|
2023-03-27 23:48:57 +00:00
|
|
|
EditHistoryMessagesType,
|
2023-04-14 18:16:28 +00:00
|
|
|
FormattingWarningDataType,
|
2023-03-20 22:23:53 +00:00
|
|
|
ForwardMessagesPropsType,
|
2023-03-27 23:48:57 +00:00
|
|
|
SafetyNumberChangedBlockingDataType,
|
|
|
|
UserNotFoundModalStateType,
|
2021-11-12 01:17:29 +00:00
|
|
|
} from '../state/ducks/globalModals';
|
2022-09-26 16:24:52 +00:00
|
|
|
import type { LocalizerType, ThemeType } from '../types/Util';
|
2023-04-14 18:16:28 +00:00
|
|
|
import type { ExplodePromiseResultType } from '../util/explodePromise';
|
2022-04-05 00:38:22 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
2021-10-23 00:41:45 +00:00
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
import { ButtonVariant } from './Button';
|
|
|
|
import { ConfirmationDialog } from './ConfirmationDialog';
|
2023-04-14 18:16:28 +00:00
|
|
|
import { FormattingWarningModal } from './FormattingWarningModal';
|
2022-07-21 00:07:09 +00:00
|
|
|
import { SignalConnectionsModal } from './SignalConnectionsModal';
|
2021-10-23 00:41:45 +00:00
|
|
|
import { WhatsNewModal } from './WhatsNewModal';
|
2021-09-21 22:37:10 +00:00
|
|
|
|
2022-12-22 22:28:47 +00:00
|
|
|
// NOTE: All types should be required for this component so that the smart
|
|
|
|
// component gives you type errors when adding/removing props.
|
2022-09-26 16:24:52 +00:00
|
|
|
export type PropsType = {
|
2021-10-23 00:41:45 +00:00
|
|
|
i18n: LocalizerType;
|
2022-09-26 16:24:52 +00:00
|
|
|
theme: ThemeType;
|
2022-12-22 03:07:45 +00:00
|
|
|
// AddUserToAnotherGroupModal
|
2022-12-22 22:28:47 +00:00
|
|
|
addUserToAnotherGroupModalContactId: string | undefined;
|
2022-12-22 03:07:45 +00:00
|
|
|
renderAddUserToAnotherGroup: () => JSX.Element;
|
2021-09-21 22:37:10 +00:00
|
|
|
// ContactModal
|
2022-12-22 22:28:47 +00:00
|
|
|
contactModalState: ContactModalStateType | undefined;
|
2021-09-21 22:37:10 +00:00
|
|
|
renderContactModal: () => JSX.Element;
|
2023-03-27 23:48:57 +00:00
|
|
|
// EditHistoryMessagesModal
|
|
|
|
editHistoryMessages: EditHistoryMessagesType | undefined;
|
|
|
|
renderEditHistoryMessagesModal: () => JSX.Element;
|
2022-12-22 03:07:45 +00:00
|
|
|
// ErrorModal
|
2022-12-22 22:28:47 +00:00
|
|
|
errorModalProps: { description?: string; title?: string } | undefined;
|
2022-12-22 03:07:45 +00:00
|
|
|
renderErrorModal: (opts: {
|
|
|
|
description?: string;
|
|
|
|
title?: string;
|
|
|
|
}) => JSX.Element;
|
2023-04-10 21:38:34 +00:00
|
|
|
// DeleteMessageModal
|
|
|
|
deleteMessagesProps: DeleteMessagesPropsType | undefined;
|
|
|
|
renderDeleteMessagesModal: () => JSX.Element;
|
2023-04-14 18:16:28 +00:00
|
|
|
// FormattingWarningModal
|
|
|
|
showFormattingWarningModal: (
|
|
|
|
explodedPromise: ExplodePromiseResultType<boolean> | undefined
|
|
|
|
) => void;
|
|
|
|
formattingWarningData: FormattingWarningDataType | undefined;
|
2022-07-01 00:52:03 +00:00
|
|
|
// ForwardMessageModal
|
2023-03-20 22:23:53 +00:00
|
|
|
forwardMessagesProps: ForwardMessagesPropsType | undefined;
|
|
|
|
renderForwardMessagesModal: () => JSX.Element;
|
2021-07-19 19:26:06 +00:00
|
|
|
// ProfileEditor
|
|
|
|
isProfileEditorVisible: boolean;
|
|
|
|
renderProfileEditor: () => JSX.Element;
|
2021-10-06 20:27:14 +00:00
|
|
|
// SafetyNumberModal
|
2022-12-22 22:28:47 +00:00
|
|
|
safetyNumberModalContactId: string | undefined;
|
2021-10-06 20:27:14 +00:00
|
|
|
renderSafetyNumber: () => JSX.Element;
|
2022-12-22 03:07:45 +00:00
|
|
|
// ShortcutGuideModal
|
|
|
|
isShortcutGuideModalVisible: boolean;
|
|
|
|
renderShortcutGuideModal: () => JSX.Element;
|
2022-07-21 00:07:09 +00:00
|
|
|
// SignalConnectionsModal
|
|
|
|
isSignalConnectionsVisible: boolean;
|
|
|
|
toggleSignalConnectionsModal: () => unknown;
|
2022-12-09 19:01:46 +00:00
|
|
|
// StickerPackPreviewModal
|
2022-12-22 22:28:47 +00:00
|
|
|
stickerPackPreviewId: string | undefined;
|
2022-12-09 19:01:46 +00:00
|
|
|
renderStickerPreviewModal: () => JSX.Element | null;
|
2022-07-21 00:07:09 +00:00
|
|
|
// StoriesSettings
|
|
|
|
isStoriesSettingsVisible: boolean;
|
|
|
|
renderStoriesSettings: () => JSX.Element;
|
2022-08-16 23:59:11 +00:00
|
|
|
// SendAnywayDialog
|
|
|
|
hasSafetyNumberChangeModal: boolean;
|
2022-12-22 22:28:47 +00:00
|
|
|
safetyNumberChangedBlockingData:
|
|
|
|
| SafetyNumberChangedBlockingDataType
|
|
|
|
| undefined;
|
2022-08-16 23:59:11 +00:00
|
|
|
renderSendAnywayDialog: () => JSX.Element;
|
2022-04-05 00:38:22 +00:00
|
|
|
// UserNotFoundModal
|
|
|
|
hideUserNotFoundModal: () => unknown;
|
2022-12-22 22:28:47 +00:00
|
|
|
userNotFoundModalState: UserNotFoundModalStateType | undefined;
|
2021-10-23 00:41:45 +00:00
|
|
|
// WhatsNewModal
|
|
|
|
isWhatsNewVisible: boolean;
|
|
|
|
hideWhatsNewModal: () => unknown;
|
2023-02-27 22:34:43 +00:00
|
|
|
// AuthArtCreatorModal
|
|
|
|
authArtCreatorData?: AuthorizeArtCreatorDataType;
|
|
|
|
isAuthorizingArtCreator?: boolean;
|
|
|
|
cancelAuthorizeArtCreator: () => unknown;
|
|
|
|
confirmAuthorizeArtCreator: () => unknown;
|
2021-05-28 16:15:17 +00:00
|
|
|
};
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function GlobalModalContainer({
|
2021-10-23 00:41:45 +00:00
|
|
|
i18n,
|
2022-12-22 03:07:45 +00:00
|
|
|
// AddUserToAnotherGroupModal
|
|
|
|
addUserToAnotherGroupModalContactId,
|
|
|
|
renderAddUserToAnotherGroup,
|
2021-09-21 22:37:10 +00:00
|
|
|
// ContactModal
|
|
|
|
contactModalState,
|
|
|
|
renderContactModal,
|
2023-03-27 23:48:57 +00:00
|
|
|
// EditHistoryMessages
|
|
|
|
editHistoryMessages,
|
|
|
|
renderEditHistoryMessagesModal,
|
2022-12-22 03:07:45 +00:00
|
|
|
// ErrorModal
|
|
|
|
errorModalProps,
|
|
|
|
renderErrorModal,
|
2023-04-10 21:38:34 +00:00
|
|
|
// DeleteMessageModal
|
|
|
|
deleteMessagesProps,
|
|
|
|
renderDeleteMessagesModal,
|
2023-04-14 18:16:28 +00:00
|
|
|
// FormattingWarningModal
|
|
|
|
showFormattingWarningModal,
|
|
|
|
formattingWarningData,
|
2022-07-01 00:52:03 +00:00
|
|
|
// ForwardMessageModal
|
2023-03-20 22:23:53 +00:00
|
|
|
forwardMessagesProps,
|
|
|
|
renderForwardMessagesModal,
|
2021-07-19 19:26:06 +00:00
|
|
|
// ProfileEditor
|
|
|
|
isProfileEditorVisible,
|
|
|
|
renderProfileEditor,
|
2021-10-06 20:27:14 +00:00
|
|
|
// SafetyNumberModal
|
|
|
|
safetyNumberModalContactId,
|
|
|
|
renderSafetyNumber,
|
2022-12-22 03:07:45 +00:00
|
|
|
// ShortcutGuideModal
|
|
|
|
isShortcutGuideModalVisible,
|
|
|
|
renderShortcutGuideModal,
|
2022-07-21 00:07:09 +00:00
|
|
|
// SignalConnectionsModal
|
|
|
|
isSignalConnectionsVisible,
|
|
|
|
toggleSignalConnectionsModal,
|
2022-12-09 19:01:46 +00:00
|
|
|
// StickerPackPreviewModal
|
|
|
|
stickerPackPreviewId,
|
|
|
|
renderStickerPreviewModal,
|
2022-07-21 00:07:09 +00:00
|
|
|
// StoriesSettings
|
|
|
|
isStoriesSettingsVisible,
|
|
|
|
renderStoriesSettings,
|
2022-08-16 23:59:11 +00:00
|
|
|
// SendAnywayDialog
|
|
|
|
hasSafetyNumberChangeModal,
|
|
|
|
safetyNumberChangedBlockingData,
|
|
|
|
renderSendAnywayDialog,
|
2022-04-05 00:38:22 +00:00
|
|
|
// UserNotFoundModal
|
|
|
|
hideUserNotFoundModal,
|
|
|
|
userNotFoundModalState,
|
2021-10-23 00:41:45 +00:00
|
|
|
// WhatsNewModal
|
|
|
|
hideWhatsNewModal,
|
|
|
|
isWhatsNewVisible,
|
2023-02-27 22:34:43 +00:00
|
|
|
// AuthArtCreatorModal
|
|
|
|
authArtCreatorData,
|
|
|
|
isAuthorizingArtCreator,
|
|
|
|
cancelAuthorizeArtCreator,
|
|
|
|
confirmAuthorizeArtCreator,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element | null {
|
2022-12-22 03:07:45 +00:00
|
|
|
// We want the following dialogs to show in this order:
|
|
|
|
// 1. Errors
|
|
|
|
// 2. Safety Number Changes
|
|
|
|
// 3. The Rest (in no particular order, but they're ordered alphabetically)
|
|
|
|
|
|
|
|
// Errors
|
|
|
|
if (errorModalProps) {
|
|
|
|
return renderErrorModal(errorModalProps);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Safety Number
|
2022-08-16 23:59:11 +00:00
|
|
|
if (hasSafetyNumberChangeModal || safetyNumberChangedBlockingData) {
|
|
|
|
return renderSendAnywayDialog();
|
|
|
|
}
|
|
|
|
|
2022-12-22 03:07:45 +00:00
|
|
|
// The Rest
|
|
|
|
|
|
|
|
if (addUserToAnotherGroupModalContactId) {
|
|
|
|
return renderAddUserToAnotherGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contactModalState) {
|
|
|
|
return renderContactModal();
|
|
|
|
}
|
|
|
|
|
2023-03-27 23:48:57 +00:00
|
|
|
if (editHistoryMessages) {
|
|
|
|
return renderEditHistoryMessagesModal();
|
|
|
|
}
|
|
|
|
|
2023-04-10 21:38:34 +00:00
|
|
|
if (deleteMessagesProps) {
|
|
|
|
return renderDeleteMessagesModal();
|
|
|
|
}
|
|
|
|
|
2023-04-14 18:16:28 +00:00
|
|
|
if (formattingWarningData) {
|
|
|
|
const { resolve } = formattingWarningData.explodedPromise;
|
|
|
|
return (
|
|
|
|
<FormattingWarningModal
|
|
|
|
i18n={i18n}
|
|
|
|
onSendAnyway={() => {
|
|
|
|
showFormattingWarningModal(undefined);
|
|
|
|
resolve(true);
|
|
|
|
}}
|
|
|
|
onCancel={() => {
|
|
|
|
showFormattingWarningModal(undefined);
|
|
|
|
resolve(false);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
if (forwardMessagesProps) {
|
|
|
|
return renderForwardMessagesModal();
|
2022-12-22 03:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isProfileEditorVisible) {
|
|
|
|
return renderProfileEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isShortcutGuideModalVisible) {
|
|
|
|
return renderShortcutGuideModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSignalConnectionsVisible) {
|
|
|
|
return (
|
|
|
|
<SignalConnectionsModal
|
|
|
|
i18n={i18n}
|
|
|
|
onClose={toggleSignalConnectionsModal}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isStoriesSettingsVisible) {
|
|
|
|
return renderStoriesSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isWhatsNewVisible) {
|
|
|
|
return <WhatsNewModal hideWhatsNewModal={hideWhatsNewModal} i18n={i18n} />;
|
|
|
|
}
|
|
|
|
|
2021-10-06 20:27:14 +00:00
|
|
|
if (safetyNumberModalContactId) {
|
|
|
|
return renderSafetyNumber();
|
|
|
|
}
|
|
|
|
|
2022-12-22 03:07:45 +00:00
|
|
|
if (stickerPackPreviewId) {
|
|
|
|
return renderStickerPreviewModal();
|
2022-09-26 16:24:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 00:38:22 +00:00
|
|
|
if (userNotFoundModalState) {
|
|
|
|
let content: string;
|
|
|
|
if (userNotFoundModalState.type === 'phoneNumber') {
|
2023-03-30 00:03:25 +00:00
|
|
|
content = i18n('icu:startConversation--phone-number-not-found', {
|
2022-04-05 00:38:22 +00:00
|
|
|
phoneNumber: userNotFoundModalState.phoneNumber,
|
|
|
|
});
|
|
|
|
} else if (userNotFoundModalState.type === 'username') {
|
2023-03-30 00:03:25 +00:00
|
|
|
content = i18n('icu:startConversation--username-not-found', {
|
2023-02-09 19:18:57 +00:00
|
|
|
atUsername: userNotFoundModalState.username,
|
2022-04-05 00:38:22 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
throw missingCaseError(userNotFoundModalState);
|
|
|
|
}
|
|
|
|
|
2021-11-12 01:17:29 +00:00
|
|
|
return (
|
|
|
|
<ConfirmationDialog
|
2022-09-27 20:24:21 +00:00
|
|
|
dialogName="GlobalModalContainer.userNotFound"
|
2023-03-30 00:03:25 +00:00
|
|
|
cancelText={i18n('icu:ok')}
|
2021-11-12 01:17:29 +00:00
|
|
|
cancelButtonVariant={ButtonVariant.Secondary}
|
|
|
|
i18n={i18n}
|
2022-04-05 00:38:22 +00:00
|
|
|
onClose={hideUserNotFoundModal}
|
2021-11-12 01:17:29 +00:00
|
|
|
>
|
2022-04-05 00:38:22 +00:00
|
|
|
{content}
|
2021-11-12 01:17:29 +00:00
|
|
|
</ConfirmationDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-27 22:34:43 +00:00
|
|
|
if (authArtCreatorData) {
|
|
|
|
return (
|
|
|
|
<ConfirmationDialog
|
|
|
|
dialogName="GlobalModalContainer.authArtCreator"
|
|
|
|
cancelText={i18n('icu:AuthArtCreator--dialog--dismiss')}
|
|
|
|
cancelButtonVariant={ButtonVariant.Secondary}
|
|
|
|
i18n={i18n}
|
|
|
|
isSpinning={isAuthorizingArtCreator}
|
|
|
|
onClose={cancelAuthorizeArtCreator}
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
text: i18n('icu:AuthArtCreator--dialog--confirm'),
|
|
|
|
style: 'affirmative',
|
|
|
|
action: confirmAuthorizeArtCreator,
|
|
|
|
autoClose: false,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
{i18n('icu:AuthArtCreator--dialog--message')}
|
|
|
|
</ConfirmationDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
return null;
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|