2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Replaced use of raw MTP* bot commands with new transitional classes.

This commit is contained in:
23rd
2022-05-15 00:27:21 +03:00
committed by John Preston
parent 5f8608ed90
commit 13146e9c06
14 changed files with 136 additions and 145 deletions

View File

@@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_config.h"
#include "mtproto/mtproto_dc_options.h"
#include "data/notify/data_notify_settings.h"
#include "data/data_peer_bot_command.h"
#include "data/stickers/data_stickers.h"
#include "data/data_session.h"
#include "data/data_user.h"
@@ -1988,16 +1987,29 @@ void Updates::feedUpdate(const MTPUpdate &update) {
const auto &d = update.c_updateBotCommands();
if (const auto peer = session().data().peerLoaded(peerFromMTP(d.vpeer()))) {
const auto botId = UserId(d.vbot_id().v);
const auto commands = Data::BotCommands{
.userId = UserId(d.vbot_id().v),
.commands = ranges::views::all(
d.vcommands().v
) | ranges::views::transform(
Data::BotCommandFromTL
) | ranges::to_vector,
};
if (const auto user = peer->asUser()) {
if (user->isBot() && user->id == peerFromUser(botId)) {
if (Data::UpdateBotCommands(user->botInfo->commands, &d.vcommands())) {
const auto equal = ranges::equal(
user->botInfo->commands,
commands.commands);
user->botInfo->commands = commands.commands;
if (!equal) {
session().data().botCommandsChanged(user);
}
}
} else if (const auto chat = peer->asChat()) {
chat->setBotCommands(botId, d.vcommands());
chat->setBotCommands({ commands });
} else if (const auto megagroup = peer->asMegagroup()) {
if (megagroup->mgInfo->updateBotCommands(botId, d.vcommands())) {
if (megagroup->mgInfo->setBotCommands({ commands })) {
session().data().botCommandsChanged(megagroup);
}
}