signal-desktop/ts/components/ToastManager.tsx

397 lines
9.7 KiB
TypeScript
Raw Normal View History

// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import type { LocalizerType } from '../types/Util';
import { SECOND } from '../util/durations';
import { Toast } from './Toast';
2022-10-18 17:12:02 +00:00
import { missingCaseError } from '../util/missingCaseError';
import type { AnyToast } from '../types/Toast';
import { ToastType } from '../types/Toast';
export type PropsType = {
hideToast: () => unknown;
i18n: LocalizerType;
2022-12-14 18:12:04 +00:00
openFileInFolder: (target: string) => unknown;
2023-01-18 23:31:10 +00:00
OS: string;
onUndoArchive: (conversaetionId: string) => unknown;
toast?: AnyToast;
};
const SHORT_TIMEOUT = 3 * SECOND;
2022-11-18 00:45:19 +00:00
export function ToastManager({
hideToast,
i18n,
2022-12-14 18:12:04 +00:00
openFileInFolder,
onUndoArchive,
2023-01-18 23:31:10 +00:00
OS,
toast,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element | null {
2022-10-18 17:12:02 +00:00
if (toast === undefined) {
return null;
}
const { toastType } = toast;
if (toastType === ToastType.AddingUserToGroup) {
return (
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
2023-03-30 00:03:25 +00:00
{i18n('icu:AddUserToAnotherGroupModal__toast--adding-user-to-group', {
contact: toast.parameters.contact,
})}
</Toast>
);
}
2022-12-22 03:07:45 +00:00
if (toastType === ToastType.AlreadyGroupMember) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:GroupV2--join--already-in-group')}
2022-12-22 03:07:45 +00:00
</Toast>
);
}
if (toastType === ToastType.AlreadyRequestedToJoin) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:GroupV2--join--already-awaiting-approval')}
2022-12-22 03:07:45 +00:00
</Toast>
);
}
2022-12-08 07:43:48 +00:00
if (toastType === ToastType.Blocked) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:unblockToSend')}</Toast>;
2022-12-08 07:43:48 +00:00
}
if (toastType === ToastType.BlockedGroup) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:unblockGroupToSend')}</Toast>;
2022-12-08 07:43:48 +00:00
}
2023-08-09 00:53:06 +00:00
if (toastType === ToastType.CallHistoryCleared) {
return (
<Toast onClose={hideToast}>
{i18n('icu:CallsTab__ToastCallHistoryCleared')}
</Toast>
);
}
if (toastType === ToastType.CannotEditMessage) {
return (
<Toast onClose={hideToast}>
{i18n('icu:ToastManager__CannotEditMessage_24')}
</Toast>
);
}
2023-03-20 22:23:53 +00:00
if (toastType === ToastType.CannotForwardEmptyMessage) {
return (
<Toast onClose={hideToast}>
{i18n('icu:ForwardMessagesModal__toast--CannotForwardEmptyMessage')}
</Toast>
);
}
if (toastType === ToastType.CannotMixMultiAndNonMultiAttachments) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:cannotSelectPhotosAndVideosAlongWithFiles')}
</Toast>
);
}
if (toastType === ToastType.CannotOpenGiftBadgeIncoming) {
return (
<Toast onClose={hideToast}>
2023-01-23 20:42:40 +00:00
{i18n('icu:message--donation--unopened--toast--incoming')}
</Toast>
);
}
if (toastType === ToastType.CannotOpenGiftBadgeOutgoing) {
return (
<Toast onClose={hideToast}>
2023-01-23 20:42:40 +00:00
{i18n('icu:message--donation--unopened--toast--outgoing')}
</Toast>
);
}
if (toastType === ToastType.CannotStartGroupCall) {
return (
<Toast onClose={hideToast}>
{i18n('icu:GroupV2--cannot-start-group-call')}
</Toast>
);
}
if (toastType === ToastType.ConversationArchived) {
return (
<Toast
onClose={hideToast}
toastAction={{
2023-03-30 00:03:25 +00:00
label: i18n('icu:conversationArchivedUndo'),
onClick: () => {
onUndoArchive(String(toast.parameters.conversationId));
},
}}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:conversationArchived')}
</Toast>
);
}
if (toastType === ToastType.ConversationMarkedUnread) {
return (
2023-03-30 00:03:25 +00:00
<Toast onClose={hideToast}>{i18n('icu:conversationMarkedUnread')}</Toast>
);
}
2023-04-05 20:48:00 +00:00
if (toastType === ToastType.ConversationRemoved) {
return (
<Toast onClose={hideToast}>
{i18n('icu:Toast--ConversationRemoved', {
title: toast.parameters.title,
2023-04-05 20:48:00 +00:00
})}
</Toast>
);
}
if (toastType === ToastType.ConversationUnarchived) {
return (
2023-03-30 00:03:25 +00:00
<Toast onClose={hideToast}>
{i18n('icu:conversationReturnedToInbox')}
</Toast>
);
}
if (toastType === ToastType.CopiedUsername) {
return (
<Toast onClose={hideToast} timeout={3 * SECOND}>
2023-03-30 00:03:25 +00:00
{i18n('icu:ProfileEditor--username--copied-username')}
</Toast>
);
}
if (toastType === ToastType.CopiedUsernameLink) {
return (
<Toast onClose={hideToast} timeout={3 * SECOND}>
2023-03-30 00:03:25 +00:00
{i18n('icu:ProfileEditor--username--copied-username-link')}
</Toast>
);
}
if (toastType === ToastType.DangerousFileType) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:dangerousFileType')}</Toast>;
}
if (toastType === ToastType.DeleteForEveryoneFailed) {
2023-03-30 00:03:25 +00:00
return (
<Toast onClose={hideToast}>{i18n('icu:deleteForEveryoneFailed')}</Toast>
);
}
2022-10-18 17:12:02 +00:00
if (toastType === ToastType.Error) {
2022-07-29 00:10:07 +00:00
return (
<Toast
autoDismissDisabled
onClose={hideToast}
toastAction={{
2023-03-30 00:03:25 +00:00
label: i18n('icu:Toast--error--action'),
2023-01-13 00:24:59 +00:00
onClick: () => window.IPC.showDebugLog(),
2022-07-29 00:10:07 +00:00
}}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:Toast--error')}
2022-07-29 00:10:07 +00:00
</Toast>
);
}
2022-12-08 07:43:48 +00:00
if (toastType === ToastType.Expired) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:expiredWarning')}</Toast>;
2022-12-08 07:43:48 +00:00
}
if (toastType === ToastType.FailedToDeleteUsername) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:ProfileEditor--username--delete-general-error')}
</Toast>
);
}
2022-12-14 18:12:04 +00:00
if (toastType === ToastType.FileSaved) {
return (
<Toast
onClose={hideToast}
toastAction={{
2023-03-30 00:03:25 +00:00
label: i18n('icu:attachmentSavedShow'),
2022-12-14 18:12:04 +00:00
onClick: () => {
openFileInFolder(toast.parameters.fullPath);
2022-12-14 18:12:04 +00:00
},
}}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:attachmentSaved')}
2022-12-14 18:12:04 +00:00
</Toast>
);
}
if (toastType === ToastType.FileSize) {
return (
<Toast onClose={hideToast}>
{i18n('icu:fileSizeWarning', {
limit: toast.parameters.limit,
units: toast.parameters.units,
})}
</Toast>
);
}
2022-12-08 07:43:48 +00:00
if (toastType === ToastType.InvalidConversation) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:invalidConversation')}</Toast>;
2022-12-08 07:43:48 +00:00
}
if (toastType === ToastType.LeftGroup) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:youLeftTheGroup')}</Toast>;
2022-12-08 07:43:48 +00:00
}
if (toastType === ToastType.MaxAttachments) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:maximumAttachments')}</Toast>;
}
2022-10-18 17:12:02 +00:00
if (toastType === ToastType.MessageBodyTooLong) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:messageBodyTooLong')}</Toast>;
}
if (toastType === ToastType.OriginalMessageNotFound) {
2023-03-30 00:03:25 +00:00
return (
<Toast onClose={hideToast}>{i18n('icu:originalMessageNotFound')}</Toast>
);
2022-12-06 19:03:09 +00:00
}
2022-12-07 01:00:02 +00:00
if (toastType === ToastType.PinnedConversationsFull) {
2023-03-30 00:03:25 +00:00
return (
<Toast onClose={hideToast}>{i18n('icu:pinnedConversationsFull')}</Toast>
);
2022-12-07 01:00:02 +00:00
}
if (toastType === ToastType.ReactionFailed) {
2023-03-30 00:03:25 +00:00
return <Toast onClose={hideToast}>{i18n('icu:Reactions--error')}</Toast>;
}
if (toastType === ToastType.ReportedSpamAndBlocked) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:MessageRequests--block-and-report-spam-success-toast')}
</Toast>
);
}
if (toastType === ToastType.StoryMuted) {
return (
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
2023-03-30 00:03:25 +00:00
{i18n('icu:Stories__toast--hasNoSound')}
</Toast>
);
}
2022-10-18 17:12:02 +00:00
if (toastType === ToastType.StoryReact) {
return (
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
2023-03-30 00:03:25 +00:00
{i18n('icu:Stories__toast--sending-reaction')}
</Toast>
);
}
2022-10-18 17:12:02 +00:00
if (toastType === ToastType.StoryReply) {
return (
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
2023-03-30 00:03:25 +00:00
{i18n('icu:Stories__toast--sending-reply')}
</Toast>
);
}
if (toastType === ToastType.StoryVideoError) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:StoryCreator__error--video-error')}
</Toast>
);
}
2022-10-18 17:12:02 +00:00
if (toastType === ToastType.StoryVideoUnsupported) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:StoryCreator__error--video-unsupported')}
</Toast>
);
}
if (toastType === ToastType.TapToViewExpiredIncoming) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:Message--tap-to-view--incoming--expired-toast')}
</Toast>
);
}
if (toastType === ToastType.TapToViewExpiredOutgoing) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:Message--tap-to-view--outgoing--expired-toast')}
</Toast>
);
}
if (toastType === ToastType.TooManyMessagesToDeleteForEveryone) {
return (
<Toast onClose={hideToast}>
{i18n(
'icu:DeleteMessagesModal__toast--TooManyMessagesToDeleteForEveryone',
{ count: toast.parameters.count }
)}
</Toast>
);
}
2023-03-20 22:23:53 +00:00
if (toastType === ToastType.TooManyMessagesToForward) {
return (
<Toast onClose={hideToast}>
{i18n('icu:SelectModeActions__toast--TooManyMessagesToForward')}
2023-03-20 22:23:53 +00:00
</Toast>
);
}
if (toastType === ToastType.UnableToLoadAttachment) {
2023-03-30 00:03:25 +00:00
return (
<Toast onClose={hideToast}>{i18n('icu:unableToLoadAttachment')}</Toast>
);
}
if (toastType === ToastType.UnsupportedMultiAttachment) {
return (
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:cannotSelectMultipleFileAttachments')}
</Toast>
);
}
2023-01-18 23:31:10 +00:00
if (toastType === ToastType.UnsupportedOS) {
return (
<Toast onClose={hideToast}>
{i18n('icu:UnsupportedOSErrorToast', { OS })}
</Toast>
);
}
2022-10-18 17:12:02 +00:00
if (toastType === ToastType.UserAddedToGroup) {
return (
2022-09-27 00:09:50 +00:00
<Toast onClose={hideToast}>
2023-03-30 00:03:25 +00:00
{i18n('icu:AddUserToAnotherGroupModal__toast--user-added-to-group', {
contact: toast.parameters.contact,
group: toast.parameters.group,
})}
</Toast>
);
}
2022-10-18 17:12:02 +00:00
throw missingCaseError(toastType);
2022-11-18 00:45:19 +00:00
}