From 7d37de7c6eae07ca29e067d2fb3488d259469bd7 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 6 Dec 2022 13:29:45 +0100 Subject: [PATCH] Fix own messages sometimes displayed as incoming (#2180) --- src/api/gramjs/updater.ts | 9 ++++++--- src/global/actions/apiUpdaters/messages.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/gramjs/updater.ts b/src/api/gramjs/updater.ts index ad81c2ba2..57c34a462 100644 --- a/src/api/gramjs/updater.ts +++ b/src/api/gramjs/updater.ts @@ -4,7 +4,7 @@ import type { ApiMessage, ApiMessageExtendedMediaPreview, ApiUpdateConnectionStateType, OnApiUpdate, } from '../types'; -import { pick } from '../../util/iteratees'; +import { omit, pick } from '../../util/iteratees'; import { buildApiMessage, buildApiMessageFromShort, @@ -298,7 +298,8 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) { addMessageToLocalDb(update.message); } - const message = buildApiMessage(update.message)!; + // Workaround for a weird server behavior when own message is marked as incoming + const message = omit(buildApiMessage(update.message)!, ['isOutgoing']); onUpdate({ '@type': 'updateMessage', @@ -700,7 +701,9 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) { if (originRequest instanceof GramJs.messages.ToggleNoForwards) { shouldIgnoreNextChannelUpdate = true; - setTimeout(() => { shouldIgnoreNextChannelUpdate = false; }, IGNORE_NEXT_CHANNEL_UPDATE_TIMEOUT); + setTimeout(() => { + shouldIgnoreNextChannelUpdate = false; + }, IGNORE_NEXT_CHANNEL_UPDATE_TIMEOUT); } const chat = buildApiChatFromPreview(channel); diff --git a/src/global/actions/apiUpdaters/messages.ts b/src/global/actions/apiUpdaters/messages.ts index 74c0b97b0..56b1d073e 100644 --- a/src/global/actions/apiUpdaters/messages.ts +++ b/src/global/actions/apiUpdaters/messages.ts @@ -164,7 +164,6 @@ addActionHandler('apiUpdate', (global, actions, update) => { const { chatId, id, message } = update; const currentMessage = selectChatMessage(global, chatId, id); - const chat = selectChat(global, chatId); global = updateWithLocalMedia(global, chatId, id, message); @@ -178,6 +177,7 @@ addActionHandler('apiUpdate', (global, actions, update) => { message.threadInfo, ); } + if (currentMessage) { global = updateChatLastMessage(global, chatId, newMessage); }