From 5581b2b421468d326d1dbf659e431c7e6dad008e Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 20 Jul 2022 16:02:06 +0200 Subject: [PATCH] Fix replying in discussions (#1954) --- src/api/gramjs/apiBuilders/messages.ts | 2 ++ src/api/gramjs/methods/messages.ts | 3 +++ src/global/actions/api/messages.ts | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 4095741ed..cc9a497d9 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -1147,6 +1147,7 @@ export function buildLocalMessage( text?: string, entities?: ApiMessageEntity[], replyingTo?: number, + replyingToTopId?: number, attachment?: ApiAttachment, sticker?: ApiSticker, gif?: ApiVideo, @@ -1181,6 +1182,7 @@ export function buildLocalMessage( isOutgoing: !isChannel, senderId: sendAs?.id || currentUserId, ...(replyingTo && { replyToMessageId: replyingTo }), + ...(replyingToTopId && { replyToTopMessageId: replyingToTopId }), ...(groupedId && { groupedId, ...(media && (media.photo || media.video) && { isInAlbum: true }), diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index 1f8062725..334e82cc4 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -202,6 +202,7 @@ export function sendMessage( text, entities, replyingTo, + replyingToTopId, attachment, sticker, gif, @@ -218,6 +219,7 @@ export function sendMessage( text?: string; entities?: ApiMessageEntity[]; replyingTo?: number; + replyingToTopId?: number; attachment?: ApiAttachment; sticker?: ApiSticker; gif?: ApiVideo; @@ -237,6 +239,7 @@ export function sendMessage( text, entities, replyingTo, + replyingToTopId, attachment, sticker, gif, diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index 1acd1f6a5..4ef0aa64d 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -912,6 +912,7 @@ async function sendMessage(params: { isSilent?: boolean; scheduledAt?: number; sendAs?: ApiChat | ApiUser; + replyingToTopId?: number; }) { let localId: number | undefined; const progressCallback = params.attachment ? (progress: number, messageLocalId: number) => { @@ -950,6 +951,10 @@ async function sendMessage(params: { params.replyingTo = selectThreadTopMessageId(global, params.chat.id, threadId)!; } + if (params.replyingTo && !params.replyingToTopId && threadId !== MAIN_THREAD_ID) { + params.replyingToTopId = selectThreadTopMessageId(global, params.chat.id, threadId)!; + } + await callApi('sendMessage', params, progressCallback); if (progressCallback && localId) {