-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Expand file tree
/
Copy pathapi_hash.cpp
More file actions
139 lines (121 loc) · 3.54 KB
/
Copy pathapi_hash.cpp
File metadata and controls
139 lines (121 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "api/api_hash.h"
#include "data/data_document.h"
#include "data/data_session.h"
#include "data/stickers/data_stickers.h"
#include "main/main_session.h"
namespace Api {
namespace {
[[nodiscard]] uint64 CountDocumentVectorHash(
const QVector<DocumentData*> vector) {
auto result = HashInit();
for (const auto document : vector) {
HashUpdate(result, document->id);
}
return HashFinalize(result);
}
[[nodiscard]] uint64 CountSpecialStickerSetHash(
not_null<Main::Session*> session,
uint64 setId) {
const auto &sets = session->data().stickers().sets();
const auto it = sets.find(setId);
if (it != sets.cend()) {
return CountDocumentVectorHash(it->second->stickers);
}
return 0;
}
[[nodiscard]] uint64 CountStickersOrderHash(
not_null<Main::Session*> session,
const Data::StickersSetsOrder &order,
bool checkOutdatedInfo) {
using Flag = Data::StickersSetFlag;
auto result = HashInit();
bool foundOutdated = false;
const auto &sets = session->data().stickers().sets();
for (auto i = order.cbegin(), e = order.cend(); i != e; ++i) {
auto it = sets.find(*i);
if (it != sets.cend()) {
const auto set = it->second.get();
if (set->id == Data::Stickers::DefaultSetId) {
foundOutdated = true;
} else if (!(set->flags & Flag::Special)
&& !(set->flags & Flag::Archived)) {
HashUpdate(result, set->hash);
}
}
}
return (!checkOutdatedInfo || !foundOutdated)
? HashFinalize(result)
: 0;
}
[[nodiscard]] uint64 CountFeaturedHash(
not_null<Main::Session*> session,
const Data::StickersSetsOrder &order) {
auto result = HashInit();
const auto &sets = session->data().stickers().sets();
for (const auto setId : order) {
HashUpdate(result, setId);
const auto it = sets.find(setId);
if (it != sets.cend()
&& (it->second->flags & Data::StickersSetFlag::Unread)) {
HashUpdate(result, 1);
}
}
return HashFinalize(result);
}
} // namespace
uint64 CountStickersHash(
not_null<Main::Session*> session,
bool checkOutdatedInfo) {
return CountStickersOrderHash(
session,
session->data().stickers().setsOrder(),
checkOutdatedInfo);
}
uint64 CountMasksHash(
not_null<Main::Session*> session,
bool checkOutdatedInfo) {
return CountStickersOrderHash(
session,
session->data().stickers().maskSetsOrder(),
checkOutdatedInfo);
}
uint64 CountCustomEmojiHash(
not_null<Main::Session*> session,
bool checkOutdatedInfo) {
return CountStickersOrderHash(
session,
session->data().stickers().emojiSetsOrder(),
checkOutdatedInfo);
}
uint64 CountRecentStickersHash(
not_null<Main::Session*> session,
bool attached) {
return CountSpecialStickerSetHash(
session,
attached
? Data::Stickers::CloudRecentAttachedSetId
: Data::Stickers::CloudRecentSetId);
}
uint64 CountFavedStickersHash(not_null<Main::Session*> session) {
return CountSpecialStickerSetHash(session, Data::Stickers::FavedSetId);
}
uint64 CountFeaturedStickersHash(not_null<Main::Session*> session) {
return CountFeaturedHash(
session,
session->data().stickers().featuredSetsOrder());
}
uint64 CountFeaturedEmojiHash(not_null<Main::Session*> session) {
return CountFeaturedHash(
session,
session->data().stickers().featuredEmojiSetsOrder());
}
uint64 CountSavedGifsHash(not_null<Main::Session*> session) {
return CountDocumentVectorHash(session->data().stickers().savedGifs());
}
} // namespace Api