top_peers.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. namespace Main {
  9. class Session;
  10. } // namespace Main
  11. namespace Data {
  12. enum class TopPeerType {
  13. Chat,
  14. BotApp,
  15. };
  16. class TopPeers final {
  17. public:
  18. TopPeers(not_null<Main::Session*> session, TopPeerType type);
  19. ~TopPeers();
  20. [[nodiscard]] std::vector<not_null<PeerData*>> list() const;
  21. [[nodiscard]] bool disabled() const;
  22. [[nodiscard]] rpl::producer<> updates() const;
  23. void remove(not_null<PeerData*> peer);
  24. void increment(not_null<PeerData*> peer, TimeId date);
  25. void reload();
  26. void toggleDisabled(bool disabled);
  27. [[nodiscard]] QByteArray serialize() const;
  28. void applyLocal(QByteArray serialized);
  29. private:
  30. struct TopPeer {
  31. not_null<PeerData*> peer;
  32. float64 rating = 0.;
  33. };
  34. void loadAfterChats();
  35. void request();
  36. [[nodiscard]] uint64 countHash() const;
  37. void updated();
  38. const not_null<Main::Session*> _session;
  39. const TopPeerType _type = {};
  40. std::vector<TopPeer> _list;
  41. rpl::event_stream<> _updates;
  42. crl::time _lastReceived = 0;
  43. TimeId _lastReceivedDate = 0;
  44. mtpRequestId _requestId = 0;
  45. bool _disabled = false;
  46. bool _received = false;
  47. };
  48. } // namespace Data