Nice design of admin/member tags.

This commit is contained in:
John Preston
2026-02-13 14:38:06 +04:00
parent 3dba01535b
commit e9fced5c2c
14 changed files with 454 additions and 109 deletions
+1 -3
View File
@@ -141,12 +141,10 @@ public:
base::flat_set<not_null<UserData*>> bots;
rpl::event_stream<bool> unrestrictedByBoostsChanges;
// For admin badges, full admins list with ranks.
base::flat_map<UserId, QString> admins;
base::flat_set<UserId> admins;
base::flat_map<UserId, QString> memberRanks;
UserData *creator = nullptr; // nullptr means unknown
QString creatorRank;
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
bool joinedMessageFound = false;
bool adminsLoaded = false;
@@ -20,16 +20,25 @@ ChannelAdminChanges::ChannelAdminChanges(not_null<ChannelData*> channel)
}
void ChannelAdminChanges::add(UserId userId, const QString &rank) {
const auto i = _admins.find(userId);
if (i == end(_admins) || i->second != rank) {
_admins[userId] = rank;
if (_admins.emplace(userId).second) {
_changes.emplace(userId);
}
auto &ranks = _channel->mgInfo->memberRanks;
if (!rank.isEmpty()) {
const auto i = ranks.find(userId);
if (i == end(ranks) || i->second != rank) {
ranks[userId] = rank;
_changes.emplace(userId);
}
} else {
if (ranks.remove(userId)) {
_changes.emplace(userId);
}
}
}
void ChannelAdminChanges::remove(UserId userId) {
if (_admins.contains(userId)) {
_admins.remove(userId);
if (_admins.remove(userId)) {
_changes.emplace(userId);
}
}
@@ -20,7 +20,7 @@ public:
private:
not_null<ChannelData*> _channel;
base::flat_map<UserId, QString> &_admins;
base::flat_set<UserId> &_admins;
base::flat_set<UserId> _changes;
};