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:
@@ -151,9 +151,8 @@ void ApplyLastList(
|
||||
}
|
||||
if (user->isBot()) {
|
||||
channel->mgInfo->bots.insert(user);
|
||||
if ((channel->mgInfo->botStatus != 0)
|
||||
&& (channel->mgInfo->botStatus < 2)) {
|
||||
channel->mgInfo->botStatus = 2;
|
||||
if (channel->mgInfo->botStatus == Data::BotStatus::NoBots) {
|
||||
channel->mgInfo->botStatus = Data::BotStatus::HasBots;
|
||||
}
|
||||
}
|
||||
if (!p.rank().isEmpty()) {
|
||||
@@ -189,7 +188,7 @@ void ApplyBotsList(
|
||||
Members list) {
|
||||
const auto history = channel->owner().historyLoaded(channel);
|
||||
channel->mgInfo->bots.clear();
|
||||
channel->mgInfo->botStatus = -1;
|
||||
channel->mgInfo->botStatus = Data::BotStatus::NoBots;
|
||||
|
||||
auto needBotsInfos = false;
|
||||
auto botStatus = channel->mgInfo->botStatus;
|
||||
@@ -199,7 +198,7 @@ void ApplyBotsList(
|
||||
const auto user = participant->asUser();
|
||||
if (user && user->isBot()) {
|
||||
channel->mgInfo->bots.insert(user);
|
||||
botStatus = 2;// (botStatus > 0/* || !i.key()->botInfo->readsAllHistory*/) ? 2 : 1;
|
||||
botStatus = Data::BotStatus::HasBots;
|
||||
if (!user->botInfo->inited) {
|
||||
needBotsInfos = true;
|
||||
}
|
||||
@@ -516,7 +515,7 @@ void ChatParticipants::requestBots(not_null<ChannelData*> channel) {
|
||||
_botsRequests.remove(channel);
|
||||
if (error.type() == u"CHANNEL_MONOFORUM_UNSUPPORTED"_q) {
|
||||
channel->mgInfo->bots.clear();
|
||||
channel->mgInfo->botStatus = -1;
|
||||
channel->mgInfo->botStatus = Data::BotStatus::NoBots;
|
||||
channel->session().changes().peerUpdated(
|
||||
channel,
|
||||
Data::PeerUpdate::Flag::FullInfo);
|
||||
|
||||
@@ -40,8 +40,8 @@ QString WrapCommandInChat(
|
||||
? peer->asChat()->botStatus
|
||||
: peer->isMegagroup()
|
||||
? peer->asChannel()->mgInfo->botStatus
|
||||
: -1;
|
||||
return ((command.indexOf('@') < 2) && (botStatus == 0 || botStatus == 2))
|
||||
: Data::BotStatus::NoBots;
|
||||
return ((command.indexOf('@') < 2) && (botStatus != Data::BotStatus::NoBots))
|
||||
? command + '@' + bot->username()
|
||||
: command;
|
||||
}
|
||||
|
||||
@@ -584,7 +584,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
bots.emplace(_user, &_user->botInfo->commands);
|
||||
} else if (_channel && _channel->isMegagroup()) {
|
||||
if (_channel->mgInfo->bots.empty()) {
|
||||
if (!_channel->mgInfo->botStatus) {
|
||||
if (_channel->mgInfo->botStatus == Data::BotStatus::Unknown) {
|
||||
_channel->session().api().chatParticipants().requestBots(
|
||||
_channel);
|
||||
}
|
||||
@@ -614,7 +614,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
};
|
||||
};
|
||||
brows.reserve(cnt);
|
||||
int32 botStatus = _chat ? _chat->botStatus : ((_channel && _channel->isMegagroup()) ? _channel->mgInfo->botStatus : -1);
|
||||
const auto botStatus = _chat ? _chat->botStatus : ((_channel && _channel->isMegagroup()) ? _channel->mgInfo->botStatus : Data::BotStatus::NoBots);
|
||||
if (_chat) {
|
||||
for (const auto &user : _chat->lastAuthors) {
|
||||
if (!user->isBot()) {
|
||||
@@ -626,7 +626,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
}
|
||||
for (const auto &command : *i->second) {
|
||||
if (!listAllSuggestions) {
|
||||
auto toFilter = (hasUsername || botStatus == 0 || botStatus == 2)
|
||||
auto toFilter = (hasUsername || botStatus != Data::BotStatus::NoBots)
|
||||
? command.command + '@' + PrimaryUsername(user)
|
||||
: command.command;
|
||||
if (!toFilter.startsWith(_filter, Qt::CaseInsensitive)/* || toFilter.size() == _filter.size()*/) {
|
||||
@@ -644,8 +644,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
for (const auto &command : *i->second) {
|
||||
if (!listAllSuggestions) {
|
||||
const auto toFilter = (hasUsername
|
||||
|| botStatus == 0
|
||||
|| botStatus == 2)
|
||||
|| botStatus != Data::BotStatus::NoBots)
|
||||
? command.command + '@' + PrimaryUsername(user)
|
||||
: command.command;
|
||||
if (!toFilter.startsWith(_filter, Qt::CaseInsensitive)/* || toFilter.size() == _filter.size()*/) continue;
|
||||
@@ -1130,8 +1129,8 @@ void FieldAutocomplete::Inner::paintEvent(QPaintEvent *e) {
|
||||
}
|
||||
|
||||
auto toHighlight = row.command;
|
||||
int32 botStatus = _parent->chat() ? _parent->chat()->botStatus : ((_parent->channel() && _parent->channel()->isMegagroup()) ? _parent->channel()->mgInfo->botStatus : -1);
|
||||
if (hasUsername || botStatus == 0 || botStatus == 2) {
|
||||
const auto botStatus = _parent->chat() ? _parent->chat()->botStatus : ((_parent->channel() && _parent->channel()->isMegagroup()) ? _parent->channel()->mgInfo->botStatus : Data::BotStatus::NoBots);
|
||||
if (hasUsername || botStatus != Data::BotStatus::NoBots) {
|
||||
toHighlight += '@' + PrimaryUsername(user);
|
||||
}
|
||||
user->loadUserpic();
|
||||
@@ -1299,10 +1298,9 @@ bool FieldAutocomplete::Inner::chooseAtIndex(
|
||||
? _parent->chat()->botStatus
|
||||
: ((_parent->channel() && _parent->channel()->isMegagroup())
|
||||
? _parent->channel()->mgInfo->botStatus
|
||||
: -1);
|
||||
: Data::BotStatus::NoBots);
|
||||
|
||||
const auto insertUsername = (botStatus == 0
|
||||
|| botStatus == 2
|
||||
const auto insertUsername = (botStatus != Data::BotStatus::NoBots
|
||||
|| _parent->filter().indexOf('@') > 0);
|
||||
const auto commandString = QString("/%1%2").arg(
|
||||
command,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1040,8 +1040,8 @@ not_null<HistoryItem*> History::addNewToBack(
|
||||
auto mgInfo = megagroup->mgInfo.get();
|
||||
Assert(mgInfo != nullptr);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1103,7 +1103,7 @@ not_null<HistoryItem*> History::addNewToBack(
|
||||
item->from()->asUser());
|
||||
} else if (peer->isMegagroup()) {
|
||||
botNotInChat = item->from()->isUser()
|
||||
&& (peer->asChannel()->mgInfo->botStatus != 0
|
||||
&& (peer->asChannel()->mgInfo->botStatus != Data::BotStatus::Unknown
|
||||
|| !Data::CanSendAnything(peer))
|
||||
&& !peer->asChannel()->mgInfo->bots.contains(
|
||||
item->from()->asUser());
|
||||
@@ -1160,8 +1160,8 @@ void History::applyServiceChanges(
|
||||
}
|
||||
if (user->isBot()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1229,8 +1229,8 @@ void History::applyServiceChanges(
|
||||
Data::PeerUpdate::Flag::Admins);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
Data::ChannelAdminChanges(megagroup).remove(uid);
|
||||
@@ -1813,7 +1813,7 @@ void History::addItemsToLists(
|
||||
&& !peer->asChat()->participants.contains(item->author()->asUser());
|
||||
} else if (peer->isMegagroup()) {
|
||||
botNotInChat = (!Data::CanSendAnything(peer)
|
||||
|| peer->asChannel()->mgInfo->botStatus != 0)
|
||||
|| peer->asChannel()->mgInfo->botStatus != Data::BotStatus::Unknown)
|
||||
&& item->author()->isUser()
|
||||
&& !peer->asChannel()->mgInfo->bots.contains(item->author()->asUser());
|
||||
}
|
||||
|
||||
@@ -5629,10 +5629,10 @@ bool HistoryWidget::insertBotCommand(const QString &cmd) {
|
||||
? _peer->asChat()->botStatus
|
||||
: _peer->isMegagroup()
|
||||
? _peer->asChannel()->mgInfo->botStatus
|
||||
: -1;
|
||||
: Data::BotStatus::NoBots;
|
||||
if ((toInsert.indexOf('@') < 0)
|
||||
&& !username.isEmpty()
|
||||
&& (botStatus == 0 || botStatus == 2)) {
|
||||
&& (botStatus != Data::BotStatus::NoBots)) {
|
||||
toInsert += '@' + username;
|
||||
}
|
||||
}
|
||||
@@ -5844,9 +5844,9 @@ bool HistoryWidget::updateCmdStartShown() {
|
||||
if (_history
|
||||
&& _peer
|
||||
&& (false
|
||||
|| (_peer->isChat() && _peer->asChat()->botStatus > 0)
|
||||
|| (_peer->isChat() && _peer->asChat()->botStatus == Data::BotStatus::HasBots)
|
||||
|| (_peer->isMegagroup()
|
||||
&& _peer->asChannel()->mgInfo->botStatus > 0))) {
|
||||
&& _peer->asChannel()->mgInfo->botStatus == Data::BotStatus::HasBots))) {
|
||||
if (!isBotStart()
|
||||
&& !isBlocked()
|
||||
&& !_keyboard->hasMarkup()
|
||||
@@ -9393,7 +9393,7 @@ void HistoryWidget::handlePeerUpdate() {
|
||||
== UserData::CallsStatus::Unknown))) {
|
||||
session().api().requestFullPeer(_peer);
|
||||
} else if (auto channel = _peer->asMegagroup()) {
|
||||
if (!channel->mgInfo->botStatus) {
|
||||
if (channel->mgInfo->botStatus == Data::BotStatus::Unknown) {
|
||||
session().api().chatParticipants().requestBots(channel);
|
||||
}
|
||||
if (!channel->mgInfo->adminsLoaded) {
|
||||
|
||||
@@ -1184,7 +1184,7 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) {
|
||||
if (peer->isChat() && peer->asChat()->noParticipantInfo()) {
|
||||
session().api().requestFullPeer(peer);
|
||||
} else if (const auto channel = peer->asMegagroup()) {
|
||||
if (!channel->mgInfo->botStatus) {
|
||||
if (channel->mgInfo->botStatus == Data::BotStatus::Unknown) {
|
||||
session().api().chatParticipants().requestBots(channel);
|
||||
}
|
||||
} else if (hasSilentBroadcastToggle()) {
|
||||
@@ -3698,8 +3698,8 @@ bool ComposeControls::updateBotCommandShown() {
|
||||
const auto peer = _history ? _history->peer.get() : nullptr;
|
||||
if (_botCommandStart
|
||||
&& peer
|
||||
&& ((peer->isChat() && peer->asChat()->botStatus > 0)
|
||||
|| (peer->isMegagroup() && peer->asChannel()->mgInfo->botStatus > 0)
|
||||
&& ((peer->isChat() && peer->asChat()->botStatus == Data::BotStatus::HasBots)
|
||||
|| (peer->isMegagroup() && peer->asChannel()->mgInfo->botStatus == Data::BotStatus::HasBots)
|
||||
|| (peer->isUser() && peer->asUser()->isBot()))) {
|
||||
if (!HasSendText(_field)) {
|
||||
shown = true;
|
||||
|
||||
@@ -24,11 +24,11 @@ bool UseBotTextOptions(
|
||||
return true;
|
||||
}
|
||||
} else if (const auto chat = history->peer->asChat()) {
|
||||
if (chat->botStatus >= 0) {
|
||||
if (chat->botStatus != Data::BotStatus::NoBots) {
|
||||
return true;
|
||||
}
|
||||
} else if (const auto group = history->peer->asMegagroup()) {
|
||||
if (group->mgInfo->botStatus >= 0) {
|
||||
if (group->mgInfo->botStatus != Data::BotStatus::NoBots) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user