// Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import type { LocalizerType, ReplacementValuesType } from '../types/Util'; import { SECOND } from '../util/durations'; import { Toast } from './Toast'; import { missingCaseError } from '../util/missingCaseError'; import { ToastType } from '../types/Toast'; export type PropsType = { hideToast: () => unknown; i18n: LocalizerType; openFileInFolder: (target: string) => unknown; OS: string; onUndoArchive: (conversaetionId: string) => unknown; toast?: { toastType: ToastType; parameters?: ReplacementValuesType; }; }; 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( 'AddUserToAnotherGroupModal__toast--adding-user-to-group', toast.parameters )} ); } if (toastType === ToastType.AlreadyGroupMember) { return ( {i18n('GroupV2--join--already-in-group')} ); } if (toastType === ToastType.AlreadyRequestedToJoin) { return ( {i18n('GroupV2--join--already-awaiting-approval')} ); } if (toastType === ToastType.Blocked) { return {i18n('unblockToSend')}; } if (toastType === ToastType.BlockedGroup) { return {i18n('unblockGroupToSend')}; } if (toastType === ToastType.CannotMixMultiAndNonMultiAttachments) { return ( {i18n('cannotSelectPhotosAndVideosAlongWithFiles')} ); } if (toastType === ToastType.CannotOpenGiftBadgeIncoming) { return ( {i18n('message--giftBadge--unopened--toast--incoming')} ); } if (toastType === ToastType.CannotOpenGiftBadgeOutgoing) { return ( {i18n('message--giftBadge--unopened--toast--outgoing')} ); } if (toastType === ToastType.CannotStartGroupCall) { return ( {i18n('GroupV2--cannot-start-group-call', toast.parameters)} ); } if (toastType === ToastType.ConversationArchived) { return ( { if (toast.parameters && 'conversationId' in toast.parameters) { onUndoArchive(String(toast.parameters.conversationId)); } }, }} > {i18n('conversationArchived')} ); } if (toastType === ToastType.ConversationMarkedUnread) { return ( {i18n('conversationMarkedUnread')} ); } if (toastType === ToastType.ConversationUnarchived) { return ( {i18n('conversationReturnedToInbox')} ); } if (toastType === ToastType.CopiedUsername) { return ( {i18n('ProfileEditor--username--copied-username')} ); } if (toastType === ToastType.CopiedUsernameLink) { return ( {i18n('ProfileEditor--username--copied-username-link')} ); } if (toastType === ToastType.DangerousFileType) { return {i18n('dangerousFileType')}; } if (toastType === ToastType.DeleteForEveryoneFailed) { return {i18n('deleteForEveryoneFailed')}; } if (toastType === ToastType.Error) { return ( window.IPC.showDebugLog(), }} > {i18n('Toast--error')} ); } if (toastType === ToastType.Expired) { return {i18n('expiredWarning')}; } if (toastType === ToastType.FailedToDeleteUsername) { return ( {i18n('ProfileEditor--username--delete-general-error')} ); } if (toastType === ToastType.FileSaved) { return ( { if (toast.parameters && 'fullPath' in toast.parameters) { openFileInFolder(String(toast.parameters.fullPath)); } }, }} > {i18n('attachmentSaved')} ); } if (toastType === ToastType.FileSize) { return ( {i18n('icu:fileSizeWarning', toast?.parameters)} ); } if (toastType === ToastType.InvalidConversation) { return {i18n('invalidConversation')}; } if (toastType === ToastType.LeftGroup) { return {i18n('youLeftTheGroup')}; } if (toastType === ToastType.MaxAttachments) { return {i18n('maximumAttachments')}; } if (toastType === ToastType.MessageBodyTooLong) { return {i18n('messageBodyTooLong')}; } if (toastType === ToastType.OriginalMessageNotFound) { return {i18n('originalMessageNotFound')}; } if (toastType === ToastType.PinnedConversationsFull) { return {i18n('pinnedConversationsFull')}; } if (toastType === ToastType.ReactionFailed) { return {i18n('Reactions--error')}; } if (toastType === ToastType.ReportedSpamAndBlocked) { return ( {i18n('MessageRequests--block-and-report-spam-success-toast')} ); } if (toastType === ToastType.StoryMuted) { return ( {i18n('Stories__toast--hasNoSound')} ); } if (toastType === ToastType.StoryReact) { return ( {i18n('Stories__toast--sending-reaction')} ); } if (toastType === ToastType.StoryReply) { return ( {i18n('Stories__toast--sending-reply')} ); } if (toastType === ToastType.StoryVideoError) { return ( {i18n('StoryCreator__error--video-error')} ); } if (toastType === ToastType.StoryVideoTooLong) { return ( {i18n('StoryCreator__error--video-too-long')} ); } if (toastType === ToastType.StoryVideoUnsupported) { return ( {i18n('StoryCreator__error--video-unsupported')} ); } if (toastType === ToastType.TapToViewExpiredIncoming) { return ( {i18n('Message--tap-to-view--incoming--expired-toast')} ); } if (toastType === ToastType.TapToViewExpiredOutgoing) { return ( {i18n('Message--tap-to-view--outgoing--expired-toast')} ); } if (toastType === ToastType.UnableToLoadAttachment) { return {i18n('unableToLoadAttachment')}; } if (toastType === ToastType.UnsupportedMultiAttachment) { return ( {i18n('cannotSelectMultipleFileAttachments')} ); } if (toastType === ToastType.UnsupportedOS) { return ( {i18n('icu:UnsupportedOSErrorToast', { OS })} ); } if (toastType === ToastType.UserAddedToGroup) { return ( {i18n( 'AddUserToAnotherGroupModal__toast--user-added-to-group', toast.parameters )} ); } throw missingCaseError(toastType); }