FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tdesktop/Telegram/SourceFiles/data/data_folder.cpp at dev · dmitry/tdesktop · GitHub
dmitry
tdesktop
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
data
/
data_folder.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
426 lines (379 loc) · 10.3 KB
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
data
/
data_folder.cpp
Copy path
File metadata and controls
426 lines (379 loc) · 10.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/*
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
"
data/data_folder.h
"
#
include
"
data/data_session.h
"
#
include
"
data/data_channel.h
"
#
include
"
data/data_histories.h
"
#
include
"
data/data_changes.h
"
#
include
"
dialogs/dialogs_key.h
"
#
include
"
dialogs/ui/dialogs_layout.h
"
#
include
"
history/history.h
"
#
include
"
history/history_item.h
"
#
include
"
ui/painter.h
"
#
include
"
ui/text/text_options.h
"
#
include
"
ui/text/text_utilities.h
"
#
include
"
lang/lang_keys.h
"
#
include
"
storage/storage_facade.h
"
#
include
"
core/application.h
"
#
include
"
core/core_settings.h
"
#
include
"
main/main_account.h
"
#
include
"
main/main_session.h
"
#
include
"
mtproto/mtproto_config.h
"
#
include
"
apiwrap.h
"
#
include
"
mainwidget.h
"
#
include
"
styles/style_dialogs.h
"
namespace
Data
{
namespace
{
constexpr
auto
kLoadedChatsMinCount
=
20
;
constexpr
auto
kShowChatNamesCount
=
8
;
[[nodiscard]]
TextWithEntities
ComposeFolderListEntryText
(
not_null<Folder*> folder) {
const
auto
&list = folder->
lastHistories
();
if
(list.
empty
()) {
if
(
const
auto
storiesUnread = folder->
storiesUnreadCount
()) {
return
{
tr::lng_contacts_stories_status_new
(
tr::now,
lt_count,
storiesUnread),
};
}
else
if
(
const
auto
storiesCount = folder->
storiesCount
()) {
return
{
tr::lng_contacts_stories_status
(
tr::now,
lt_count,
storiesCount),
};
}
return
{};
}
const
auto
count =
std::max
(
int
(list.
size
()),
folder->
chatsList
()->
fullSize
().
current
());
const
auto
throwAwayLastName = (list.
size
() >
1
)
&& (count == list.
size
() +
1
);
auto
&&peers =
ranges::views::all
(
list
) |
ranges::views::take
(
list.
size
() - (throwAwayLastName ?
1
:
0
)
);
const
auto
wrapName = [](not_null<History*> history) {
const
auto
name = history->
peer
->
name
();
return
st::wrap_rtl
(TextWithEntities{
.
text
= name,
.
entities
= (history->
chatListBadgesState
().
unread
? EntitiesInText{
{ EntityType::Semibold,
0
,
int
(name.
size
()),
QString
() },
{ EntityType::Colorized,
0
,
int
(name.
size
()),
QString
() },
}
: EntitiesInText{}),
});
};
const
auto
shown =
int
(peers.
size
());
const
auto
accumulated = [&] {
Expects
(shown >
0
);
auto
i = peers.
begin
();
auto
result =
wrapName
(*i);
for
(++i; i != peers.
end
(); ++i) {
result =
tr::lng_archived_last_list
(
tr::now,
lt_accumulated,
result,
lt_chat,
wrapName
(*i),
tr::marked);
}
return
result;
}();
return
(shown < count)
?
tr::lng_archived_last
(
tr::now,
lt_count,
(count - shown),
lt_chats,
accumulated,
tr::marked)
: accumulated;
}
}
//
namespace
Folder::Folder
(not_null<Session*> owner, FolderId id)
: Entry(owner, Type::Folder)
, _id(id)
, _chatsList(
&owner->
session
(),
FilterId(),
owner->maxPinnedChatsLimitValue(
this
))
, _name(tr::lng_archived_name(tr::now)) {
indexNameParts
();
session
().
changes
().
peerUpdates
(
PeerUpdate::Flag::Name
) |
rpl::filter
([=](
const
PeerUpdate &update) {
return
ranges::contains
(_lastHistories, update.
peer
, &History::peer);
}) |
rpl::on_next
([=] {
++_chatListViewVersion;
updateChatListEntryPostponed
();
}, _lifetime);
_chatsList.
setAllAreMuted
(
true
);
_chatsList.
unreadStateChanges
(
) |
rpl::filter
([=] {
return
inChatList
();
}) |
rpl::on_next
([=](
const
Dialogs::UnreadState &old) {
++_chatListViewVersion;
notifyUnreadStateChange
(old);
}, _lifetime);
_chatsList.
fullSize
().
changes
(
) |
rpl::on_next
([=] {
updateChatListEntryPostponed
();
}, _lifetime);
}
FolderId
Folder::id
()
const
{
return
_id;
}
void
Folder::indexNameParts
() {
//
We don't want archive to be filtered in the chats list.
}
void
Folder::registerOne
(not_null<History*> history) {
if
(_chatsList.
indexed
()->
size
() ==
1
) {
updateChatListSortPosition
();
if
(!_chatsList.
cloudUnreadKnown
()) {
owner
().
histories
().
requestDialogEntry
(
this
);
}
}
else
{
updateChatListEntry
();
}
reorderLastHistories
();
}
void
Folder::unregisterOne
(not_null<History*> history) {
if
(_chatsList.
empty
()) {
updateChatListExistence
();
}
reorderLastHistories
();
}
int
Folder::chatListNameVersion
()
const
{
return
1
;
}
void
Folder::oneListMessageChanged
(HistoryItem *from, HistoryItem *to) {
if
(from || to) {
reorderLastHistories
();
}
}
void
Folder::reorderLastHistories
() {
//
We want first kShowChatNamesCount histories, by last message date.
const
auto
pred = [](not_null<History*> a, not_null<History*> b) {
const
auto
aItem = a->
chatListMessage
();
const
auto
bItem = b->
chatListMessage
();
const
auto
aDate = aItem ? aItem->
date
() :
TimeId
(
0
);
const
auto
bDate = bItem ? bItem->
date
() :
TimeId
(
0
);
return
aDate > bDate;
};
_lastHistories.
clear
();
_lastHistories.
reserve
(
kShowChatNamesCount
+
1
);
auto
&&histories =
ranges::views::all
(
*_chatsList.
indexed
()
) |
ranges::views::transform
([](not_null<Dialogs::Row*> row) {
return
row->
history
();
}) |
ranges::views::filter
([](History *history) {
return
(history !=
nullptr
);
});
auto
nonPinnedChecked =
0
;
for
(
const
auto
history : histories) {
const
auto
i =
ranges::upper_bound
(
_lastHistories,
not_null
(history),
pred);
if
(
size
(_lastHistories) <
kShowChatNamesCount
|| i !=
end
(_lastHistories)) {
_lastHistories.
insert
(i, history);
}
if
(
size
(_lastHistories) >
kShowChatNamesCount
) {
_lastHistories.
pop_back
();
}
if
(!history->
isPinnedDialog
(
FilterId
())
&& ++nonPinnedChecked >=
kShowChatNamesCount
) {
break
;
}
}
++_chatListViewVersion;
updateChatListEntry
();
}
not_null<Dialogs::MainList*>
Folder::chatsList
() {
return
&_chatsList;
}
void
Folder::clearChatsList
() {
_chatsList.
clear
();
}
void
Folder::chatListPreloadData
() {
}
void
Folder::paintUserpic
(
Painter &p,
Ui::PeerUserpicView &view,
const
Dialogs::Ui::PaintContext &context)
const
{
paintUserpic
(
p,
context.
st
->
padding
.
left
(),
context.
st
->
padding
.
top
(),
context.
st
->
photoSize
);
}
void
Folder::paintUserpic
(Painter &p,
int
x,
int
y,
int
size)
const
{
paintUserpic
(p, x, y, size,
nullptr
,
nullptr
);
}
void
Folder::paintUserpic
(
Painter &p,
int
x,
int
y,
int
size,
const
style::color &bg,
const
style::color &fg)
const
{
paintUserpic
(p, x, y, size, &bg, &fg);
}
void
Folder::paintUserpic
(
Painter &p,
int
x,
int
y,
int
size,
const
style::color *overrideBg,
const
style::color *overrideFg)
const
{
p.
setPen
(Qt::NoPen);
p.
setBrush
(overrideBg ? *overrideBg : st::historyPeerArchiveUserpicBg);
{
PainterHighQualityEnabler
hq
(p);
p.
drawEllipse
(x, y, size, size);
}
if
(size == st::defaultDialogRow.
photoSize
) {
const
auto
rect = QRect{ x, y, size, size };
if
(overrideFg) {
st::dialogsArchiveUserpic.
paintInCenter
(
p,
rect,
(*overrideFg)->
c
);
}
else
{
st::dialogsArchiveUserpic.
paintInCenter
(p, rect);
}
}
else
{
p.
save
();
const
auto
ratio = size /
float64
(st::defaultDialogRow.
photoSize
);
p.
translate
(x + size /
2
., y + size /
2
.);
p.
scale
(ratio, ratio);
const
auto
skip = st::defaultDialogRow.
photoSize
;
const
auto
rect = QRect{ -skip, -skip,
2
* skip,
2
* skip };
if
(overrideFg) {
st::dialogsArchiveUserpic.
paintInCenter
(
p,
rect,
(*overrideFg)->
c
);
}
else
{
st::dialogsArchiveUserpic.
paintInCenter
(p, rect);
}
p.
restore
();
}
}
const
std::vector<not_null<History*>> &
Folder::lastHistories
()
const
{
return
_lastHistories;
}
void
Folder::validateListEntryCache
() {
if
(_listEntryCacheVersion == _chatListViewVersion) {
return
;
}
_listEntryCacheVersion = _chatListViewVersion;
_listEntryCache.
setMarkedText
(
st::dialogsTextStyle,
ComposeFolderListEntryText
(
this
),
//
Use rich options as long as the entry text does not have user text.
Ui::ItemTextDefaultOptions
());
}
void
Folder::updateStoriesCount
(
int
count,
int
unread) {
if
(_storiesCount == count && _storiesUnreadCount == unread) {
return
;
}
const
auto
limit = (
1
<<
16
) -
1
;
const
auto
was = (_storiesCount >
0
);
_storiesCount =
std::min
(count, limit);
_storiesUnreadCount =
std::min
(unread, limit);
const
auto
now = (_storiesCount >
0
);
if
(was == now) {
updateChatListEntryPostponed
();
}
else
if
(now) {
updateChatListSortPosition
();
}
else
{
updateChatListExistence
();
}
++_chatListViewVersion;
}
int
Folder::storiesCount
()
const
{
return
_storiesCount;
}
int
Folder::storiesUnreadCount
()
const
{
return
_storiesUnreadCount;
}
TimeId
Folder::adjustedChatListTimeId
()
const
{
return
chatListTimeId
();
}
void
Folder::applyDialog
(
const
MTPDdialogFolder &data) {
_chatsList.
updateCloudUnread
(data);
if
(
const
auto
peerId =
peerFromMTP
(data.
vpeer
())) {
const
auto
history =
owner
().
history
(peerId);
const
auto
fullId =
FullMsgId
(peerId, data.
vtop_message
().
v
);
history->
setFolder
(
this
,
owner
().
message
(fullId));
}
else
{
_chatsList.
clear
();
updateChatListExistence
();
}
if
(_chatsList.
indexed
()->
size
() <
kLoadedChatsMinCount
) {
session
().
api
().
requestDialogs
(
this
);
}
}
void
Folder::applyPinnedUpdate
(
const
MTPDupdateDialogPinned &data) {
const
auto
folderId = data.
vfolder_id
().
value_or_empty
();
if
(folderId !=
0
) {
LOG
((
"
API Error: Nested folders detected.
"
));
}
owner
().
setChatPinned
(
this
,
FilterId
(), data.
is_pinned
());
}
int
Folder::fixedOnTopIndex
()
const
{
return
kArchiveFixOnTopIndex
;
}
bool
Folder::shouldBeInChatList
()
const
{
return
!_chatsList.
empty
() || (_storiesCount >
0
);
}
Dialogs::UnreadState
Folder::chatListUnreadState
()
const
{
return
_chatsList.
unreadState
();
}
Dialogs::BadgesState
Folder::chatListBadgesState
()
const
{
auto
result =
Dialogs::BadgesForUnread
(
chatListUnreadState
(),
Dialogs::CountInBadge::Chats,
Dialogs::IncludeInBadge::All);
result.
unreadMuted
= result.
mentionMuted
= result.
reactionMuted
= result.
pollMuted
=
true
;
if
(result.
unread
&& !result.
unreadCounter
) {
result.
unreadCounter
=
1
;
}
return
result;
}
HistoryItem *
Folder::chatListMessage
()
const
{
return
nullptr
;
}
bool
Folder::chatListMessageKnown
()
const
{
return
true
;
}
const
QString &
Folder::chatListName
()
const
{
return
_name;
}
const
base::flat_set<QString> &
Folder::chatListNameWords
()
const
{
return
_nameWords;
}
const
base::flat_set<QChar> &
Folder::chatListFirstLetters
()
const
{
return
_nameFirstLetters;
}
const
QString &
Folder::chatListNameSortKey
()
const
{
static
const
auto
empty =
QString
();
return
empty;
}
}
//
namespace Data
Back
|
FazBrowse Home
|
New Git URL