data_stickers_set.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "data/data_cloud_file.h"
  9. class DocumentData;
  10. enum class StickerType : uchar;
  11. namespace Main {
  12. class Session;
  13. } // namespace Main
  14. namespace Data {
  15. class Session;
  16. using StickersSetsOrder = QList<uint64>;
  17. using SavedGifs = QVector<DocumentData*>;
  18. using StickersPack = QVector<DocumentData*>;
  19. enum class StickersType : uchar;
  20. class StickersSet;
  21. using StickersSets = base::flat_map<uint64, std::unique_ptr<StickersSet>>;
  22. class StickersSetThumbnailView final {
  23. public:
  24. explicit StickersSetThumbnailView(not_null<StickersSet*> owner);
  25. [[nodiscard]] not_null<StickersSet*> owner() const;
  26. void set(not_null<Main::Session*> session, QByteArray content);
  27. [[nodiscard]] Image *image() const;
  28. [[nodiscard]] QByteArray content() const;
  29. private:
  30. const not_null<StickersSet*> _owner;
  31. std::unique_ptr<Image> _image;
  32. QByteArray _content;
  33. };
  34. enum class StickersSetFlag : ushort {
  35. Installed = (1 << 0),
  36. Archived = (1 << 1),
  37. Masks = (1 << 2),
  38. Official = (1 << 3),
  39. NotLoaded = (1 << 4),
  40. Featured = (1 << 5),
  41. Unread = (1 << 6),
  42. Special = (1 << 7),
  43. Emoji = (1 << 9),
  44. TextColor = (1 << 10),
  45. ChannelStatus = (1 << 11),
  46. AmCreator = (1 << 12),
  47. };
  48. inline constexpr bool is_flag_type(StickersSetFlag) { return true; };
  49. using StickersSetFlags = base::flags<StickersSetFlag>;
  50. [[nodiscard]] StickersSetFlags ParseStickersSetFlags(
  51. const MTPDstickerSet &data);
  52. class StickersSet final {
  53. public:
  54. StickersSet(
  55. not_null<Data::Session*> owner,
  56. uint64 id,
  57. uint64 accessHash,
  58. uint64 hash,
  59. const QString &title,
  60. const QString &shortName,
  61. int count,
  62. StickersSetFlags flags,
  63. TimeId installDate);
  64. ~StickersSet();
  65. [[nodiscard]] Data::Session &owner() const;
  66. [[nodiscard]] Main::Session &session() const;
  67. [[nodiscard]] MTPInputStickerSet mtpInput() const;
  68. [[nodiscard]] StickerSetIdentifier identifier() const;
  69. [[nodiscard]] StickersType type() const;
  70. [[nodiscard]] bool textColor() const;
  71. [[nodiscard]] bool channelStatus() const;
  72. void setThumbnail(const ImageWithLocation &data, StickerType type);
  73. [[nodiscard]] bool hasThumbnail() const;
  74. [[nodiscard]] StickerType thumbnailType() const;
  75. [[nodiscard]] bool thumbnailLoading() const;
  76. [[nodiscard]] bool thumbnailFailed() const;
  77. void loadThumbnail();
  78. [[nodiscard]] const ImageLocation &thumbnailLocation() const;
  79. [[nodiscard]] Storage::Cache::Key thumbnailBigFileBaseCacheKey() const;
  80. [[nodiscard]] int thumbnailByteSize() const;
  81. [[nodiscard]] DocumentData *lookupThumbnailDocument() const;
  82. [[nodiscard]] std::shared_ptr<StickersSetThumbnailView> createThumbnailView();
  83. [[nodiscard]] std::shared_ptr<StickersSetThumbnailView> activeThumbnailView();
  84. uint64 id = 0;
  85. uint64 accessHash = 0;
  86. uint64 hash = 0;
  87. DocumentId thumbnailDocumentId = 0;
  88. QString title, shortName;
  89. int count = 0;
  90. int locked = 0;
  91. StickersSetFlags flags;
  92. private:
  93. StickerType _thumbnailType = {};
  94. public:
  95. TimeId installDate = 0;
  96. StickersPack covers;
  97. StickersPack stickers;
  98. std::vector<TimeId> dates;
  99. base::flat_map<EmojiPtr, StickersPack> emoji;
  100. private:
  101. const not_null<Data::Session*> _owner;
  102. CloudFile _thumbnail;
  103. std::weak_ptr<StickersSetThumbnailView> _thumbnailView;
  104. };
  105. [[nodiscard]] MTPInputStickerSet InputStickerSet(StickerSetIdentifier id);
  106. [[nodiscard]] StickerSetIdentifier FromInputSet(const MTPInputStickerSet &id);
  107. } // namespace Data