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 }) {