data_star_gift.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. namespace Data {
  9. struct UniqueGiftAttribute {
  10. QString name;
  11. int rarityPermille = 0;
  12. };
  13. struct UniqueGiftModel : UniqueGiftAttribute {
  14. not_null<DocumentData*> document;
  15. };
  16. struct UniqueGiftPattern : UniqueGiftAttribute {
  17. not_null<DocumentData*> document;
  18. };
  19. struct UniqueGiftBackdrop : UniqueGiftAttribute {
  20. QColor centerColor;
  21. QColor edgeColor;
  22. QColor patternColor;
  23. QColor textColor;
  24. };
  25. struct UniqueGiftOriginalDetails {
  26. PeerId senderId = 0;
  27. PeerId recipientId = 0;
  28. TimeId date = 0;
  29. TextWithEntities message;
  30. };
  31. struct UniqueGift {
  32. CollectibleId id = 0;
  33. QString slug;
  34. QString title;
  35. QString ownerAddress;
  36. QString ownerName;
  37. PeerId ownerId = 0;
  38. int number = 0;
  39. int starsForTransfer = -1;
  40. TimeId exportAt = 0;
  41. UniqueGiftModel model;
  42. UniqueGiftPattern pattern;
  43. UniqueGiftBackdrop backdrop;
  44. UniqueGiftOriginalDetails originalDetails;
  45. };
  46. [[nodiscard]] inline QString UniqueGiftName(const UniqueGift &gift) {
  47. return gift.title + u" #"_q + QString::number(gift.number);
  48. }
  49. struct StarGift {
  50. uint64 id = 0;
  51. std::shared_ptr<UniqueGift> unique;
  52. int64 stars = 0;
  53. int64 starsConverted = 0;
  54. int64 starsToUpgrade = 0;
  55. not_null<DocumentData*> document;
  56. int limitedLeft = 0;
  57. int limitedCount = 0;
  58. TimeId firstSaleDate = 0;
  59. TimeId lastSaleDate = 0;
  60. bool upgradable = false;
  61. bool birthday = false;
  62. bool soldOut = false;
  63. friend inline bool operator==(
  64. const StarGift &,
  65. const StarGift &) = default;
  66. };
  67. class SavedStarGiftId {
  68. public:
  69. [[nodiscard]] static SavedStarGiftId User(MsgId messageId) {
  70. auto result = SavedStarGiftId();
  71. result.entityId = uint64(messageId.bare);
  72. return result;
  73. }
  74. [[nodiscard]] static SavedStarGiftId Chat(
  75. not_null<PeerData*> peer,
  76. uint64 savedId) {
  77. auto result = SavedStarGiftId();
  78. result.peer = peer;
  79. result.entityId = savedId;
  80. return result;
  81. }
  82. [[nodiscard]] bool isUser() const {
  83. return !peer;
  84. }
  85. [[nodiscard]] bool isChat() const {
  86. return peer != nullptr;
  87. }
  88. [[nodiscard]] MsgId userMessageId() const {
  89. return peer ? MsgId(0) : MsgId(entityId);
  90. }
  91. [[nodiscard]] PeerData *chat() const {
  92. return peer;
  93. }
  94. [[nodiscard]] uint64 chatSavedId() const {
  95. return peer ? entityId : 0;
  96. }
  97. explicit operator bool() const {
  98. return entityId != 0;
  99. }
  100. friend inline bool operator==(
  101. const SavedStarGiftId &a,
  102. const SavedStarGiftId &b) = default;
  103. private:
  104. PeerData *peer = nullptr;
  105. uint64 entityId = 0;
  106. };
  107. struct SavedStarGift {
  108. StarGift info;
  109. SavedStarGiftId manageId;
  110. TextWithEntities message;
  111. int64 starsConverted = 0;
  112. int64 starsUpgradedBySender = 0;
  113. PeerId fromId = 0;
  114. TimeId date = 0;
  115. bool upgradable = false;
  116. bool anonymous = false;
  117. bool pinned = false;
  118. bool hidden = false;
  119. bool mine = false;
  120. };
  121. } // namespace Data