send_as_peers.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. class PeerData;
  9. namespace Main {
  10. class Session;
  11. struct SendAsPeer {
  12. not_null<PeerData*> peer;
  13. bool premiumRequired = false;
  14. friend inline auto operator<=>(SendAsPeer, SendAsPeer) = default;
  15. };
  16. class SendAsPeers final {
  17. public:
  18. explicit SendAsPeers(not_null<Session*> session);
  19. bool shouldChoose(not_null<PeerData*> peer);
  20. void refresh(not_null<PeerData*> peer, bool force = false);
  21. [[nodiscard]] const std::vector<SendAsPeer> &list(
  22. not_null<PeerData*> peer) const;
  23. [[nodiscard]] rpl::producer<not_null<PeerData*>> updated() const;
  24. void saveChosen(not_null<PeerData*> peer, not_null<PeerData*> chosen);
  25. void setChosen(not_null<PeerData*> peer, PeerId chosenId);
  26. [[nodiscard]] PeerId chosen(not_null<PeerData*> peer) const;
  27. [[nodiscard]] const std::vector<not_null<PeerData*>> &paidReactionList(
  28. not_null<PeerData*> peer) const;
  29. // If !list(peer).empty() then the result will be from that list.
  30. [[nodiscard]] not_null<PeerData*> resolveChosen(
  31. not_null<PeerData*> peer) const;
  32. [[nodiscard]] static not_null<PeerData*> ResolveChosen(
  33. not_null<PeerData*> peer,
  34. const std::vector<SendAsPeer> &list,
  35. PeerId chosen);
  36. private:
  37. void request(not_null<PeerData*> peer, bool forPaidReactions = false);
  38. const not_null<Session*> _session;
  39. const std::vector<SendAsPeer> _onlyMe;
  40. const std::vector<not_null<PeerData*>> _onlyMePaid;
  41. base::flat_map<not_null<PeerData*>, std::vector<SendAsPeer>> _lists;
  42. base::flat_map<not_null<PeerData*>, crl::time> _lastRequestTime;
  43. base::flat_map<not_null<PeerData*>, PeerId> _chosen;
  44. base::flat_map<
  45. not_null<PeerData*>,
  46. std::vector<not_null<PeerData*>>> _paidReactionLists;
  47. rpl::event_stream<not_null<PeerData*>> _updates;
  48. rpl::lifetime _lifetime;
  49. };
  50. } // namespace Main