api_chat_links.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. class ApiWrap;
  9. namespace Api {
  10. struct ChatLink {
  11. QString link;
  12. QString title;
  13. TextWithEntities message;
  14. int clicks = 0;
  15. };
  16. struct ChatLinkUpdate {
  17. QString was;
  18. std::optional<ChatLink> now;
  19. };
  20. class ChatLinks final {
  21. public:
  22. explicit ChatLinks(not_null<ApiWrap*> api);
  23. using Link = ChatLink;
  24. using Update = ChatLinkUpdate;
  25. void create(
  26. const QString &title,
  27. const TextWithEntities &message,
  28. Fn<void(Link)> done = nullptr);
  29. void edit(
  30. const QString &link,
  31. const QString &title,
  32. const TextWithEntities &message,
  33. Fn<void(Link)> done = nullptr);
  34. void destroy(
  35. const QString &link,
  36. Fn<void()> done = nullptr);
  37. void preload();
  38. [[nodiscard]] const std::vector<ChatLink> &list() const;
  39. [[nodiscard]] bool loaded() const;
  40. [[nodiscard]] rpl::producer<> loadedUpdates() const;
  41. [[nodiscard]] rpl::producer<Update> updates() const;
  42. private:
  43. const not_null<ApiWrap*> _api;
  44. std::vector<Link> _list;
  45. rpl::event_stream<> _loadedUpdates;
  46. mtpRequestId _requestId = 0;
  47. bool _loaded = false;
  48. rpl::event_stream<Update> _updates;
  49. };
  50. } // namespace Api