From 92a512a16dbefafd577325d7437097e78294defc Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 6 Dec 2022 09:31:44 -0800 Subject: [PATCH] ConversationView: Move call/mute functions into redux --- ts/components/ToastCannotStartGroupCall.tsx | 20 --- ts/components/ToastManager.tsx | 167 +++++++++--------- .../ConversationHeader.stories.tsx | 2 +- .../conversation/ConversationHeader.tsx | 27 +-- .../ConversationDetails.tsx | 15 +- .../ConversationNotificationsModal.tsx | 9 +- ...versationNotificationsSettings.stories.tsx | 1 + .../ConversationNotificationsSettings.tsx | 12 +- ts/state/ducks/calling.ts | 106 +++++++++++ ts/state/ducks/conversations.ts | 64 +++++-- ts/state/ducks/toast.ts | 11 +- ts/state/smart/ConversationDetails.tsx | 3 - ts/state/smart/ConversationHeader.tsx | 3 - .../ConversationNotificationsSettings.tsx | 13 +- ts/util/isCallSafe.ts | 38 ++++ ts/util/showToast.tsx | 2 - ts/views/conversation_view.tsx | 147 ++------------- 17 files changed, 353 insertions(+), 287 deletions(-) delete mode 100644 ts/components/ToastCannotStartGroupCall.tsx create mode 100644 ts/util/isCallSafe.ts diff --git a/ts/components/ToastCannotStartGroupCall.tsx b/ts/components/ToastCannotStartGroupCall.tsx deleted file mode 100644 index 58996bc15..000000000 --- a/ts/components/ToastCannotStartGroupCall.tsx +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2021 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -import React from 'react'; -import type { LocalizerType } from '../types/Util'; -import { Toast } from './Toast'; - -type PropsType = { - i18n: LocalizerType; - onClose: () => unknown; -}; - -export function ToastCannotStartGroupCall({ - i18n, - onClose, -}: PropsType): JSX.Element { - return ( - {i18n('GroupV2--cannot-start-group-call')} - ); -} diff --git a/ts/components/ToastManager.tsx b/ts/components/ToastManager.tsx index 339ad003e..b9f8abbe2 100644 --- a/ts/components/ToastManager.tsx +++ b/ts/components/ToastManager.tsx @@ -30,72 +30,6 @@ export function ToastManager({ } const { toastType } = toast; - if (toastType === ToastType.Error) { - return ( - window.showDebugLog(), - }} - > - {i18n('Toast--error')} - - ); - } - - if (toastType === ToastType.MessageBodyTooLong) { - return ; - } - - if (toastType === ToastType.StoryReact) { - return ( - - {i18n('Stories__toast--sending-reaction')} - - ); - } - - if (toastType === ToastType.StoryReply) { - return ( - - {i18n('Stories__toast--sending-reply')} - - ); - } - - if (toastType === ToastType.StoryMuted) { - return ( - - {i18n('Stories__toast--hasNoSound')} - - ); - } - - if (toastType === ToastType.StoryVideoTooLong) { - return ( - - {i18n('StoryCreator__error--video-too-long')} - - ); - } - - if (toastType === ToastType.StoryVideoUnsupported) { - return ( - - {i18n('StoryCreator__error--video-unsupported')} - - ); - } - - if (toastType === ToastType.StoryVideoError) { - return ( - - {i18n('StoryCreator__error--video-error')} - - ); - } if (toastType === ToastType.AddingUserToGroup) { return ( @@ -108,21 +42,10 @@ export function ToastManager({ ); } - if (toastType === ToastType.UserAddedToGroup) { + if (toastType === ToastType.CannotStartGroupCall) { return ( - {i18n( - 'AddUserToAnotherGroupModal__toast--user-added-to-group', - toast.parameters - )} - - ); - } - - if (toastType === ToastType.FailedToDeleteUsername) { - return ( - - {i18n('ProfileEditor--username--delete-general-error')} + {i18n('GroupV2--cannot-start-group-call', toast.parameters)} ); } @@ -147,5 +70,91 @@ export function ToastManager({ return {i18n('deleteForEveryoneFailed')}; } + if (toastType === ToastType.Error) { + return ( + window.showDebugLog(), + }} + > + {i18n('Toast--error')} + + ); + } + + if (toastType === ToastType.FailedToDeleteUsername) { + return ( + + {i18n('ProfileEditor--username--delete-general-error')} + + ); + } + + if (toastType === ToastType.MessageBodyTooLong) { + return ; + } + + 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.UserAddedToGroup) { + return ( + + {i18n( + 'AddUserToAnotherGroupModal__toast--user-added-to-group', + toast.parameters + )} + + ); + } + throw missingCaseError(toastType); } diff --git a/ts/components/conversation/ConversationHeader.stories.tsx b/ts/components/conversation/ConversationHeader.stories.tsx index 9b700b225..228520c3a 100644 --- a/ts/components/conversation/ConversationHeader.stories.tsx +++ b/ts/components/conversation/ConversationHeader.stories.tsx @@ -41,7 +41,6 @@ const commonProps = { setDisappearingMessages: action('setDisappearingMessages'), destroyMessages: action('destroyMessages'), onSearchInConversation: action('onSearchInConversation'), - onSetMuteNotifications: action('onSetMuteNotifications'), onOutgoingAudioCallInConversation: action( 'onOutgoingAudioCallInConversation' ), @@ -57,6 +56,7 @@ const commonProps = { onMarkUnread: action('onMarkUnread'), onMoveToInbox: action('onMoveToInbox'), onSetPin: action('onSetPin'), + setMuteExpiration: action('onSetMuteNotifications'), viewUserStories: action('viewUserStories'), }; diff --git a/ts/components/conversation/ConversationHeader.tsx b/ts/components/conversation/ConversationHeader.tsx index 95f6bd092..728118e2e 100644 --- a/ts/components/conversation/ConversationHeader.tsx +++ b/ts/components/conversation/ConversationHeader.tsx @@ -80,11 +80,10 @@ export type PropsDataType = { >; export type PropsActionsType = { - onSetMuteNotifications: (seconds: number) => void; destroyMessages: (conversationId: string) => void; onSearchInConversation: () => void; - onOutgoingAudioCallInConversation: () => void; - onOutgoingVideoCallInConversation: () => void; + onOutgoingAudioCallInConversation: (conversationId: string) => void; + onOutgoingVideoCallInConversation: (conversationId: string) => void; onSetPin: (value: boolean) => void; onShowConversationDetails: () => void; @@ -95,6 +94,7 @@ export type PropsActionsType = { onArchive: () => void; onMarkUnread: () => void; onMoveToInbox: () => void; + setMuteExpiration: (conversationId: string, seconds: number) => void; setDisappearingMessages: ( conversationId: string, seconds: DurationInSeconds @@ -349,12 +349,12 @@ export class ConversationHeader extends React.Component { onArchive, onMarkUnread, onMoveToInbox, - onSetMuteNotifications, onSetPin, onShowAllMedia, onShowConversationDetails, onShowGroupMembers, setDisappearingMessages, + setMuteExpiration, type, } = this.props; @@ -371,7 +371,7 @@ export class ConversationHeader extends React.Component { {isMuted ? ( { - onSetMuteNotifications(0); + setMuteExpiration(id, 0); }} > {i18n('unmute')} @@ -379,7 +379,7 @@ export class ConversationHeader extends React.Component { ) : ( { - onSetMuteNotifications(Number.MAX_SAFE_INTEGER); + setMuteExpiration(id, Number.MAX_SAFE_INTEGER); }} > {i18n('muteAlways')} @@ -465,7 +465,7 @@ export class ConversationHeader extends React.Component { key={item.name} disabled={item.disabled} onClick={() => { - onSetMuteNotifications(item.value); + setMuteExpiration(id, item.value); }} > {item.name} @@ -676,6 +676,7 @@ export class ConversationHeader extends React.Component { announcementsOnly={announcementsOnly} areWeAdmin={areWeAdmin} i18n={i18n} + id={id} isNarrow={isNarrow} onOutgoingAudioCallInConversation={ onOutgoingAudioCallInConversation @@ -702,6 +703,7 @@ function OutgoingCallButtons({ announcementsOnly, areWeAdmin, i18n, + id, isNarrow, onOutgoingAudioCallInConversation, onOutgoingVideoCallInConversation, @@ -712,6 +714,7 @@ function OutgoingCallButtons({ | 'announcementsOnly' | 'areWeAdmin' | 'i18n' + | 'id' | 'onOutgoingAudioCallInConversation' | 'onOutgoingVideoCallInConversation' | 'outgoingCallButtonStyle' @@ -729,14 +732,14 @@ function OutgoingCallButtons({ : undefined )} disabled={showBackButton} - onClick={onOutgoingVideoCallInConversation} + onClick={() => onOutgoingVideoCallInConversation(id)} type="button" /> ); const startCallShortcuts = useStartCallShortcuts( - onOutgoingAudioCallInConversation, - onOutgoingVideoCallInConversation + () => onOutgoingAudioCallInConversation(id), + () => onOutgoingVideoCallInConversation(id) ); useKeyboardShortcuts(startCallShortcuts); @@ -751,7 +754,7 @@ function OutgoingCallButtons({ {videoButton}