From 969ade40f34a621754c1d8f9fdd2e0c9e78cf10e Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 23 Aug 2026 18:30:09 +0300 Subject: [PATCH] Added preload of admins to participants controller for role grouping. Related commit: 9fa11844f2. --- .../boxes/peers/edit_participants_box.cpp | 48 +++++++++++++++++++ .../boxes/peers/edit_participants_box.h | 3 ++ 2 files changed, 51 insertions(+) diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 48a6b995ba..b333b8a6a5 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1581,7 +1581,11 @@ void ParticipantsBoxController::unload() { if (const auto requestId = base::take(_loadRequestId)) { _api.request(requestId).cancel(); } + if (const auto requestId = base::take(_adminsRequestId)) { + _api.request(requestId).cancel(); + } _allLoaded = false; + _adminsPreloaded = false; _offset = 0; } @@ -1590,6 +1594,7 @@ void ParticipantsBoxController::rebuild() { prepareChatRows(chat); } else { loadMoreRows(); + preloadAdmins(); } refreshRows(); } @@ -2711,6 +2716,48 @@ void ParticipantsBoxController::applyRoleSectionHeaders() { } } +void ParticipantsBoxController::preloadAdmins() { + if (_adminsPreloaded + || _adminsRequestId + || !_groupByRole.current() + || (_role != Role::Profile && _role != Role::Members)) { + return; + } + const auto channel = _peer->asChannel(); + if (!channel || !channel->canViewAdmins()) { + return; + } + const auto offset = 0; + const auto participantsHash = uint64(0); + _adminsRequestId = _api.request(MTPchannels_GetParticipants( + channel->inputChannel(), + MTP_channelParticipantsAdmins(), + MTP_int(offset), + MTP_int(channel->session().serverConfig().chatSizeMax), + MTP_long(participantsHash) + )).done([=](const MTPchannels_ChannelParticipants &result) { + _adminsRequestId = 0; + _adminsPreloaded = true; + result.match([&](const MTPDchannels_channelParticipants &data) { + const auto &[availableCount, list] + = Api::ChatParticipants::Parse(channel, data); + for (const auto &data : list) { + if (const auto participant = _additional.applyParticipant( + data)) { + appendRow(participant); + } + } + }, [](const MTPDchannels_channelParticipantsNotModified &) { + LOG(("API Error: " + "channels.channelParticipantsNotModified received!")); + }); + resort(); + refreshRows(); + }).fail([=] { + _adminsRequestId = 0; + }).send(); +} + void ParticipantsBoxController::resort() { if (_groupByRole.current()) { if (_onlineSorter) { @@ -2735,6 +2782,7 @@ void ParticipantsBoxController::setGroupByRole(bool grouped) { return; } _groupByRole = grouped; + preloadAdmins(); resort(); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h index 43b2786535..ed59143d81 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h @@ -321,6 +321,7 @@ private: void fullListRefresh(); void refreshRows(); void resort(); + void preloadAdmins(); void sortByRoleAndName(); void applyRoleSectionHeaders(); [[nodiscard]] int memberRoleTier(not_null peer) const; @@ -333,7 +334,9 @@ private: Role _role = Role::Admins; int _offset = 0; mtpRequestId _loadRequestId = 0; + mtpRequestId _adminsRequestId = 0; bool _allLoaded = false; + bool _adminsPreloaded = false; ParticipantsAdditionalData _additional; std::unique_ptr _onlineSorter; rpl::variable _groupByRole = false;