init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
53
Telegram/SourceFiles/data/data_peer_bot_commands.cpp
Normal file
53
Telegram/SourceFiles/data/data_peer_bot_commands.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "data/data_peer_bot_commands.h"
|
||||
|
||||
namespace Data {
|
||||
|
||||
ChatBotCommands::Changed ChatBotCommands::update(
|
||||
const std::vector<BotCommands> &list) {
|
||||
auto changed = false;
|
||||
if (list.empty()) {
|
||||
changed = (list.empty() != empty());
|
||||
clear();
|
||||
} else {
|
||||
for (const auto &commands : list) {
|
||||
if (commands.commands.empty()) {
|
||||
changed |= remove(commands.userId);
|
||||
} else {
|
||||
auto &value = operator[](commands.userId);
|
||||
const auto isEqual = ranges::equal(value, commands.commands);
|
||||
changed |= !isEqual;
|
||||
if (!isEqual) {
|
||||
value = commands.commands;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
BotCommands BotCommandsFromTL(const MTPBotInfo &result) {
|
||||
return result.match([](const MTPDbotInfo &data) {
|
||||
const auto userId = data.vuser_id()
|
||||
? UserId(*data.vuser_id())
|
||||
: UserId();
|
||||
if (!data.vcommands()) {
|
||||
return BotCommands{ .userId = userId };
|
||||
}
|
||||
auto commands = ranges::views::all(
|
||||
data.vcommands()->v
|
||||
) | ranges::views::transform(BotCommandFromTL) | ranges::to_vector;
|
||||
return BotCommands{
|
||||
.userId = userId,
|
||||
.commands = std::move(commands),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
Reference in New Issue
Block a user