mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-27 07:52:57 +02:00
Realtime update admin status in members list.
This commit is contained in:
parent
03c24e2906
commit
bfb4652425
6 changed files with 72 additions and 17 deletions
|
@ -1522,6 +1522,7 @@ void AddSpecialBoxController::editAdminDone(
|
||||||
}
|
}
|
||||||
|
|
||||||
_additional.applyAdminLocally(user, rights, rank);
|
_additional.applyAdminLocally(user, rights, rank);
|
||||||
|
// _adminDoneCallback should call changes().chatAdminUpdated.
|
||||||
if (const auto callback = _adminDoneCallback) {
|
if (const auto callback = _adminDoneCallback) {
|
||||||
callback(user, rights, rank);
|
callback(user, rights, rank);
|
||||||
}
|
}
|
||||||
|
|
|
@ -461,6 +461,7 @@ void ParticipantsAdditionalData::setExternal(
|
||||||
_adminRights.erase(user);
|
_adminRights.erase(user);
|
||||||
_adminCanEdit.erase(user);
|
_adminCanEdit.erase(user);
|
||||||
_adminPromotedBy.erase(user);
|
_adminPromotedBy.erase(user);
|
||||||
|
_adminRanks.erase(user);
|
||||||
_admins.erase(user);
|
_admins.erase(user);
|
||||||
}
|
}
|
||||||
_restrictedRights.erase(participant);
|
_restrictedRights.erase(participant);
|
||||||
|
@ -538,6 +539,7 @@ void ParticipantsAdditionalData::fillFromChannel(
|
||||||
_adminRights.erase(user);
|
_adminRights.erase(user);
|
||||||
_adminCanEdit.erase(user);
|
_adminCanEdit.erase(user);
|
||||||
_adminPromotedBy.erase(user);
|
_adminPromotedBy.erase(user);
|
||||||
|
_adminRanks.erase(user);
|
||||||
_restrictedRights.emplace(user, restricted->second.rights);
|
_restrictedRights.emplace(user, restricted->second.rights);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -743,6 +745,7 @@ UserData *ParticipantsAdditionalData::applyRegular(UserId userId) {
|
||||||
_adminRights.erase(user);
|
_adminRights.erase(user);
|
||||||
_adminCanEdit.erase(user);
|
_adminCanEdit.erase(user);
|
||||||
_adminPromotedBy.erase(user);
|
_adminPromotedBy.erase(user);
|
||||||
|
_adminRanks.erase(user);
|
||||||
_restrictedRights.erase(user);
|
_restrictedRights.erase(user);
|
||||||
_kicked.erase(user);
|
_kicked.erase(user);
|
||||||
_restrictedBy.erase(user);
|
_restrictedBy.erase(user);
|
||||||
|
@ -761,6 +764,7 @@ PeerData *ParticipantsAdditionalData::applyBanned(
|
||||||
_adminRights.erase(user);
|
_adminRights.erase(user);
|
||||||
_adminCanEdit.erase(user);
|
_adminCanEdit.erase(user);
|
||||||
_adminPromotedBy.erase(user);
|
_adminPromotedBy.erase(user);
|
||||||
|
_adminRanks.erase(user);
|
||||||
}
|
}
|
||||||
if (data.isKicked()) {
|
if (data.isKicked()) {
|
||||||
_kicked.emplace(participant);
|
_kicked.emplace(participant);
|
||||||
|
@ -1270,6 +1274,33 @@ void ParticipantsBoxController::prepare() {
|
||||||
} else {
|
} else {
|
||||||
rebuild();
|
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() {
|
void ParticipantsBoxController::unload() {
|
||||||
|
@ -1800,23 +1831,8 @@ void ParticipantsBoxController::editAdminDone(
|
||||||
if (_editParticipantBox) {
|
if (_editParticipantBox) {
|
||||||
_editParticipantBox->closeBox();
|
_editParticipantBox->closeBox();
|
||||||
}
|
}
|
||||||
|
const auto flags = rights.flags;
|
||||||
_additional.applyAdminLocally(user, rights, rank);
|
user->session().changes().chatAdminChanged(_peer, user, flags, 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantsBoxController::showRestricted(not_null<UserData*> user) {
|
void ParticipantsBoxController::showRestricted(not_null<UserData*> user) {
|
||||||
|
|
|
@ -340,6 +340,23 @@ rpl::producer<StoryUpdate> Changes::realtimeStoryUpdates(
|
||||||
return _storyChanges.realtimeUpdates(flag);
|
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() {
|
void Changes::scheduleNotifications() {
|
||||||
if (!_notify) {
|
if (!_notify) {
|
||||||
_notify = true;
|
_notify = true;
|
||||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "base/flags.h"
|
#include "base/flags.h"
|
||||||
|
#include "data/data_chat_participant_status.h"
|
||||||
|
|
||||||
class History;
|
class History;
|
||||||
class PeerData;
|
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 {
|
class Changes final {
|
||||||
public:
|
public:
|
||||||
explicit Changes(not_null<Main::Session*> session);
|
explicit Changes(not_null<Main::Session*> session);
|
||||||
|
@ -383,6 +391,13 @@ public:
|
||||||
[[nodiscard]] rpl::producer<StoryUpdate> realtimeStoryUpdates(
|
[[nodiscard]] rpl::producer<StoryUpdate> realtimeStoryUpdates(
|
||||||
StoryUpdate::Flag flag) const;
|
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();
|
void sendNotifications();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -435,6 +450,7 @@ private:
|
||||||
Manager<HistoryItem, MessageUpdate> _messageChanges;
|
Manager<HistoryItem, MessageUpdate> _messageChanges;
|
||||||
Manager<Dialogs::Entry, EntryUpdate> _entryChanges;
|
Manager<Dialogs::Entry, EntryUpdate> _entryChanges;
|
||||||
Manager<Story, StoryUpdate> _storyChanges;
|
Manager<Story, StoryUpdate> _storyChanges;
|
||||||
|
rpl::event_stream<ChatAdminChange> _chatAdminChanges;
|
||||||
|
|
||||||
bool _notify = false;
|
bool _notify = false;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,10 @@ void MemberListRow::setType(Type type) {
|
||||||
: QString());
|
: QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemberListRow::Type MemberListRow::type() const {
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
|
|
||||||
bool MemberListRow::rightActionDisabled() const {
|
bool MemberListRow::rightActionDisabled() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ public:
|
||||||
MemberListRow(not_null<UserData*> user, Type type);
|
MemberListRow(not_null<UserData*> user, Type type);
|
||||||
|
|
||||||
void setType(Type type);
|
void setType(Type type);
|
||||||
|
[[nodiscard]] Type type() const;
|
||||||
bool rightActionDisabled() const override;
|
bool rightActionDisabled() const override;
|
||||||
QMargins rightActionMargins() const override;
|
QMargins rightActionMargins() const override;
|
||||||
void refreshStatus() override;
|
void refreshStatus() override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue