tdesktop/Telegram/SourceFiles/data/data_channel_admins.cpp

40 lines
1.0 KiB
C++
Raw Normal View History

2017-12-02 11:07:27 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2017-12-02 11:07:27 +00:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2017-12-02 11:07:27 +00:00
*/
#include "data/data_channel_admins.h"
#include "history/history.h"
#include "data/data_channel.h"
2019-01-18 12:27:37 +00:00
#include "data/data_session.h"
2017-12-02 11:07:27 +00:00
namespace Data {
ChannelAdminChanges::ChannelAdminChanges(not_null<ChannelData*> channel)
: _channel(channel)
, _admins(_channel->mgInfo->admins) {
}
void ChannelAdminChanges::feed(UserId userId, bool isAdmin) {
if (isAdmin && !_admins.contains(userId)) {
_admins.insert(userId);
_changes.emplace(userId, true);
} else if (!isAdmin && _admins.contains(userId)) {
_admins.remove(userId);
_changes.emplace(userId, false);
}
}
ChannelAdminChanges::~ChannelAdminChanges() {
if (!_changes.empty()) {
2019-01-18 12:27:37 +00:00
if (const auto history = _channel->owner().historyLoaded(_channel)) {
2017-12-02 11:07:27 +00:00
history->applyGroupAdminChanges(_changes);
}
}
}
} // namespace Data