mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/telegramdesktop/tdesktop
synced 2026-09-20 08:03:45 +08:00
Added preload of admins to participants controller for role grouping.
Related commit: 9fa11844f2.
This commit is contained in:
@@ -1581,7 +1581,11 @@ void ParticipantsBoxController::unload() {
|
|||||||
if (const auto requestId = base::take(_loadRequestId)) {
|
if (const auto requestId = base::take(_loadRequestId)) {
|
||||||
_api.request(requestId).cancel();
|
_api.request(requestId).cancel();
|
||||||
}
|
}
|
||||||
|
if (const auto requestId = base::take(_adminsRequestId)) {
|
||||||
|
_api.request(requestId).cancel();
|
||||||
|
}
|
||||||
_allLoaded = false;
|
_allLoaded = false;
|
||||||
|
_adminsPreloaded = false;
|
||||||
_offset = 0;
|
_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1590,6 +1594,7 @@ void ParticipantsBoxController::rebuild() {
|
|||||||
prepareChatRows(chat);
|
prepareChatRows(chat);
|
||||||
} else {
|
} else {
|
||||||
loadMoreRows();
|
loadMoreRows();
|
||||||
|
preloadAdmins();
|
||||||
}
|
}
|
||||||
refreshRows();
|
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() {
|
void ParticipantsBoxController::resort() {
|
||||||
if (_groupByRole.current()) {
|
if (_groupByRole.current()) {
|
||||||
if (_onlineSorter) {
|
if (_onlineSorter) {
|
||||||
@@ -2735,6 +2782,7 @@ void ParticipantsBoxController::setGroupByRole(bool grouped) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_groupByRole = grouped;
|
_groupByRole = grouped;
|
||||||
|
preloadAdmins();
|
||||||
resort();
|
resort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ private:
|
|||||||
void fullListRefresh();
|
void fullListRefresh();
|
||||||
void refreshRows();
|
void refreshRows();
|
||||||
void resort();
|
void resort();
|
||||||
|
void preloadAdmins();
|
||||||
void sortByRoleAndName();
|
void sortByRoleAndName();
|
||||||
void applyRoleSectionHeaders();
|
void applyRoleSectionHeaders();
|
||||||
[[nodiscard]] int memberRoleTier(not_null<PeerData*> peer) const;
|
[[nodiscard]] int memberRoleTier(not_null<PeerData*> peer) const;
|
||||||
@@ -333,7 +334,9 @@ private:
|
|||||||
Role _role = Role::Admins;
|
Role _role = Role::Admins;
|
||||||
int _offset = 0;
|
int _offset = 0;
|
||||||
mtpRequestId _loadRequestId = 0;
|
mtpRequestId _loadRequestId = 0;
|
||||||
|
mtpRequestId _adminsRequestId = 0;
|
||||||
bool _allLoaded = false;
|
bool _allLoaded = false;
|
||||||
|
bool _adminsPreloaded = false;
|
||||||
ParticipantsAdditionalData _additional;
|
ParticipantsAdditionalData _additional;
|
||||||
std::unique_ptr<ParticipantsOnlineSorter> _onlineSorter;
|
std::unique_ptr<ParticipantsOnlineSorter> _onlineSorter;
|
||||||
rpl::variable<bool> _groupByRole = false;
|
rpl::variable<bool> _groupByRole = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user