Replaced int botStatus with a type-safe Data::BotStatus enum class.

This commit is contained in:
23rd
2026-03-30 11:52:49 +03:00
parent 8f4b6f80ad
commit aa5e0440d4
12 changed files with 57 additions and 50 deletions
+12 -8
View File
@@ -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();
}
}