mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Handle updateBotCommands.
This commit is contained in:
parent
8f5ac0420e
commit
8fc7ba7ac1
7 changed files with 54 additions and 6 deletions
|
@ -1889,6 +1889,26 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case mtpc_updateBotCommands: {
|
||||||
|
const auto &d = update.c_updateBotCommands();
|
||||||
|
if (const auto peer = session().data().peerLoaded(peerFromMTP(d.vpeer()))) {
|
||||||
|
const auto botId = UserId(d.vbot_id().v);
|
||||||
|
if (const auto user = peer->asUser()) {
|
||||||
|
if (user->isBot() && user->id == peerFromUser(botId)) {
|
||||||
|
if (Data::UpdateBotCommands(user->botInfo->commands, d.vcommands())) {
|
||||||
|
session().data().botCommandsChanged(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (const auto chat = peer->asChat()) {
|
||||||
|
chat->setBotCommands(botId, d.vcommands());
|
||||||
|
} else if (const auto megagroup = peer->asMegagroup()) {
|
||||||
|
if (megagroup->mgInfo->updateBotCommands(botId, d.vcommands())) {
|
||||||
|
session().data().botCommandsChanged(megagroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
case mtpc_updateServiceNotification: {
|
case mtpc_updateServiceNotification: {
|
||||||
const auto &d = update.c_updateServiceNotification();
|
const auto &d = update.c_updateServiceNotification();
|
||||||
const auto text = TextWithEntities {
|
const auto text = TextWithEntities {
|
||||||
|
|
|
@ -50,6 +50,12 @@ bool MegagroupInfo::updateBotCommands(const MTPVector<MTPBotInfo> &data) {
|
||||||
return Data::UpdateBotCommands(_botCommands, data);
|
return Data::UpdateBotCommands(_botCommands, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MegagroupInfo::updateBotCommands(
|
||||||
|
UserId botId,
|
||||||
|
const MTPVector<MTPBotCommand> &data) {
|
||||||
|
return Data::UpdateBotCommands(_botCommands, botId, data);
|
||||||
|
}
|
||||||
|
|
||||||
ChannelData::ChannelData(not_null<Data::Session*> owner, PeerId id)
|
ChannelData::ChannelData(not_null<Data::Session*> owner, PeerId id)
|
||||||
: PeerData(owner, id)
|
: PeerData(owner, id)
|
||||||
, inputChannel(
|
, inputChannel(
|
||||||
|
|
|
@ -82,6 +82,9 @@ public:
|
||||||
void setLocation(const ChannelLocation &location);
|
void setLocation(const ChannelLocation &location);
|
||||||
|
|
||||||
bool updateBotCommands(const MTPVector<MTPBotInfo> &data);
|
bool updateBotCommands(const MTPVector<MTPBotInfo> &data);
|
||||||
|
bool updateBotCommands(
|
||||||
|
UserId botId,
|
||||||
|
const MTPVector<MTPBotCommand> &data);
|
||||||
[[nodiscard]] auto botCommands() const
|
[[nodiscard]] auto botCommands() const
|
||||||
-> const base::flat_map<UserId, std::vector<BotCommand>> & {
|
-> const base::flat_map<UserId, std::vector<BotCommand>> & {
|
||||||
return _botCommands;
|
return _botCommands;
|
||||||
|
|
|
@ -250,6 +250,14 @@ void ChatData::setBotCommands(const MTPVector<MTPBotInfo> &data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatData::setBotCommands(
|
||||||
|
UserId botId,
|
||||||
|
const MTPVector<MTPBotCommand> &data) {
|
||||||
|
if (Data::UpdateBotCommands(_botCommands, botId, data)) {
|
||||||
|
owner().botCommandsChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
void ApplyChatUpdate(
|
void ApplyChatUpdate(
|
||||||
|
|
|
@ -156,6 +156,9 @@ public:
|
||||||
[[nodiscard]] PeerId groupCallDefaultJoinAs() const;
|
[[nodiscard]] PeerId groupCallDefaultJoinAs() const;
|
||||||
|
|
||||||
void setBotCommands(const MTPVector<MTPBotInfo> &data);
|
void setBotCommands(const MTPVector<MTPBotInfo> &data);
|
||||||
|
void setBotCommands(
|
||||||
|
UserId botId,
|
||||||
|
const MTPVector<MTPBotCommand> &data);
|
||||||
[[nodiscard]] auto botCommands() const
|
[[nodiscard]] auto botCommands() const
|
||||||
-> const base::flat_map<UserId, std::vector<BotCommand>> & {
|
-> const base::flat_map<UserId, std::vector<BotCommand>> & {
|
||||||
return _botCommands;
|
return _botCommands;
|
||||||
|
|
|
@ -120,6 +120,15 @@ bool UpdateBotCommands(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UpdateBotCommands(
|
||||||
|
base::flat_map<UserId, std::vector<BotCommand>> &commands,
|
||||||
|
UserId botId,
|
||||||
|
const MTPVector<MTPBotCommand> &data) {
|
||||||
|
return data.v.isEmpty()
|
||||||
|
? commands.remove(botId)
|
||||||
|
: UpdateBotCommands(commands[botId], data);
|
||||||
|
}
|
||||||
|
|
||||||
bool UpdateBotCommands(
|
bool UpdateBotCommands(
|
||||||
base::flat_map<UserId, std::vector<BotCommand>> &commands,
|
base::flat_map<UserId, std::vector<BotCommand>> &commands,
|
||||||
const MTPVector<MTPBotInfo> &data) {
|
const MTPVector<MTPBotInfo> &data) {
|
||||||
|
@ -132,12 +141,7 @@ bool UpdateBotCommands(
|
||||||
if (!filled.emplace(id).second) {
|
if (!filled.emplace(id).second) {
|
||||||
LOG(("API Error: Two BotInfo for a single bot."));
|
LOG(("API Error: Two BotInfo for a single bot."));
|
||||||
return;
|
return;
|
||||||
}
|
} else if (UpdateBotCommands(commands, id, data.vcommands())) {
|
||||||
if (data.vcommands().v.isEmpty()) {
|
|
||||||
if (commands.remove(id)) {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
} else if (UpdateBotCommands(commands[id], data.vcommands())) {
|
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -168,6 +168,10 @@ struct UnavailableReason {
|
||||||
bool UpdateBotCommands(
|
bool UpdateBotCommands(
|
||||||
std::vector<BotCommand> &commands,
|
std::vector<BotCommand> &commands,
|
||||||
const MTPVector<MTPBotCommand> &data);
|
const MTPVector<MTPBotCommand> &data);
|
||||||
|
bool UpdateBotCommands(
|
||||||
|
base::flat_map<UserId, std::vector<BotCommand>> &commands,
|
||||||
|
UserId botId,
|
||||||
|
const MTPVector<MTPBotCommand> &data);
|
||||||
bool UpdateBotCommands(
|
bool UpdateBotCommands(
|
||||||
base::flat_map<UserId, std::vector<BotCommand>> &commands,
|
base::flat_map<UserId, std::vector<BotCommand>> &commands,
|
||||||
const MTPVector<MTPBotInfo> &data);
|
const MTPVector<MTPBotInfo> &data);
|
||||||
|
|
Loading…
Add table
Reference in a new issue