mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Send start in bots auto in existing bot chats.
This commit is contained in:
parent
10f1ae152d
commit
3957fea5e4
4 changed files with 32 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<MsgId> _topicsRequested;
|
||||
TextWithEntities _showAtMsgHighlightPart;
|
||||
int _showAtMsgHighlightPartOffsetHint = 0;
|
||||
bool _showAndMaybeSendStart = false;
|
||||
|
||||
int _firstLoadRequest = 0; // Not real mtpRequestId.
|
||||
int _preloadRequest = 0; // Not real mtpRequestId.
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue