diff --git a/Telegram/SourceFiles/data/data_msg_id.h b/Telegram/SourceFiles/data/data_msg_id.h index b2faef165..93162e182 100644 --- a/Telegram/SourceFiles/data/data_msg_id.h +++ b/Telegram/SourceFiles/data/data_msg_id.h @@ -86,6 +86,7 @@ constexpr auto SpecialMsgIdShift = EndStoryMsgId.bare; constexpr auto ShowAtTheEndMsgId = MsgId(SpecialMsgIdShift + 1); constexpr auto SwitchAtTopMsgId = MsgId(SpecialMsgIdShift + 2); constexpr auto ShowAndStartBotMsgId = MsgId(SpecialMsgIdShift + 4); +constexpr auto ShowAndMaybeStartBotMsgId = MsgId(SpecialMsgIdShift + 5); constexpr auto ShowForChooseMessagesMsgId = MsgId(SpecialMsgIdShift + 6); static_assert(SpecialMsgIdShift + 0xFF < 0); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index a22aa877a..5697949c1 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2181,7 +2181,8 @@ void HistoryWidget::showHistory( const auto wasState = controller()->currentDialogsEntryState(); const auto startBot = (showAtMsgId == ShowAndStartBotMsgId); - if (startBot) { + _showAndMaybeSendStart = (showAtMsgId == ShowAndMaybeStartBotMsgId); + if (startBot || _showAndMaybeSendStart) { showAtMsgId = ShowAtTheEndMsgId; } @@ -2283,8 +2284,8 @@ void HistoryWidget::showHistory( if (const auto user = _peer->asUser()) { if (const auto &info = user->botInfo) { - if (startBot) { - if (wasState.key) { + if (startBot || clearMaybeSendStart()) { + if (startBot && wasState.key) { info->inlineReturnTo = wasState; } sendBotStartCommand(); @@ -2519,8 +2520,9 @@ void HistoryWidget::showHistory( if (const auto user = _peer->asUser()) { if (const auto &info = user->botInfo) { - if (startBot) { - if (wasState.key) { + if (startBot + || (!_history->isEmpty() && clearMaybeSendStart())) { + if (startBot && wasState.key) { info->inlineReturnTo = wasState; } sendBotStartCommand(); @@ -3582,6 +3584,21 @@ void HistoryWidget::historyLoaded() { doneShow(); } +bool HistoryWidget::clearMaybeSendStart() { + if (!_showAndMaybeSendStart) { + return false; + } + _showAndMaybeSendStart = false; + if (const auto user = _history ? _history->peer->asUser() : nullptr) { + if (const auto info = user->botInfo.get()) { + if (!info->startToken.isEmpty()) { + return true; + } + } + } + return false; +} + void HistoryWidget::windowShown() { updateControlsGeometry(); } @@ -3944,6 +3961,11 @@ void HistoryWidget::preloadHistoryIfNeeded() { preloadHistoryByScroll(); checkReplyReturns(); } + if (_history && _history->loadedAtTop() && _history->loadedAtBottom()) { + if (clearMaybeSendStart() && !_history->isDisplayedEmpty()) { + sendBotStartCommand(); + } + } } void HistoryWidget::preloadHistoryByScroll() { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 6c4c9cdbb..e1a8dc53d 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -391,6 +391,7 @@ private: void fileChosen(ChatHelpers::FileChosen &&data); void updateFieldSubmitSettings(); + bool clearMaybeSendStart(); // Checks if we are too close to the top or to the bottom // in the scroll area and preloads history if needed. @@ -726,6 +727,7 @@ private: base::flat_set _topicsRequested; TextWithEntities _showAtMsgHighlightPart; int _showAtMsgHighlightPartOffsetHint = 0; + bool _showAndMaybeSendStart = false; int _firstLoadRequest = 0; // Not real mtpRequestId. int _preloadRequest = 0; // Not real mtpRequestId. diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index cc73eddba..e7b656586 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -690,6 +690,8 @@ void SessionNavigation::showPeerByLinkResolved( ? info.messageId : info.startAutoSubmit ? ShowAndStartBotMsgId + : (bot && !info.startToken.isEmpty()) + ? ShowAndMaybeStartBotMsgId : ShowAtUnreadMsgId; const auto attachBotUsername = info.attachBotUsername; if (bot && bot->botInfo->startToken != info.startToken) {