api_blocked_peers.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "mtproto/sender.h"
  9. class ApiWrap;
  10. namespace Main {
  11. class Session;
  12. } // namespace Main
  13. namespace Api {
  14. class BlockedPeers final {
  15. public:
  16. struct Slice {
  17. struct Item {
  18. PeerId id;
  19. TimeId date = 0;
  20. bool operator==(const Item &other) const;
  21. bool operator!=(const Item &other) const;
  22. };
  23. QVector<Item> list;
  24. int total = 0;
  25. bool operator==(const Slice &other) const;
  26. bool operator!=(const Slice &other) const;
  27. };
  28. explicit BlockedPeers(not_null<ApiWrap*> api);
  29. void reload();
  30. rpl::producer<Slice> slice();
  31. void request(int offset, Fn<void(Slice)> done);
  32. void block(not_null<PeerData*> peer);
  33. void unblock(
  34. not_null<PeerData*> peer,
  35. Fn<void(bool success)> done = nullptr,
  36. bool force = false);
  37. private:
  38. struct Request {
  39. std::vector<Fn<void(bool success)>> callbacks;
  40. mtpRequestId requestId = 0;
  41. bool blocking = false;
  42. };
  43. [[nodiscard]] bool blockAlreadySent(
  44. not_null<PeerData*> peer,
  45. bool blocking,
  46. Fn<void(bool success)> done = nullptr);
  47. const not_null<Main::Session*> _session;
  48. MTP::Sender _api;
  49. base::flat_map<not_null<PeerData*>, Request> _blockRequests;
  50. mtpRequestId _requestId = 0;
  51. std::optional<Slice> _slice;
  52. rpl::event_stream<Slice> _changes;
  53. };
  54. } // namespace Api