From 923c3ee12e57f8e6ff90547c7d158310c4af374d Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 20 Sep 2022 14:59:12 +0200 Subject: [PATCH] Composer: Fix error when opening chat with read-only restriction (again) (#2044) --- src/api/gramjs/methods/messages.ts | 17 +++++++++++------ src/global/actions/api/messages.ts | 8 +++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index 4f8be32d..01bfccdd 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -734,12 +734,17 @@ export async function sendMessageAction({ return undefined; } - const result = await invokeRequest(new GramJs.messages.SetTyping({ - peer: buildInputPeer(peer.id, peer.accessHash), - topMsgId: threadId, - action: gramAction, - })); - return result; + try { + const result = await invokeRequest(new GramJs.messages.SetTyping({ + peer: buildInputPeer(peer.id, peer.accessHash), + topMsgId: threadId, + action: gramAction, + }), undefined, true); + return result; + } catch (error) { + // Prevent error from being displayed in UI + } + return undefined; } export async function markMessageListRead({ diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index d1f39028..03808f2a 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -75,7 +75,9 @@ import { import { debounce, onTickEnd, rafPromise, } from '../../../util/schedulers'; -import { getMessageOriginalId, getUserFullName, isServiceNotificationMessage } from '../../helpers'; +import { + getMessageOriginalId, getUserFullName, isDeletedUser, isServiceNotificationMessage, isUserBot, +} from '../../helpers'; import { getTranslation } from '../../../util/langProvider'; import { ensureProtocol } from '../../../util/ensureProtocol'; @@ -332,6 +334,8 @@ addActionHandler('saveDraft', (global, actions, payload) => { const { text, entities } = draft; const chat = selectChat(global, chatId)!; + const user = selectUser(global, chatId)!; + if (user && isDeletedUser(user)) return undefined; if (threadId === MAIN_THREAD_ID) { void callApi('saveDraft', { @@ -484,6 +488,8 @@ addActionHandler('sendMessageAction', async (global, actions, payload) => { const chat = selectChat(global, chatId)!; if (!chat) return; + const user = selectUser(global, chatId); + if (user && (isUserBot(user) || isDeletedUser(user))) return; await callApi('sendMessageAction', { peer: chat, threadId, action,