diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index cca131d7f..fc8cc0cfe 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -68,7 +68,11 @@ addActionHandler('preloadTopChatMessages', async (global, actions) => { }); addActionHandler('openChat', (global, actions, payload) => { - const { id, threadId } = payload!; + const { id, threadId = MAIN_THREAD_ID } = payload; + if (!id) { + return; + } + const { currentUserId } = global; const chat = selectChat(global, id); diff --git a/src/global/actions/ui/chats.ts b/src/global/actions/ui/chats.ts index 5b0b700b6..da8bfd9c1 100644 --- a/src/global/actions/ui/chats.ts +++ b/src/global/actions/ui/chats.ts @@ -1,5 +1,7 @@ import { addActionHandler, setGlobal } from '../../index'; +import { MAIN_THREAD_ID } from '../../../api/types'; + import { exitMessageSelectMode, replaceThreadParam, updateCurrentMessageList, } from '../../reducers'; @@ -8,8 +10,11 @@ import { closeLocalTextSearch } from './localSearch'; addActionHandler('openChat', (global, actions, payload) => { const { - id, threadId = -1, type = 'thread', shouldReplaceHistory = false, - } = payload!; + id, + threadId = MAIN_THREAD_ID, + type = 'thread', + shouldReplaceHistory = false, + } = payload; const currentMessageList = selectCurrentMessageList(global); @@ -19,7 +24,10 @@ addActionHandler('openChat', (global, actions, payload) => { || currentMessageList.threadId !== threadId || currentMessageList.type !== type )) { - global = replaceThreadParam(global, id, threadId, 'replyStack', []); + if (id) { + global = replaceThreadParam(global, id, threadId, 'replyStack', []); + } + global = exitMessageSelectMode(global); global = closeLocalTextSearch(global); diff --git a/src/global/types.ts b/src/global/types.ts index cd6d2565d..f63253d4f 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -509,6 +509,12 @@ export type GlobalState = { export interface ActionPayloads { apiUpdate: ApiUpdate; + openChat: { + id: string | undefined; + threadId?: number; + type?: MessageListType; + shouldReplaceHistory?: boolean; + }; } export type NonTypedActionNames = ( @@ -525,7 +531,7 @@ export type NonTypedActionNames = ( 'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' | 'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' | // chats - 'preloadTopChatMessages' | 'loadAllChats' | 'openChat' | 'openChatWithInfo' | 'openLinkedChat' | + 'preloadTopChatMessages' | 'loadAllChats' | 'openChatWithInfo' | 'openLinkedChat' | 'openSupportChat' | 'openTipsChat' | 'focusMessageInComments' | 'openChatByPhoneNumber' | 'loadFullChat' | 'loadTopChats' | 'requestChatUpdate' | 'updateChatMutedState' | 'joinChannel' | 'leaveChannel' | 'deleteChannel' | 'toggleChatPinned' | 'toggleChatArchived' | 'toggleChatUnread' |