mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Replaced int botStatus with a type-safe Data::BotStatus enum class.
This commit is contained in:
@@ -458,8 +458,8 @@ void ChannelData::applyEditAdmin(
|
||||
setMembersCount(membersCount() + 1);
|
||||
if (user->isBot() && !mgInfo->bots.contains(user)) {
|
||||
mgInfo->bots.insert(user);
|
||||
if (mgInfo->botStatus != 0 && mgInfo->botStatus < 2) {
|
||||
mgInfo->botStatus = 2;
|
||||
if (mgInfo->botStatus == Data::BotStatus::NoBots) {
|
||||
mgInfo->botStatus = Data::BotStatus::HasBots;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -576,8 +576,8 @@ void ChannelData::applyEditBanned(
|
||||
setKickedCount(kickedCount() + 1);
|
||||
if (mgInfo->bots.contains(user)) {
|
||||
mgInfo->bots.remove(user);
|
||||
if (mgInfo->bots.empty() && mgInfo->botStatus > 0) {
|
||||
mgInfo->botStatus = -1;
|
||||
if (mgInfo->bots.empty() && mgInfo->botStatus == Data::BotStatus::HasBots) {
|
||||
mgInfo->botStatus = Data::BotStatus::NoBots;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
base::flat_map<UserId, QString> memberRanks;
|
||||
|
||||
UserData *creator = nullptr; // nullptr means unknown
|
||||
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
|
||||
Data::BotStatus botStatus = Data::BotStatus::Unknown;
|
||||
bool joinedMessageFound = false;
|
||||
bool adminsLoaded = false;
|
||||
StickerSetIdentifier stickerSet;
|
||||
|
||||
@@ -126,7 +126,7 @@ void ChatData::invalidateParticipants() {
|
||||
setAdminRights(ChatAdminRights());
|
||||
//setDefaultRestrictions(ChatRestrictions());
|
||||
invitedByMe.clear();
|
||||
botStatus = 0;
|
||||
botStatus = Data::BotStatus::Unknown;
|
||||
session().changes().peerUpdated(
|
||||
this,
|
||||
UpdateFlag::Members | UpdateFlag::Admins);
|
||||
@@ -176,10 +176,14 @@ void ChatData::setDefaultRestrictions(ChatRestrictions rights) {
|
||||
|
||||
void ChatData::refreshBotStatus() {
|
||||
if (participants.empty()) {
|
||||
botStatus = 0;
|
||||
botStatus = Data::BotStatus::Unknown;
|
||||
} else {
|
||||
const auto bot = ranges::none_of(participants, &UserData::isBot);
|
||||
botStatus = bot ? -1 : 2;
|
||||
const auto noBots = ranges::none_of(
|
||||
participants,
|
||||
&UserData::isBot);
|
||||
botStatus = noBots
|
||||
? Data::BotStatus::NoBots
|
||||
: Data::BotStatus::HasBots;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,7 +350,7 @@ void ApplyChatUpdate(
|
||||
if (chat->count > 0) { // If the count is known.
|
||||
++chat->count;
|
||||
}
|
||||
chat->botStatus = 0;
|
||||
chat->botStatus = Data::BotStatus::Unknown;
|
||||
} else {
|
||||
chat->participants.emplace(user);
|
||||
if (UserId(update.vinviter_id()) == session->userId()) {
|
||||
@@ -356,7 +360,7 @@ void ApplyChatUpdate(
|
||||
}
|
||||
++chat->count;
|
||||
if (user->isBot()) {
|
||||
chat->botStatus = 2;
|
||||
chat->botStatus = Data::BotStatus::HasBots;
|
||||
if (!user->botInfo->inited) {
|
||||
session->api().requestFullPeer(user);
|
||||
}
|
||||
@@ -386,7 +390,7 @@ void ApplyChatUpdate(
|
||||
if (chat->count > 0) {
|
||||
chat->count--;
|
||||
}
|
||||
chat->botStatus = 0;
|
||||
chat->botStatus = Data::BotStatus::Unknown;
|
||||
} else {
|
||||
chat->participants.erase(user);
|
||||
chat->count--;
|
||||
@@ -400,7 +404,7 @@ void ApplyChatUpdate(
|
||||
history->clearLastKeyboard();
|
||||
}
|
||||
}
|
||||
if (chat->botStatus > 0 && user->isBot()) {
|
||||
if (chat->botStatus == Data::BotStatus::HasBots && user->isBot()) {
|
||||
chat->refreshBotStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public:
|
||||
std::deque<not_null<UserData*>> lastAuthors;
|
||||
base::flat_set<not_null<PeerData*>> markupSenders;
|
||||
base::flat_map<UserId, QString> memberRanks;
|
||||
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
|
||||
Data::BotStatus botStatus = Data::BotStatus::Unknown;
|
||||
|
||||
private:
|
||||
Flags _flags;
|
||||
|
||||
@@ -11,6 +11,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
namespace Data {
|
||||
|
||||
enum class BotStatus : int {
|
||||
NoBots = -1,
|
||||
Unknown = 0,
|
||||
HasBots = 2,
|
||||
};
|
||||
|
||||
struct BotCommands final {
|
||||
UserId userId;
|
||||
std::vector<BotCommand> commands;
|
||||
|
||||
Reference in New Issue
Block a user