From a11ef0f618759d6d74fa7913b4fec3f1f05a62fc Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 15 Apr 2023 13:51:19 +0200 Subject: [PATCH] Fix pinned action message not appearing (#2982) --- src/api/gramjs/methods/messages.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index ca9e458e0..eaf787623 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -71,6 +71,7 @@ import { requestChatUpdate } from './chats'; import { getEmojiOnlyCountForMessage } from '../../../global/helpers/getEmojiOnlyCountForMessage'; import { getServerTimeOffset } from '../../../util/serverTime'; import { getApiChatIdFromMtpPeer } from '../apiBuilders/peers'; +import { updater } from '../updater'; const FAST_SEND_TIMEOUT = 1000; const INPUT_WAVEFORM_LENGTH = 63; @@ -665,13 +666,22 @@ async function uploadMedia(localMessage: ApiMessage, attachment: ApiAttachment, export async function pinMessage({ chat, messageId, isUnpin, isOneSide, isSilent, }: { chat: ApiChat; messageId: number; isUnpin: boolean; isOneSide?: boolean; isSilent?: boolean }) { - await invokeRequest(new GramJs.messages.UpdatePinnedMessage({ + const result = await invokeRequest(new GramJs.messages.UpdatePinnedMessage({ peer: buildInputPeer(chat.id, chat.accessHash), id: messageId, ...(isUnpin && { unpin: true }), ...(isOneSide && { pmOneside: true }), ...(isSilent && { silent: true }), - }), true); + }), undefined, undefined, true); + + if (!(result instanceof GramJs.Updates)) return; + + // For some reason, Telegram returns UpdateMessageID when pinning a message with a randomId that is unknown to us, + // which causes an 'updateMessage' update instead of 'newMessage'. We ignore this update. + result.updates.forEach((update) => { + if (update instanceof GramJs.UpdateMessageID) return; + updater(update); + }); } export async function unpinAllMessages({ chat, threadId }: { chat: ApiChat; threadId?: number }) {