2017-12-02 11:07:27 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-02 11:07:27 +00:00
|
|
|
|
2018-01-03 10:23:14 +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"
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
2019-01-18 12:27:37 +00:00
|
|
|
#include "data/data_session.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2017-12-02 11:07:27 +00:00
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
ChannelAdminChanges::ChannelAdminChanges(not_null<ChannelData*> channel)
|
|
|
|
: _channel(channel)
|
|
|
|
, _admins(_channel->mgInfo->admins) {
|
|
|
|
}
|
|
|
|
|
2019-07-19 13:34:09 +00:00
|
|
|
void ChannelAdminChanges::add(UserId userId, const QString &rank) {
|
|
|
|
const auto i = _admins.find(userId);
|
|
|
|
if (i == end(_admins) || i->second != rank) {
|
|
|
|
_admins[userId] = rank;
|
|
|
|
_changes.emplace(userId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelAdminChanges::remove(UserId userId) {
|
|
|
|
if (_admins.contains(userId)) {
|
2017-12-02 11:07:27 +00:00
|
|
|
_admins.remove(userId);
|
2019-07-19 13:34:09 +00:00
|
|
|
_changes.emplace(userId);
|
2017-12-02 11:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChannelAdminChanges::~ChannelAdminChanges() {
|
2019-07-19 13:34:09 +00:00
|
|
|
if (_changes.size() > 1
|
|
|
|
|| (!_changes.empty()
|
|
|
|
&& _changes.front() != _channel->session().userId())) {
|
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
|