add_bot_to_chat_box.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #pragma once
  8. #include "boxes/peer_list_controllers.h"
  9. #include "data/data_chat_participant_status.h"
  10. class AddBotToGroupBoxController
  11. : public ChatsListBoxController
  12. , public base::has_weak_ptr {
  13. public:
  14. enum class Scope {
  15. None,
  16. GroupAdmin,
  17. ChannelAdmin,
  18. All,
  19. };
  20. static void Start(
  21. not_null<Window::SessionController*> controller,
  22. not_null<UserData*> bot,
  23. Scope scope = Scope::All,
  24. const QString &token = QString(),
  25. ChatAdminRights requestedRights = {});
  26. AddBotToGroupBoxController(
  27. not_null<Window::SessionController*> controller,
  28. not_null<UserData*> bot,
  29. Scope scope,
  30. const QString &token,
  31. ChatAdminRights requestedRights);
  32. Main::Session &session() const override;
  33. void rowClicked(not_null<PeerListRow*> row) override;
  34. protected:
  35. std::unique_ptr<Row> createRow(not_null<History*> history) override;
  36. void prepareViewHook() override;
  37. QString emptyBoxText() const override;
  38. private:
  39. [[nodiscard]] object_ptr<Ui::RpWidget> prepareAdminnedChats();
  40. [[nodiscard]] bool onlyAdminToGroup() const;
  41. [[nodiscard]] bool onlyAdminToChannel() const;
  42. bool needToCreateRow(not_null<PeerData*> peer) const;
  43. QString noResultsText() const;
  44. void updateLabels();
  45. void addBotToGroup(not_null<PeerData*> chat);
  46. void requestExistingRights(not_null<ChannelData*> channel);
  47. const not_null<Window::SessionController*> _controller;
  48. const not_null<UserData*> _bot;
  49. const Scope _scope = Scope::None;
  50. const QString _token;
  51. const ChatAdminRights _requestedRights;
  52. ChannelData *_existingRightsChannel = nullptr;
  53. mtpRequestId _existingRightsRequestId = 0;
  54. std::optional<ChatAdminRights> _existingRights;
  55. QString _existingRank;
  56. TimeId _promotedSince = 0;
  57. UserId _promotedBy = 0;
  58. rpl::event_stream<not_null<PeerData*>> _groups;
  59. rpl::event_stream<not_null<PeerData*>> _channels;
  60. bool _adminToGroup = false;
  61. bool _adminToChannel = false;
  62. bool _memberToGroup = false;
  63. };
  64. void AddBotToGroup(
  65. std::shared_ptr<Ui::Show> show,
  66. not_null<UserData*> bot,
  67. not_null<PeerData*> chat,
  68. const QString &startToken);