2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Apply channel admin edition changes.

This commit is contained in:
John Preston
2017-12-02 15:07:27 +04:00
parent 675499df4d
commit 301aa9572f
6 changed files with 111 additions and 19 deletions

View File

@@ -44,6 +44,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "storage/storage_user_photos.h"
#include "data/data_sparse_ids.h"
#include "data/data_search_controller.h"
#include "data/data_channel_admins.h"
namespace {
@@ -1792,24 +1793,12 @@ void ApiWrap::parseChannelParticipants(
void ApiWrap::refreshChannelAdmins(
not_null<ChannelData*> channel,
const QVector<MTPChannelParticipant> &participants) {
auto changes = base::flat_map<UserId, bool>();
auto &admins = channel->mgInfo->admins;
for (auto &participant : participants) {
auto userId = TLHelp::ReadChannelParticipantUserId(participant);
auto admin = (participant.type() == mtpc_channelParticipantAdmin)
|| (participant.type() == mtpc_channelParticipantCreator);
if (admin && !admins.contains(userId)) {
admins.insert(userId);
changes.emplace(userId, true);
} else if (!admin && admins.contains(userId)) {
admins.remove(userId);
changes.emplace(userId, false);
}
}
if (!changes.empty()) {
if (auto history = App::historyLoaded(channel)) {
history->applyGroupAdminChanges(changes);
}
Data::ChannelAdminChanges changes(channel);
for (auto &p : participants) {
const auto userId = TLHelp::ReadChannelParticipantUserId(p);
const auto isAdmin = (p.type() == mtpc_channelParticipantAdmin)
|| (p.type() == mtpc_channelParticipantCreator);
changes.feed(userId, isAdmin);
}
}