2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Display admin badges in supergroups.

Also prefer std containers to Qt and OrderedSet in data_peer.
This commit is contained in:
John Preston
2017-12-01 22:38:44 +04:00
parent 3bdce06e19
commit 85b3d3f64d
27 changed files with 347 additions and 220 deletions

View File

@@ -806,7 +806,7 @@ void ChannelData::setInviteLink(const QString &newInviteLink) {
void ChannelData::setMembersCount(int newMembersCount) {
if (_membersCount != newMembersCount) {
if (isMegagroup() && !mgInfo->lastParticipants.isEmpty()) {
if (isMegagroup() && !mgInfo->lastParticipants.empty()) {
mgInfo->lastParticipantsStatus |= MegagroupInfo::LastParticipantsCountOutdated;
mgInfo->lastParticipantsCount = membersCount();
}
@@ -845,7 +845,8 @@ MTPChannelBannedRights ChannelData::KickedRestrictedRights() {
void ChannelData::applyEditAdmin(not_null<UserData*> user, const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
auto flags = Notify::PeerUpdate::Flag::AdminsChanged | Notify::PeerUpdate::Flag::None;
if (mgInfo) {
if (!mgInfo->lastParticipants.contains(user)) { // If rights are empty - still add participant? TODO check
// If rights are empty - still add participant? TODO check
if (!base::contains(mgInfo->lastParticipants, user)) {
mgInfo->lastParticipants.push_front(user);
setMembersCount(membersCount() + 1);
if (user->botInfo && !mgInfo->bots.contains(user)) {
@@ -855,7 +856,8 @@ void ChannelData::applyEditAdmin(not_null<UserData*> user, const MTPChannelAdmin
}
}
}
if (mgInfo->lastRestricted.contains(user)) { // If rights are empty - still remove restrictions? TODO check
// If rights are empty - still remove restrictions? TODO check
if (mgInfo->lastRestricted.contains(user)) {
mgInfo->lastRestricted.remove(user);
if (restrictedCount() > 0) {
setRestrictedCount(restrictedCount() - 1);
@@ -866,10 +868,10 @@ void ChannelData::applyEditAdmin(not_null<UserData*> user, const MTPChannelAdmin
auto lastAdmin = MegagroupInfo::Admin { newRights };
lastAdmin.canEdit = true;
if (it == mgInfo->lastAdmins.cend()) {
mgInfo->lastAdmins.insert(user, lastAdmin);
mgInfo->lastAdmins.emplace(user, lastAdmin);
setAdminsCount(adminsCount() + 1);
} else {
it.value() = lastAdmin;
it->second = lastAdmin;
}
} else {
if (it != mgInfo->lastAdmins.cend()) {
@@ -913,10 +915,10 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBann
auto it = mgInfo->lastRestricted.find(user);
if (isRestricted) {
if (it == mgInfo->lastRestricted.cend()) {
mgInfo->lastRestricted.insert(user, MegagroupInfo::Restricted { newRights });
mgInfo->lastRestricted.emplace(user, MegagroupInfo::Restricted { newRights });
setRestrictedCount(restrictedCount() + 1);
} else {
it->rights = newRights;
it->second.rights = newRights;
}
} else {
if (it != mgInfo->lastRestricted.cend()) {
@@ -926,9 +928,9 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBann
}
}
if (isKicked) {
auto i = mgInfo->lastParticipants.indexOf(user);
if (i >= 0) {
mgInfo->lastParticipants.removeAt(i);
auto i = ranges::find(mgInfo->lastParticipants, user);
if (i != mgInfo->lastParticipants.end()) {
mgInfo->lastParticipants.erase(i);
}
if (membersCount() > 1) {
setMembersCount(membersCount() - 1);
@@ -939,7 +941,7 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBann
setKickedCount(kickedCount() + 1);
if (mgInfo->bots.contains(user)) {
mgInfo->bots.remove(user);
if (mgInfo->bots.isEmpty() && mgInfo->botStatus > 0) {
if (mgInfo->bots.empty() && mgInfo->botStatus > 0) {
mgInfo->botStatus = -1;
}
}
@@ -956,6 +958,13 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBann
Notify::peerUpdatedDelayed(this, flags);
}
bool ChannelData::isGroupAdmin(not_null<UserData*> user) const {
if (auto info = mgInfo.get()) {
return info->admins.contains(peerToUser(user->id));
}
return false;
}
void ChannelData::setRestrictionReason(const QString &text) {
if (_restrictionReason != text) {
_restrictionReason = text;
@@ -1087,9 +1096,9 @@ bool ChannelData::canDelete() const {
bool ChannelData::canEditLastAdmin(not_null<UserData*> user) const {
// Duplicated in ParticipantsBoxController::canEditAdmin :(
if (mgInfo) {
auto i = mgInfo->lastAdmins.constFind(user);
auto i = mgInfo->lastAdmins.find(user);
if (i != mgInfo->lastAdmins.cend()) {
return i->canEdit;
return i->second.canEdit;
}
return (user != mgInfo->creator);
}
@@ -1130,7 +1139,7 @@ void ChannelData::setAdminRights(const MTPChannelAdminRights &rights) {
if (!amCreator()) {
auto me = MegagroupInfo::Admin { rights };
me.canEdit = false;
mgInfo->lastAdmins.insert(App::self(), me);
mgInfo->lastAdmins.emplace(App::self(), me);
}
mgInfo->lastRestricted.remove(App::self());
} else {
@@ -1151,7 +1160,7 @@ void ChannelData::setRestrictedRights(const MTPChannelBannedRights &rights) {
if (hasRestrictions()) {
if (!amCreator()) {
auto me = MegagroupInfo::Restricted { rights };
mgInfo->lastRestricted.insert(App::self(), me);
mgInfo->lastRestricted.emplace(App::self(), me);
}
mgInfo->lastAdmins.remove(App::self());
} else {

View File

@@ -115,11 +115,6 @@ private:
static const PhotoId UnknownPeerPhotoId = 0xFFFFFFFFFFFFFFFFULL;
inline const QString &emptyUsername() {
static QString empty;
return empty;
}
class PeerData;
class PeerClickHandler : public ClickHandler {
@@ -195,7 +190,7 @@ public:
const Text &dialogName() const;
const QString &shortName() const;
const QString &userName() const;
QString userName() const;
const PeerId id;
int32 bareId() const {
@@ -559,7 +554,7 @@ public:
void invalidateParticipants();
bool noParticipantInfo() const {
return (count > 0 || amIn()) && participants.isEmpty();
return (count > 0 || amIn()) && participants.empty();
}
MTPint inputChat;
@@ -623,11 +618,11 @@ public:
bool isMigrated() const {
return flags() & MTPDchat::Flag::f_migrated_to;
}
QMap<not_null<UserData*>, int> participants;
OrderedSet<not_null<UserData*>> invitedByMe;
OrderedSet<not_null<UserData*>> admins;
QList<not_null<UserData*>> lastAuthors;
OrderedSet<not_null<PeerData*>> markupSenders;
base::flat_map<not_null<UserData*>, int> participants;
base::flat_set<not_null<UserData*>> invitedByMe;
base::flat_set<not_null<UserData*>> admins;
std::deque<not_null<UserData*>> lastAuthors;
base::flat_set<not_null<PeerData*>> markupSenders;
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
// ImagePtr photoFull;
@@ -744,11 +739,14 @@ struct MegagroupInfo {
}
MTPChannelBannedRights rights;
};
QList<not_null<UserData*>> lastParticipants;
QMap<not_null<UserData*>, Admin> lastAdmins;
QMap<not_null<UserData*>, Restricted> lastRestricted;
OrderedSet<not_null<PeerData*>> markupSenders;
OrderedSet<not_null<UserData*>> bots;
std::deque<not_null<UserData*>> lastParticipants;
base::flat_map<not_null<UserData*>, Admin> lastAdmins;
base::flat_map<not_null<UserData*>, Restricted> lastRestricted;
base::flat_set<not_null<PeerData*>> markupSenders;
base::flat_set<not_null<UserData*>> bots;
// For admin badges, full admins list.
base::flat_set<UserId> admins;
UserData *creator = nullptr; // nullptr means unknown
int botStatus = 0; // -1 - no bots, 0 - unknown, 1 - one bot, that sees all history, 2 - other
@@ -898,6 +896,8 @@ public:
const MTPChannelBannedRights &oldRights,
const MTPChannelBannedRights &newRights);
bool isGroupAdmin(not_null<UserData*> user) const;
int32 date = 0;
int version = 0;
std::unique_ptr<MegagroupInfo> mgInfo;
@@ -1176,12 +1176,12 @@ inline const Text &PeerData::dialogName() const {
inline const QString &PeerData::shortName() const {
return isUser() ? asUser()->firstName : name;
}
inline const QString &PeerData::userName() const {
inline QString PeerData::userName() const {
return isUser()
? asUser()->username
: isChannel()
? asChannel()->username
: emptyUsername();
: QString();
}
inline bool PeerData::isVerified() const {
return isUser()