data_channel_admins.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "data/data_channel_admins.h"
  8. #include "history/history.h"
  9. #include "data/data_channel.h"
  10. #include "data/data_session.h"
  11. #include "main/main_session.h"
  12. namespace Data {
  13. ChannelAdminChanges::ChannelAdminChanges(not_null<ChannelData*> channel)
  14. : _channel(channel)
  15. , _admins(_channel->mgInfo->admins) {
  16. }
  17. void ChannelAdminChanges::add(UserId userId, const QString &rank) {
  18. const auto i = _admins.find(userId);
  19. if (i == end(_admins) || i->second != rank) {
  20. _admins[userId] = rank;
  21. _changes.emplace(userId);
  22. }
  23. }
  24. void ChannelAdminChanges::remove(UserId userId) {
  25. if (_admins.contains(userId)) {
  26. _admins.remove(userId);
  27. _changes.emplace(userId);
  28. }
  29. }
  30. ChannelAdminChanges::~ChannelAdminChanges() {
  31. if (_changes.size() > 1
  32. || (!_changes.empty()
  33. && _changes.front() != _channel->session().userId())) {
  34. if (const auto history = _channel->owner().historyLoaded(_channel)) {
  35. history->applyGroupAdminChanges(_changes);
  36. }
  37. }
  38. }
  39. } // namespace Data