mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-01 12:00:48 +00:00
Update bot menu attach in realtime.
This commit is contained in:
parent
c73eb5d791
commit
be6ee73a04
@ -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()))) {
|
||||
|
@ -159,6 +159,25 @@ bool UpdateBotCommands(
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ApplyBotMenuButton(
|
||||
not_null<BotInfo*> 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<PeerData*> peer)
|
||||
|
@ -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<UserId, std::vector<BotCommand>> &commands,
|
||||
const MTPVector<MTPBotInfo> &data);
|
||||
bool ApplyBotMenuButton(
|
||||
not_null<BotInfo*> info,
|
||||
const MTPBotMenuButton &button);
|
||||
|
||||
} // namespace Data
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user