diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index baae3ac46..361dc89ef 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -2010,6 +2010,17 @@ void Updates::feedUpdate(const MTPUpdate &update) { session().data().webViewResultSent({ .queryId = d.vquery_id().v }); } break; + case mtpc_updateBotMenuButton: { + const auto &d = update.c_updateBotMenuButton(); + if (const auto bot = session().data().userLoaded(d.vbot_id())) { + if (const auto info = bot->botInfo.get(); info && info->inited) { + if (Data::ApplyBotMenuButton(info, d.vbutton())) { + session().data().botCommandsChanged(bot); + } + } + } + } break; + case mtpc_updatePendingJoinRequests: { const auto &d = update.c_updatePendingJoinRequests(); if (const auto peer = session().data().peerLoaded(peerFromMTP(d.vpeer()))) { diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index ba42dc7fc..ce9bd3e35 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -159,6 +159,25 @@ bool UpdateBotCommands( return result; } +bool ApplyBotMenuButton( + not_null info, + const MTPBotMenuButton &button) { + auto text = QString(); + auto url = QString(); + button.match([&](const MTPDbotMenuButton &data) { + text = qs(data.vtext()); + url = qs(data.vurl()); + }, [&](const auto &) { + }); + const auto changed = (info->botMenuButtonText != text) + || (info->botMenuButtonUrl != url); + + info->botMenuButtonText = text; + info->botMenuButtonUrl = url; + + return changed; +} + } // namespace Data PeerClickHandler::PeerClickHandler(not_null peer) diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index c393f829a..02d186834 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/notify/data_peer_notify_settings.h" #include "data/data_cloud_file.h" +struct BotInfo; class PeerData; class UserData; class ChatData; @@ -109,6 +110,9 @@ bool UpdateBotCommands( bool UpdateBotCommands( base::flat_map> &commands, const MTPVector &data); +bool ApplyBotMenuButton( + not_null info, + const MTPBotMenuButton &button); } // namespace Data diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp index 43e3d63ab..86afabe94 100644 --- a/Telegram/SourceFiles/data/data_user.cpp +++ b/Telegram/SourceFiles/data/data_user.cpp @@ -133,20 +133,9 @@ void UserData::setBotInfo(const MTPBotInfo &info) { const auto changedCommands = Data::UpdateBotCommands( botInfo->commands, d.vcommands()); - auto text = QString(); - auto url = QString(); - d.vmenu_button().match([&](const MTPDbotMenuButton &data) { - text = qs(data.vtext()); - url = qs(data.vurl()); - }, [&](const auto &) { - }); - const auto changedButton = (botInfo->botMenuButtonText != text) - || (botInfo->botMenuButtonUrl != url); - if (changedButton) { - botInfo->botMenuButtonText = text; - botInfo->botMenuButtonUrl = url; - } - + const auto changedButton = Data::ApplyBotMenuButton( + botInfo.get(), + d.vmenu_button()); botInfo->inited = true; if (changedCommands || changedButton) {