From 53ec3098b85bf810b9a22e5acd2ada4d5f75e38d Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 27 Aug 2021 21:05:52 +0300 Subject: [PATCH] Message List: Focus bot message when updated inline keyboard --- src/modules/actions/apiUpdaters/messages.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/modules/actions/apiUpdaters/messages.ts b/src/modules/actions/apiUpdaters/messages.ts index 1c92d5ef..8566021e 100644 --- a/src/modules/actions/apiUpdaters/messages.ts +++ b/src/modules/actions/apiUpdaters/messages.ts @@ -37,6 +37,7 @@ import { selectViewportIds, selectFirstUnreadId, selectChat, + selectIsChatWithBot, } from '../../selectors'; import { getMessageContent, isChatPrivate, isMessageLocal } from '../../helpers'; @@ -136,6 +137,20 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => { setGlobal(global); + // Scroll down if bot message height is changed with an updated inline keyboard. + // A drawback: this will scroll down even if the previous scroll was not at bottom. + const chat = selectChat(global, chatId); + if ( + chat + && !message.isOutgoing + && chat.lastMessage?.id === message.id + && selectIsChatWithBot(global, chat) + && isMessageInCurrentMessageList(global, chatId, message as ApiMessage) + && selectIsViewportNewest(global, chatId, message.threadInfo?.threadId || MAIN_THREAD_ID) + ) { + actions.focusLastMessage(); + } + break; }