From d9bee45147e1c20dcfd08226556f29910fee6e90 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 17 Aug 2022 10:34:54 +0200 Subject: [PATCH] Avoid using `contacts.ResolvePhone` for service notifications chat (#1999) --- src/config.ts | 1 - src/global/actions/api/chats.ts | 30 ++++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/config.ts b/src/config.ts index ec4e282e..a097edc9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -200,7 +200,6 @@ export const COUNTRIES_WITH_12H_TIME_FORMAT = new Set(['AU', 'BD', 'CA', 'CO', ' // MTProto constants export const SERVICE_NOTIFICATIONS_USER_ID = '777000'; -export const SERVICE_NOTIFICATIONS_NUMBER = '42777'; export const REPLIES_USER_ID = '1271266957'; // TODO For Test connection ID must be equal to 708513 export const ALL_FOLDER_ID = 0; export const ARCHIVED_FOLDER_ID = 1; diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index 28ff733e..5e557c13 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -15,7 +15,9 @@ import { CHAT_LIST_LOAD_SLICE, RE_TG_LINK, SERVICE_NOTIFICATIONS_USER_ID, - TMP_CHAT_ID, ALL_FOLDER_ID, DEBUG, SERVICE_NOTIFICATIONS_NUMBER, + TMP_CHAT_ID, + ALL_FOLDER_ID, + DEBUG, } from '../../../config'; import { callApi } from '../../../api/gramjs'; import { @@ -45,6 +47,15 @@ import { selectCurrentLimit } from '../../selectors/limits'; const TOP_CHAT_MESSAGES_PRELOAD_INTERVAL = 100; const INFINITE_LOOP_MARKER = 100; +const SERVICE_NOTIFICATIONS_USER_MOCK: ApiUser = { + id: SERVICE_NOTIFICATIONS_USER_ID, + accessHash: '0', + type: 'userTypeRegular', + isMin: true, + username: '', + phoneNumber: '', +}; + const runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true); const runDebouncedForLoadFullChat = debounce((cb) => cb(), 500, false, true); @@ -1111,16 +1122,23 @@ async function loadChats( if (shouldReplace && listType === 'active') { // Always include service notifications chat if (!chatIds.includes(SERVICE_NOTIFICATIONS_USER_ID)) { - const chat = await callApi('getChatByPhoneNumber', SERVICE_NOTIFICATIONS_NUMBER); + const result2 = await callApi('fetchChat', { + type: 'user', + user: SERVICE_NOTIFICATIONS_USER_MOCK, + }); + global = getGlobal(); - if (chat) { - chatIds.unshift(chat.id); - result.chats.unshift(chat); + + const notificationsChat = result2 && selectChat(global, result2.chatId); + if (notificationsChat) { + chatIds.unshift(notificationsChat.id); + result.chats.unshift(notificationsChat); if (lastLocalServiceMessage) { - chat.lastMessage = lastLocalServiceMessage; + notificationsChat.lastMessage = lastLocalServiceMessage; } } } + const currentChat = selectCurrentChat(global); const visibleChats = currentChat ? [currentChat] : [];