edit_peer_requests_box.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_box.h"
  9. #include "base/weak_ptr.h"
  10. #include "mtproto/sender.h"
  11. namespace Window {
  12. class SessionNavigation;
  13. } // namespace Window
  14. namespace Ui {
  15. class RippleAnimation;
  16. } // namespace Ui
  17. class RequestsBoxController final
  18. : public PeerListController
  19. , public base::has_weak_ptr {
  20. public:
  21. RequestsBoxController(
  22. not_null<Window::SessionNavigation*> navigation,
  23. not_null<PeerData*> peer);
  24. ~RequestsBoxController();
  25. static void Start(
  26. not_null<Window::SessionNavigation*> navigation,
  27. not_null<PeerData*> peer);
  28. Main::Session &session() const override;
  29. void prepare() override;
  30. void rowClicked(not_null<PeerListRow*> row) override;
  31. void rowElementClicked(
  32. not_null<PeerListRow*> row,
  33. int element) override;
  34. void loadMoreRows() override;
  35. std::unique_ptr<PeerListRow> createSearchRow(
  36. not_null<PeerData*> peer) override;
  37. std::unique_ptr<PeerListRow> createRestoredRow(
  38. not_null<PeerData*> peer) override;
  39. std::unique_ptr<PeerListState> saveState() const override;
  40. void restoreState(std::unique_ptr<PeerListState> state) override;
  41. private:
  42. class RowHelper;
  43. struct SavedState : SavedStateBase {
  44. using SearchStateBase = PeerListSearchController::SavedStateBase;
  45. std::unique_ptr<SearchStateBase> searchState;
  46. base::flat_map<not_null<UserData*>, TimeId> dates;
  47. TimeId offsetDate = 0;
  48. UserData *offsetUser = nullptr;
  49. bool allLoaded = false;
  50. bool wasLoading = false;
  51. };
  52. static std::unique_ptr<PeerListSearchController> CreateSearchController(
  53. not_null<PeerData*> peer);
  54. [[nodiscard]] std::unique_ptr<PeerListRow> createRow(
  55. not_null<UserData*> user,
  56. TimeId date = 0);
  57. void appendRow(not_null<UserData*> user, TimeId date);
  58. void refreshDescription();
  59. void processRequest(not_null<UserData*> user, bool approved);
  60. void subscribeToMigration();
  61. void migrate(not_null<ChatData*> chat, not_null<ChannelData*> channel);
  62. const not_null<Window::SessionNavigation*> _navigation;
  63. const std::unique_ptr<RowHelper> _helper;
  64. not_null<PeerData*> _peer;
  65. MTP::Sender _api;
  66. base::flat_map<not_null<UserData*>, TimeId> _dates;
  67. TimeId _offsetDate = 0;
  68. UserData *_offsetUser = nullptr;
  69. mtpRequestId _loadRequestId = 0;
  70. bool _allLoaded = false;
  71. };
  72. // Members, banned and restricted users server side search.
  73. class RequestsBoxSearchController final : public PeerListSearchController {
  74. public:
  75. RequestsBoxSearchController(not_null<PeerData*> peer);
  76. void searchQuery(const QString &query) override;
  77. bool isLoading() override;
  78. bool loadMoreRows() override;
  79. void removeFromCache(not_null<UserData*> user);
  80. [[nodiscard]] TimeId dateForUser(not_null<UserData*> user);
  81. std::unique_ptr<SavedStateBase> saveState() const override;
  82. void restoreState(std::unique_ptr<SavedStateBase> state) override;
  83. private:
  84. struct SavedState : SavedStateBase {
  85. QString query;
  86. TimeId offsetDate = 0;
  87. UserData *offsetUser = nullptr;
  88. bool allLoaded = false;
  89. bool wasLoading = false;
  90. };
  91. struct Item {
  92. not_null<UserData*> user;
  93. TimeId date = 0;
  94. };
  95. struct CacheEntry {
  96. std::vector<Item> items;
  97. int requestedCount = 0;
  98. };
  99. struct Query {
  100. QString text;
  101. TimeId offsetDate = 0;
  102. UserData *offsetUser = nullptr;
  103. };
  104. void searchOnServer();
  105. bool searchInCache();
  106. void searchDone(
  107. mtpRequestId requestId,
  108. const std::vector<Item> &items,
  109. int requestedCount);
  110. not_null<PeerData*> _peer;
  111. MTP::Sender _api;
  112. base::Timer _timer;
  113. QString _query;
  114. mtpRequestId _requestId = 0;
  115. TimeId _offsetDate = 0;
  116. UserData *_offsetUser = nullptr;
  117. bool _allLoaded = false;
  118. base::flat_map<QString, CacheEntry> _cache;
  119. base::flat_map<mtpRequestId, Query> _queries;
  120. base::flat_map<not_null<UserData*>, TimeId> _dates;
  121. };