Realtime update admin status in members list.

This commit is contained in:
John Preston 2025-06-05 16:09:41 +04:00
parent 03c24e2906
commit bfb4652425
6 changed files with 72 additions and 17 deletions

View file

@ -1522,6 +1522,7 @@ void AddSpecialBoxController::editAdminDone(
}
_additional.applyAdminLocally(user, rights, rank);
// _adminDoneCallback should call changes().chatAdminUpdated.
if (const auto callback = _adminDoneCallback) {
callback(user, rights, rank);
}

View file

@ -461,6 +461,7 @@ void ParticipantsAdditionalData::setExternal(
_adminRights.erase(user);
_adminCanEdit.erase(user);
_adminPromotedBy.erase(user);
_adminRanks.erase(user);
_admins.erase(user);
}
_restrictedRights.erase(participant);
@ -538,6 +539,7 @@ void ParticipantsAdditionalData::fillFromChannel(
_adminRights.erase(user);
_adminCanEdit.erase(user);
_adminPromotedBy.erase(user);
_adminRanks.erase(user);
_restrictedRights.emplace(user, restricted->second.rights);
}
}
@ -743,6 +745,7 @@ UserData *ParticipantsAdditionalData::applyRegular(UserId userId) {
_adminRights.erase(user);
_adminCanEdit.erase(user);
_adminPromotedBy.erase(user);
_adminRanks.erase(user);
_restrictedRights.erase(user);
_kicked.erase(user);
_restrictedBy.erase(user);
@ -761,6 +764,7 @@ PeerData *ParticipantsAdditionalData::applyBanned(
_adminRights.erase(user);
_adminCanEdit.erase(user);
_adminPromotedBy.erase(user);
_adminRanks.erase(user);
}
if (data.isKicked()) {
_kicked.emplace(participant);
@ -1270,6 +1274,33 @@ void ParticipantsBoxController::prepare() {
} else {
rebuild();
}
_peer->session().changes().chatAdminChanges(
) | rpl::start_with_next([=](const Data::ChatAdminChange &update) {
if (update.peer != _peer) {
return;
}
const auto user = update.user;
const auto rights = ChatAdminRightsInfo(update.rights);
const auto rank = update.rank;
_additional.applyAdminLocally(user, rights, rank);
if (!_additional.isCreator(user) || !user->isSelf()) {
if (!rights.flags) {
if (_role == Role::Admins) {
removeRow(user);
}
} else {
if (_role == Role::Admins) {
prependRow(user);
} else if (_role == Role::Kicked
|| _role == Role::Restricted) {
removeRow(user);
}
}
}
recomputeTypeFor(user);
refreshRows();
}, lifetime());
}
void ParticipantsBoxController::unload() {
@ -1800,23 +1831,8 @@ void ParticipantsBoxController::editAdminDone(
if (_editParticipantBox) {
_editParticipantBox->closeBox();
}
_additional.applyAdminLocally(user, rights, rank);
if (!_additional.isCreator(user) || !user->isSelf()) {
if (!rights.flags) {
if (_role == Role::Admins) {
removeRow(user);
}
} else {
if (_role == Role::Admins) {
prependRow(user);
} else if (_role == Role::Kicked || _role == Role::Restricted) {
removeRow(user);
}
}
}
recomputeTypeFor(user);
refreshRows();
const auto flags = rights.flags;
user->session().changes().chatAdminChanged(_peer, user, flags, rank);
}
void ParticipantsBoxController::showRestricted(not_null<UserData*> user) {

View file

@ -340,6 +340,23 @@ rpl::producer<StoryUpdate> Changes::realtimeStoryUpdates(
return _storyChanges.realtimeUpdates(flag);
}
void Changes::chatAdminChanged(
not_null<PeerData*> peer,
not_null<UserData*> user,
ChatAdminRights rights,
QString rank) {
_chatAdminChanges.fire({
.peer = peer,
.user = user,
.rights = rights,
.rank = std::move(rank),
});
}
rpl::producer<ChatAdminChange> Changes::chatAdminChanges() const {
return _chatAdminChanges.events();
}
void Changes::scheduleNotifications() {
if (!_notify) {
_notify = true;

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "base/flags.h"
#include "data/data_chat_participant_status.h"
class History;
class PeerData;
@ -271,6 +272,13 @@ struct StoryUpdate {
};
struct ChatAdminChange {
not_null<PeerData*> peer;
not_null<UserData*> user;
ChatAdminRights rights;
QString rank;
};
class Changes final {
public:
explicit Changes(not_null<Main::Session*> session);
@ -383,6 +391,13 @@ public:
[[nodiscard]] rpl::producer<StoryUpdate> realtimeStoryUpdates(
StoryUpdate::Flag flag) const;
void chatAdminChanged(
not_null<PeerData*> peer,
not_null<UserData*> user,
ChatAdminRights rights,
QString rank);
[[nodiscard]] rpl::producer<ChatAdminChange> chatAdminChanges() const;
void sendNotifications();
private:
@ -435,6 +450,7 @@ private:
Manager<HistoryItem, MessageUpdate> _messageChanges;
Manager<Dialogs::Entry, EntryUpdate> _entryChanges;
Manager<Story, StoryUpdate> _storyChanges;
rpl::event_stream<ChatAdminChange> _chatAdminChanges;
bool _notify = false;

View file

@ -39,6 +39,10 @@ void MemberListRow::setType(Type type) {
: QString());
}
MemberListRow::Type MemberListRow::type() const {
return _type;
}
bool MemberListRow::rightActionDisabled() const {
return true;
}

View file

@ -34,6 +34,7 @@ public:
MemberListRow(not_null<UserData*> user, Type type);
void setType(Type type);
[[nodiscard]] Type type() const;
bool rightActionDisabled() const override;
QMargins rightActionMargins() const override;
void refreshStatus() override;