api_hash.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include "api/api_hash.h"
  8. #include "data/data_document.h"
  9. #include "data/data_session.h"
  10. #include "data/stickers/data_stickers.h"
  11. #include "main/main_session.h"
  12. namespace Api {
  13. namespace {
  14. [[nodiscard]] uint64 CountDocumentVectorHash(
  15. const QVector<DocumentData*> vector) {
  16. auto result = HashInit();
  17. for (const auto document : vector) {
  18. HashUpdate(result, document->id);
  19. }
  20. return HashFinalize(result);
  21. }
  22. [[nodiscard]] uint64 CountSpecialStickerSetHash(
  23. not_null<Main::Session*> session,
  24. uint64 setId) {
  25. const auto &sets = session->data().stickers().sets();
  26. const auto it = sets.find(setId);
  27. if (it != sets.cend()) {
  28. return CountDocumentVectorHash(it->second->stickers);
  29. }
  30. return 0;
  31. }
  32. [[nodiscard]] uint64 CountStickersOrderHash(
  33. not_null<Main::Session*> session,
  34. const Data::StickersSetsOrder &order,
  35. bool checkOutdatedInfo) {
  36. using Flag = Data::StickersSetFlag;
  37. auto result = HashInit();
  38. bool foundOutdated = false;
  39. const auto &sets = session->data().stickers().sets();
  40. for (auto i = order.cbegin(), e = order.cend(); i != e; ++i) {
  41. auto it = sets.find(*i);
  42. if (it != sets.cend()) {
  43. const auto set = it->second.get();
  44. if (set->id == Data::Stickers::DefaultSetId) {
  45. foundOutdated = true;
  46. } else if (!(set->flags & Flag::Special)
  47. && !(set->flags & Flag::Archived)) {
  48. HashUpdate(result, set->hash);
  49. }
  50. }
  51. }
  52. return (!checkOutdatedInfo || !foundOutdated)
  53. ? HashFinalize(result)
  54. : 0;
  55. }
  56. [[nodiscard]] uint64 CountFeaturedHash(
  57. not_null<Main::Session*> session,
  58. const Data::StickersSetsOrder &order) {
  59. auto result = HashInit();
  60. const auto &sets = session->data().stickers().sets();
  61. for (const auto setId : order) {
  62. HashUpdate(result, setId);
  63. const auto it = sets.find(setId);
  64. if (it != sets.cend()
  65. && (it->second->flags & Data::StickersSetFlag::Unread)) {
  66. HashUpdate(result, 1);
  67. }
  68. }
  69. return HashFinalize(result);
  70. }
  71. } // namespace
  72. uint64 CountStickersHash(
  73. not_null<Main::Session*> session,
  74. bool checkOutdatedInfo) {
  75. return CountStickersOrderHash(
  76. session,
  77. session->data().stickers().setsOrder(),
  78. checkOutdatedInfo);
  79. }
  80. uint64 CountMasksHash(
  81. not_null<Main::Session*> session,
  82. bool checkOutdatedInfo) {
  83. return CountStickersOrderHash(
  84. session,
  85. session->data().stickers().maskSetsOrder(),
  86. checkOutdatedInfo);
  87. }
  88. uint64 CountCustomEmojiHash(
  89. not_null<Main::Session*> session,
  90. bool checkOutdatedInfo) {
  91. return CountStickersOrderHash(
  92. session,
  93. session->data().stickers().emojiSetsOrder(),
  94. checkOutdatedInfo);
  95. }
  96. uint64 CountRecentStickersHash(
  97. not_null<Main::Session*> session,
  98. bool attached) {
  99. return CountSpecialStickerSetHash(
  100. session,
  101. attached
  102. ? Data::Stickers::CloudRecentAttachedSetId
  103. : Data::Stickers::CloudRecentSetId);
  104. }
  105. uint64 CountFavedStickersHash(not_null<Main::Session*> session) {
  106. return CountSpecialStickerSetHash(session, Data::Stickers::FavedSetId);
  107. }
  108. uint64 CountFeaturedStickersHash(not_null<Main::Session*> session) {
  109. return CountFeaturedHash(
  110. session,
  111. session->data().stickers().featuredSetsOrder());
  112. }
  113. uint64 CountFeaturedEmojiHash(not_null<Main::Session*> session) {
  114. return CountFeaturedHash(
  115. session,
  116. session->data().stickers().featuredEmojiSetsOrder());
  117. }
  118. uint64 CountSavedGifsHash(not_null<Main::Session*> session) {
  119. return CountDocumentVectorHash(session->data().stickers().savedGifs());
  120. }
  121. } // namespace Api