// 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'; import { missingCaseError } from '../util/missingCaseError'; import type { AnyToast } from '../types/Toast'; import { ToastType } from '../types/Toast'; export type PropsType = { hideToast: () => unknown; i18n: LocalizerType; openFileInFolder: (target: string) => unknown; OS: string; onUndoArchive: (conversaetionId: string) => unknown; toast?: AnyToast; }; const SHORT_TIMEOUT = 3 * SECOND; export function ToastManager({ hideToast, i18n, openFileInFolder, onUndoArchive, OS, toast, }: PropsType): JSX.Element | null { if (toast === undefined) { return null; } const { toastType } = toast; if (toastType === ToastType.AddingUserToGroup) { return ( {i18n('icu:AddUserToAnotherGroupModal__toast--adding-user-to-group', { contact: toast.parameters.contact, })} ); } if (toastType === ToastType.AlreadyGroupMember) { return ( {i18n('icu:GroupV2--join--already-in-group')} ); } if (toastType === ToastType.AlreadyRequestedToJoin) { return ( {i18n('icu:GroupV2--join--already-awaiting-approval')} ); } if (toastType === ToastType.Blocked) { return {i18n('icu:unblockToSend')}; } if (toastType === ToastType.BlockedGroup) { return {i18n('icu:unblockGroupToSend')}; } if (toastType === ToastType.CannotEditMessage) { return ( {i18n('icu:ToastManager__CannotEditMessage')} ); } if (toastType === ToastType.CannotForwardEmptyMessage) { return ( {i18n('icu:ForwardMessagesModal__toast--CannotForwardEmptyMessage')} ); } if (toastType === ToastType.CannotMixMultiAndNonMultiAttachments) { return ( {i18n('icu:cannotSelectPhotosAndVideosAlongWithFiles')} ); } if (toastType === ToastType.CannotOpenGiftBadgeIncoming) { return ( {i18n('icu:message--donation--unopened--toast--incoming')} ); } if (toastType === ToastType.CannotOpenGiftBadgeOutgoing) { return ( {i18n('icu:message--donation--unopened--toast--outgoing')} ); } if (toastType === ToastType.CannotStartGroupCall) { return ( {i18n('icu:GroupV2--cannot-start-group-call')} ); } if (toastType === ToastType.ConversationArchived) { return ( { onUndoArchive(String(toast.parameters.conversationId)); }, }} > {i18n('icu:conversationArchived')} ); } if (toastType === ToastType.ConversationMarkedUnread) { return ( {i18n('icu:conversationMarkedUnread')} ); } if (toastType === ToastType.ConversationRemoved) { return ( {i18n('icu:Toast--ConversationRemoved', { title: toast.parameters.title, })} ); } if (toastType === ToastType.ConversationUnarchived) { return ( {i18n('icu:conversationReturnedToInbox')} ); } if (toastType === ToastType.CopiedUsername) { return ( {i18n('icu:ProfileEditor--username--copied-username')} ); } if (toastType === ToastType.CopiedUsernameLink) { return ( {i18n('icu:ProfileEditor--username--copied-username-link')} ); } if (toastType === ToastType.DangerousFileType) { return {i18n('icu:dangerousFileType')}; } if (toastType === ToastType.DeleteForEveryoneFailed) { return ( {i18n('icu:deleteForEveryoneFailed')} ); } if (toastType === ToastType.Error) { return ( window.IPC.showDebugLog(), }} > {i18n('icu:Toast--error')} ); } if (toastType === ToastType.Expired) { return {i18n('icu:expiredWarning')}; } if (toastType === ToastType.FailedToDeleteUsername) { return ( {i18n('icu:ProfileEditor--username--delete-general-error')} ); } if (toastType === ToastType.FileSaved) { return ( { openFileInFolder(toast.parameters.fullPath); }, }} > {i18n('icu:attachmentSaved')} ); } if (toastType === ToastType.FileSize) { return ( {i18n('icu:fileSizeWarning', { limit: toast.parameters.limit, units: toast.parameters.units, })} ); } if (toastType === ToastType.InvalidConversation) { return {i18n('icu:invalidConversation')}; } if (toastType === ToastType.LeftGroup) { return {i18n('icu:youLeftTheGroup')}; } if (toastType === ToastType.MaxAttachments) { return {i18n('icu:maximumAttachments')}; } if (toastType === ToastType.MessageBodyTooLong) { return {i18n('icu:messageBodyTooLong')}; } if (toastType === ToastType.OriginalMessageNotFound) { return ( {i18n('icu:originalMessageNotFound')} ); } if (toastType === ToastType.PinnedConversationsFull) { return ( {i18n('icu:pinnedConversationsFull')} ); } if (toastType === ToastType.ReactionFailed) { return {i18n('icu:Reactions--error')}; } if (toastType === ToastType.ReportedSpamAndBlocked) { return ( {i18n('icu:MessageRequests--block-and-report-spam-success-toast')} ); } if (toastType === ToastType.StoryMuted) { return ( {i18n('icu:Stories__toast--hasNoSound')} ); } if (toastType === ToastType.StoryReact) { return ( {i18n('icu:Stories__toast--sending-reaction')} ); } if (toastType === ToastType.StoryReply) { return ( {i18n('icu:Stories__toast--sending-reply')} ); } if (toastType === ToastType.StoryVideoError) { return ( {i18n('icu:StoryCreator__error--video-error')} ); } if (toastType === ToastType.StoryVideoUnsupported) { return ( {i18n('icu:StoryCreator__error--video-unsupported')} ); } if (toastType === ToastType.TapToViewExpiredIncoming) { return ( {i18n('icu:Message--tap-to-view--incoming--expired-toast')} ); } if (toastType === ToastType.TapToViewExpiredOutgoing) { return ( {i18n('icu:Message--tap-to-view--outgoing--expired-toast')} ); } if (toastType === ToastType.TooManyMessagesToDeleteForEveryone) { return ( {i18n( 'icu:DeleteMessagesModal__toast--TooManyMessagesToDeleteForEveryone', { count: toast.parameters.count } )} ); } if (toastType === ToastType.TooManyMessagesToForward) { return ( {i18n('icu:SelectModeActions__toast--TooManyMessagesToForward')} ); } if (toastType === ToastType.UnableToLoadAttachment) { return ( {i18n('icu:unableToLoadAttachment')} ); } if (toastType === ToastType.UnsupportedMultiAttachment) { return ( {i18n('icu:cannotSelectMultipleFileAttachments')} ); } if (toastType === ToastType.UnsupportedOS) { return ( {i18n('icu:UnsupportedOSErrorToast', { OS })} ); } if (toastType === ToastType.UserAddedToGroup) { return ( {i18n('icu:AddUserToAnotherGroupModal__toast--user-added-to-group', { contact: toast.parameters.contact, group: toast.parameters.group, })} ); } throw missingCaseError(toastType); }