iv_instance.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "iv/iv_delegate.h"
  9. namespace Main {
  10. class Session;
  11. class SessionShow;
  12. } // namespace Main
  13. namespace Window {
  14. class SessionController;
  15. } // namespace Window
  16. namespace Iv {
  17. class Data;
  18. class Shown;
  19. class TonSite;
  20. class Instance final {
  21. public:
  22. explicit Instance(not_null<Delegate*> delegate);
  23. ~Instance();
  24. void show(
  25. not_null<Window::SessionController*> controller,
  26. not_null<Data*> data,
  27. QString hash);
  28. void show(
  29. std::shared_ptr<Main::SessionShow> show,
  30. not_null<Data*> data,
  31. QString hash);
  32. void show(
  33. not_null<Main::Session*> session,
  34. not_null<Data*> data,
  35. QString hash);
  36. void openWithIvPreferred(
  37. not_null<Window::SessionController*> controller,
  38. QString uri,
  39. QVariant context = {});
  40. void openWithIvPreferred(
  41. not_null<Main::Session*> session,
  42. QString uri,
  43. QVariant context = {});
  44. void showTonSite(
  45. const QString &uri,
  46. QVariant context = {});
  47. [[nodiscard]] bool hasActiveWindow(
  48. not_null<Main::Session*> session) const;
  49. bool closeActive();
  50. bool minimizeActive();
  51. void closeAll();
  52. [[nodiscard]] rpl::lifetime &lifetime();
  53. private:
  54. struct FullResult {
  55. crl::time lastRequestedAt = 0;
  56. WebPageData *page = nullptr;
  57. int32 hash = 0;
  58. };
  59. void processOpenChannel(const QString &context);
  60. void processJoinChannel(const QString &context);
  61. void requestFull(not_null<Main::Session*> session, const QString &id);
  62. void trackSession(not_null<Main::Session*> session);
  63. WebPageData *processReceivedPage(
  64. not_null<Main::Session*> session,
  65. const QString &url,
  66. const MTPmessages_WebPage &result);
  67. const not_null<Delegate*> _delegate;
  68. std::unique_ptr<Shown> _shown;
  69. Main::Session *_shownSession = nullptr;
  70. base::flat_set<not_null<Main::Session*>> _tracking;
  71. base::flat_map<
  72. not_null<Main::Session*>,
  73. base::flat_set<not_null<ChannelData*>>> _joining;
  74. base::flat_map<
  75. not_null<Main::Session*>,
  76. base::flat_map<QString, FullResult>> _fullRequested;
  77. base::flat_map<
  78. not_null<Main::Session*>,
  79. base::flat_map<QString, WebPageData*>> _ivCache;
  80. Main::Session *_ivRequestSession = nullptr;
  81. QString _ivRequestUri;
  82. mtpRequestId _ivRequestId = 0;
  83. std::unique_ptr<TonSite> _tonSite;
  84. rpl::lifetime _lifetime;
  85. };
  86. [[nodiscard]] bool PreferForUri(const QString &uri);
  87. } // namespace Iv