data_web_page.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 "base/flags.h"
  9. #include "data/data_photo.h"
  10. #include "data/data_document.h"
  11. class ChannelData;
  12. namespace Data {
  13. class Session;
  14. struct UniqueGift;
  15. } // namespace Data
  16. namespace Iv {
  17. class Data;
  18. } // namespace Iv
  19. enum class WebPageType : uint8 {
  20. None,
  21. Message,
  22. Album,
  23. Group,
  24. GroupWithRequest,
  25. GroupBoost,
  26. Channel,
  27. ChannelWithRequest,
  28. ChannelBoost,
  29. Giftcode,
  30. Photo,
  31. Video,
  32. Document,
  33. User,
  34. Bot,
  35. Profile,
  36. BotApp,
  37. WallPaper,
  38. Theme,
  39. Story,
  40. StickerSet,
  41. Article,
  42. ArticleWithIV,
  43. VoiceChat,
  44. Livestream,
  45. Factcheck,
  46. };
  47. [[nodiscard]] WebPageType ParseWebPageType(const MTPDwebPage &type);
  48. [[nodiscard]] bool IgnoreIv(WebPageType type);
  49. struct WebPageCollage {
  50. using Item = std::variant<PhotoData*, DocumentData*>;
  51. WebPageCollage() = default;
  52. explicit WebPageCollage(
  53. not_null<Data::Session*> owner,
  54. const MTPDwebPage &data);
  55. std::vector<Item> items;
  56. };
  57. struct WebPageStickerSet {
  58. WebPageStickerSet() = default;
  59. std::vector<not_null<DocumentData*>> items;
  60. bool isEmoji = false;
  61. bool isTextColor = false;
  62. };
  63. struct WebPageData {
  64. WebPageData(not_null<Data::Session*> owner, const WebPageId &id);
  65. ~WebPageData();
  66. [[nodiscard]] Data::Session &owner() const;
  67. [[nodiscard]] Main::Session &session() const;
  68. bool applyChanges(
  69. WebPageType newType,
  70. const QString &newUrl,
  71. const QString &newDisplayUrl,
  72. const QString &newSiteName,
  73. const QString &newTitle,
  74. const TextWithEntities &newDescription,
  75. FullStoryId newStoryId,
  76. PhotoData *newPhoto,
  77. DocumentData *newDocument,
  78. WebPageCollage &&newCollage,
  79. std::unique_ptr<Iv::Data> newIv,
  80. std::unique_ptr<WebPageStickerSet> newStickerSet,
  81. std::shared_ptr<Data::UniqueGift> newUniqueGift,
  82. int newDuration,
  83. const QString &newAuthor,
  84. bool newHasLargeMedia,
  85. bool newPhotoIsVideoCover,
  86. int newPendingTill);
  87. static void ApplyChanges(
  88. not_null<Main::Session*> session,
  89. ChannelData *channel,
  90. const MTPmessages_Messages &result);
  91. [[nodiscard]] QString displayedSiteName() const;
  92. [[nodiscard]] TimeId extractVideoTimestamp() const;
  93. [[nodiscard]] bool computeDefaultSmallMedia() const;
  94. [[nodiscard]] bool suggestEnlargePhoto() const;
  95. const WebPageId id = 0;
  96. WebPageType type = WebPageType::None;
  97. QString url;
  98. QString displayUrl;
  99. QString siteName;
  100. QString title;
  101. TextWithEntities description;
  102. FullStoryId storyId;
  103. QString author;
  104. PhotoData *photo = nullptr;
  105. DocumentData *document = nullptr;
  106. WebPageCollage collage;
  107. std::unique_ptr<Iv::Data> iv;
  108. std::unique_ptr<WebPageStickerSet> stickerSet;
  109. std::shared_ptr<Data::UniqueGift> uniqueGift;
  110. int duration = 0;
  111. TimeId pendingTill = 0;
  112. uint32 version : 29 = 0;
  113. uint32 photoIsVideoCover : 1 = 0;
  114. uint32 hasLargeMedia : 1 = 0;
  115. uint32 failed : 1 = 0;
  116. private:
  117. void replaceDocumentGoodThumbnail();
  118. const not_null<Data::Session*> _owner;
  119. };