2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 22:25:12 +00:00

Moved code for api participants to separated file.

This commit is contained in:
23rd
2021-11-24 07:25:05 +03:00
committed by John Preston
parent 3271cdf251
commit b9c64499bd
24 changed files with 840 additions and 730 deletions

View File

@@ -927,77 +927,4 @@ void ApplyChannelUpdate(
channel->owner().sendHistoryChangeNotifications();
}
void ApplyMegagroupAdmins(
not_null<ChannelData*> channel,
const MTPDchannels_channelParticipants &data) {
Expects(channel->isMegagroup());
channel->owner().processUsers(data.vusers());
const auto &list = data.vparticipants().v;
const auto i = ranges::find(
list,
mtpc_channelParticipantCreator,
&MTPChannelParticipant::type);
if (i != list.end()) {
const auto &data = i->c_channelParticipantCreator();
const auto userId = data.vuser_id().v;
channel->mgInfo->creator = channel->owner().userLoaded(userId);
channel->mgInfo->creatorRank = qs(data.vrank().value_or_empty());
} else {
channel->mgInfo->creator = nullptr;
channel->mgInfo->creatorRank = QString();
}
auto adding = base::flat_map<UserId, QString>();
auto admins = ranges::make_subrange(
list.begin(), list.end()
) | ranges::views::transform([](const MTPChannelParticipant &p) {
const auto participantId = p.match([](
const MTPDchannelParticipantBanned &data) {
return peerFromMTP(data.vpeer());
}, [](const MTPDchannelParticipantLeft &data) {
return peerFromMTP(data.vpeer());
}, [](const auto &data) {
return peerFromUser(data.vuser_id());
});
const auto rank = p.match([](const MTPDchannelParticipantAdmin &data) {
return qs(data.vrank().value_or_empty());
}, [](const MTPDchannelParticipantCreator &data) {
return qs(data.vrank().value_or_empty());
}, [](const auto &data) {
return QString();
});
return std::make_pair(participantId, rank);
}) | ranges::views::filter([](const auto &pair) {
return peerIsUser(pair.first);
});
for (const auto &[participantId, rank] : admins) {
Assert(peerIsUser(participantId));
adding.emplace(peerToUser(participantId), rank);
}
if (channel->mgInfo->creator) {
adding.emplace(
peerToUser(channel->mgInfo->creator->id),
channel->mgInfo->creatorRank);
}
auto removing = channel->mgInfo->admins;
if (removing.empty() && adding.empty()) {
// Add some admin-placeholder so we don't DDOS
// server with admins list requests.
LOG(("API Error: Got empty admins list from server."));
adding.emplace(0, QString());
}
Data::ChannelAdminChanges changes(channel);
for (const auto &[addingId, rank] : adding) {
if (!removing.remove(addingId)) {
changes.add(addingId, rank);
}
}
for (const auto &[removingId, rank] : removing) {
changes.remove(removingId);
}
}
} // namespace Data