[Refactoring] Add typing for openChat

This commit is contained in:
Alexander Zinchuk 2022-03-19 21:19:16 +01:00
parent 4f3c7a1a69
commit a348fda4dd
3 changed files with 23 additions and 5 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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' |