FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tdesktop/Telegram/SourceFiles/menu/menu_sponsored.cpp at dev · dmitry/tdesktop · GitHub
dmitry
/
tdesktop
Public
forked from
telegramdesktop/tdesktop
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
menu
/
menu_sponsored.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
515 lines (491 loc) · 14.7 KB
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
menu
/
menu_sponsored.cpp
Copy path
File metadata and controls
515 lines (491 loc) · 14.7 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
/*
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
"
menu/menu_sponsored.h
"
#
include
"
boxes/premium_preview_box.h
"
#
include
"
chat_helpers/compose/compose_show.h
"
#
include
"
core/ui_integration.h
"
//
TextContext
#
include
"
data/components/sponsored_messages.h
"
#
include
"
data/data_premium_limits.h
"
#
include
"
data/data_session.h
"
#
include
"
data/stickers/data_custom_emoji.h
"
#
include
"
history/history.h
"
#
include
"
lang/lang_keys.h
"
#
include
"
main/main_session.h
"
#
include
"
ui/boxes/report_box_graphics.h
"
//
AddReportOptionButton.
#
include
"
ui/layers/generic_box.h
"
#
include
"
ui/painter.h
"
#
include
"
ui/rect.h
"
#
include
"
ui/text/text_utilities.h
"
#
include
"
ui/toast/toast.h
"
#
include
"
ui/vertical_list.h
"
#
include
"
ui/widgets/buttons.h
"
#
include
"
ui/widgets/menu/menu_add_action_callback.h
"
#
include
"
ui/widgets/menu/menu_add_action_callback_factory.h
"
#
include
"
ui/widgets/menu/menu_multiline_action.h
"
#
include
"
ui/widgets/popup_menu.h
"
#
include
"
styles/style_channel_earn.h
"
#
include
"
styles/style_chat.h
"
#
include
"
styles/style_info.h
"
#
include
"
styles/style_layers.h
"
#
include
"
styles/style_media_view.h
"
#
include
"
styles/style_menu_icons.h
"
#
include
"
styles/style_premium.h
"
#
include
"
styles/style_settings.h
"
namespace
Menu
{
namespace
{
[[nodiscard]]
SponsoredPhrases
PhrasesForMessage
(FullMsgId fullId) {
return
peerIsChannel
(fullId.
peer
)
? SponsoredPhrases::Channel
: SponsoredPhrases::Bot;
}
void
AboutBox
(
not_null<Ui::GenericBox*> box,
std::shared_ptr<ChatHelpers::Show> show,
SponsoredPhrases phrases,
const
Data::SponsoredMessages::Details &details,
Data::SponsoredReportAction report) {
constexpr
auto
kUrl
=
"
https://promote.telegram.org
"
_cs;
box->
setWidth
(st::boxWideWidth);
box->
setNoContentMargin
(
true
);
const
auto
isChannel = (phrases == SponsoredPhrases::Channel);
const
auto
isSearch = (phrases == SponsoredPhrases::Search);
const
auto
session = &show->
session
();
const
auto
content = box->
verticalLayout
().
get
();
const
auto
levels =
Data::LevelLimits
(session)
.
channelRestrictSponsoredLevelMin
();
Ui::AddSkip
(content);
Ui::AddSkip
(content);
Ui::AddSkip
(content);
{
const
auto
&icon = st::sponsoredAboutTitleIcon;
const
auto
rect =
Rect
(icon.
size
() *
1.4
);
auto
owned = object_ptr<Ui::RpWidget>(content);
owned->
resize
(rect.
size
());
owned->
setNaturalWidth
(rect.
width
());
const
auto
widget = box->
addRow
(
std::move
(owned), style::al_top);
widget->
paintRequest
(
) |
rpl::on_next
([=] {
auto
p =
Painter
(widget);
auto
hq =
PainterHighQualityEnabler
(p);
p.
setPen
(Qt::NoPen);
p.
setBrush
(st::activeButtonBg);
p.
drawEllipse
(rect);
icon.
paintInCenter
(p, rect);
}, widget->
lifetime
());
}
Ui::AddSkip
(content);
Ui::AddSkip
(content);
box->
addRow
(
object_ptr<Ui::FlatLabel>(
content,
tr::lng_sponsored_menu_revenued_about
(),
st::boxTitle),
style::al_top);
Ui::AddSkip
(content);
box->
addRow
(
object_ptr<Ui::FlatLabel>(
content,
tr::lng_sponsored_revenued_subtitle
(),
st::channelEarnLearnDescription),
style::al_top);
Ui::AddSkip
(content);
Ui::AddSkip
(content);
{
const
auto
padding =
QMargins
(
st::settingsButton.
padding
.
left
(),
st::boxRowPadding.
top
(),
st::boxRowPadding.
right
(),
st::boxRowPadding.
bottom
());
const
auto
addEntry = [&](
rpl::producer<QString> title,
rpl::producer<TextWithEntities> about,
const
style::icon &icon) {
const
auto
top = content->
add
(
object_ptr<Ui::FlatLabel>(
content,
std::move
(title),
st::channelEarnSemiboldLabel),
padding);
Ui::AddSkip
(content, st::channelEarnHistoryThreeSkip);
const
auto
label = content->
add
(
object_ptr<Ui::FlatLabel>(
content,
std::move
(about),
st::channelEarnHistoryRecipientLabel),
padding);
const
auto
left = Ui::CreateChild<Ui::RpWidget>(
box->
verticalLayout
().
get
());
left->
paintRequest
(
) |
rpl::on_next
([=] {
auto
p =
Painter
(left);
icon.
paint
(p,
0
,
0
, left->
width
());
}, left->
lifetime
());
left->
resize
(icon.
size
());
top->
geometryValue
(
) |
rpl::on_next
([=](
const
QRect &g) {
left->
moveToLeft
(
(g.
left
() - left->
width
()) /
2
,
g.
top
() + st::channelEarnHistoryThreeSkip);
}, left->
lifetime
());
return
label;
};
addEntry
(
tr::lng_sponsored_revenued_info1_title
(),
(isChannel
? tr::lng_sponsored_revenued_info1_description
: isSearch
? tr::lng_sponsored_revenued_info1_search_description
: tr::lng_sponsored_revenued_info1_bot_description)(
tr::rich),
st::sponsoredAboutPrivacyIcon);
if
(!isSearch) {
Ui::AddSkip
(content);
Ui::AddSkip
(content);
addEntry
(
(isChannel
? tr::lng_sponsored_revenued_info2_title
: tr::lng_sponsored_revenued_info2_bot_title)(),
(isChannel
? tr::lng_sponsored_revenued_info2_description
: tr::lng_sponsored_revenued_info2_bot_description)(
tr::rich),
st::sponsoredAboutSplitIcon);
}
Ui::AddSkip
(content);
Ui::AddSkip
(content);
auto
link =
tr::lng_settings_privacy_premium_link
(
) |
rpl::map
([](QString t) {
return
tr::link
(
std::move
(t),
u"
internal:
"
_q);
});
addEntry
(
tr::lng_sponsored_revenued_info3_title
(),
(isChannel
?
tr::lng_sponsored_revenued_info3_description
(
lt_count,
rpl::single
(
float64
(levels)),
lt_link,
std::move
(link),
tr::rich)
: isSearch
?
tr::lng_sponsored_revenued_info3_search_description
(
lt_link,
tr::lng_sponsored_revenued_info3_search_link
(
lt_arrow,
rpl::single
(
Ui::Text::IconEmoji
(&st::textMoreIconEmoji)),
tr::marked
) |
rpl::map
([](TextWithEntities &&link) {
return
Ui::Text::Wrapped
(
std::move
(link),
EntityType::CustomUrl,
u"
internal:
"
_q);
}),
tr::rich)
:
tr::lng_sponsored_revenued_info3_bot_description
(
lt_link,
std::move
(link),
tr::rich)),
st::sponsoredAboutRemoveIcon)->
setClickHandlerFilter
([=](
const
auto
&...) {
ShowPremiumPreviewBox
(show, PremiumFeature::NoAds);
return
true
;
});
Ui::AddSkip
(content);
Ui::AddSkip
(content);
}
Ui::AddSkip
(content);
Ui::AddSkip
(content);
{
box->
addRow
(
object_ptr<Ui::FlatLabel>(
content,
tr::lng_sponsored_revenued_footer_title
(),
st::boxTitle),
style::al_top);
}
Ui::AddSkip
(content);
{
const
auto
arrow =
Ui::Text::IconEmoji
(&st::textMoreIconEmoji);
const
auto
available = box->
width
()
-
rect::m::sum::h
(st::boxRowPadding);
box->
addRow
(
object_ptr<Ui::FlatLabel>(
content,
(isChannel
? tr::lng_sponsored_revenued_footer_description
: isSearch
? tr::lng_sponsored_revenued_footer_search_description
: tr::lng_sponsored_revenued_footer_bot_description)(
lt_link,
tr::lng_channel_earn_about_link
(
lt_emoji,
rpl::single
(arrow),
tr::rich
) |
rpl::map
([=](TextWithEntities t) {
return
tr::link
(
std::move
(t),
kUrl
.
utf16
());
}),
tr::rich),
st::channelEarnLearnDescription))->
resizeToWidth
(available);
}
Ui::AddSkip
(content);
Ui::AddSkip
(content);
{
const
auto
&st = st::premiumPreviewDoubledLimitsBox;
box->
setStyle
(st);
auto
button = object_ptr<Ui::RoundButton>(
box,
tr::lng_box_ok
(),
st::defaultActiveButton);
button->
setTextTransform
(Ui::RoundButtonTextTransform::ToUpper);
button->
resizeToWidth
(box->
width
()
- st.
buttonPadding
.
left
()
- st.
buttonPadding
.
left
());
button->
setClickedCallback
([=] { box->
closeBox
(); });
box->
addButton
(
std::move
(button));
}
if
(!isChannel) {
const
auto
top = Ui::CreateChild<Ui::IconButton>(
box,
st::infoTopBarMenu);
box->
widthValue
(
) |
rpl::on_next
([=](
int
width) {
top->
raise
();
top->
moveToLeft
(
width - top->
width
() - st::defaultScrollArea.
width
,
0
);
}, top->
lifetime
());
using
MenuPtr = base::unique_qptr<Ui::PopupMenu>;
const
auto
menu = top->
lifetime
().
make_state
<MenuPtr>();
top->
setClickedCallback
([=] {
*menu = base::make_unique_q<Ui::PopupMenu>(
box->
window
(),
st::popupMenuWithIcons);
const
auto
raw = menu->
get
();
raw->
animatePhaseValue
(
) |
rpl::on_next
([=](Ui::PopupMenu::AnimatePhase phase) {
top->
setForceRippled
(
false
|| phase == Ui::PopupMenu::AnimatePhase::Shown
|| phase == Ui::PopupMenu::AnimatePhase::StartShow);
}, top->
lifetime
());
raw->
setDestroyedCallback
([=] {
top->
setForceRippled
(
false
);
});
FillSponsored
(
Ui::Menu::CreateAddActionCallback
(menu->
get
()),
show,
phrases,
details,
report,
{ .
skipAbout
=
true
});
const
auto
global = top->
mapToGlobal
(
QPoint
(top->
width
() /
4
*
3
, top->
height
() /
2
));
raw->
setForcedOrigin
(Ui::PanelAnimation::Origin::TopRight);
raw->
popup
(
QPoint
(
global.
x
(),
std::max
(global.
y
(),
QCursor::pos
().
y
())));
return
true
;
});
}
}
void
ShowReportSponsoredBox
(
std::shared_ptr<ChatHelpers::Show> show,
Data::SponsoredReportAction report) {
const
auto
guideLink =
tr::link
(
tr::lng_report_sponsored_reported_link
(tr::now),
u"
https://promote.telegram.org/guidelines
"
_q);
auto
performRequest = [=](
const
auto
&repeatRequest,
Data::SponsoredReportResult::Id id) ->
void
{
report.
callback
(id, [=](
const
Data::SponsoredReportResult &result) {
if
(!result.
error
.
isEmpty
()) {
show->
showToast
(result.
error
);
}
if
(!result.
options
.
empty
()) {
show->
show
(
Box
([=](not_null<Ui::GenericBox*> box) {
box->
setTitle
(result.
title
);
for
(
const
auto
&option : result.
options
) {
const
auto
button =
Ui::AddReportOptionButton
(
box->
verticalLayout
(),
option.
text
,
nullptr
);
button->
setClickedCallback
([=] {
repeatRequest
(repeatRequest, option.
id
);
});
}
if
(!id.
isNull
()) {
box->
addLeftButton
(
tr::lng_create_group_back
(),
[=] { box->
closeBox
(); });
}
else
{
const
auto
container = box->
verticalLayout
();
Ui::AddSkip
(container);
container->
add
(object_ptr<Ui::DividerLabel>(
container,
object_ptr<Ui::FlatLabel>(
container,
tr::lng_report_sponsored_reported_learn
(
lt_link,
rpl::single
(guideLink),
tr::marked),
st::boxDividerLabel),
st::defaultBoxDividerLabelPadding));
}
box->
addButton
(
tr::lng_close
(),
[=] { show->
hideLayer
(); });
}));
}
else
{
constexpr
auto
kToastDuration
=
crl::time
(
4000
);
switch
(result.
result
) {
case
Data::SponsoredReportResult::FinalStep::Hidden: {
show->
showToast
(
tr::lng_report_sponsored_hidden
(tr::now),
kToastDuration
);
}
break
;
case
Data::SponsoredReportResult::FinalStep::Reported: {
auto
text =
tr::lng_report_sponsored_reported
(
tr::now,
lt_link,
guideLink,
tr::marked);
show->
showToast
({
.
text
=
std::move
(text),
.
duration
=
kToastDuration
,
});
}
break
;
case
Data::SponsoredReportResult::FinalStep::Premium: {
ShowPremiumPreviewBox
(show, PremiumFeature::NoAds);
}
break
;
}
show->
hideLayer
();
}
});
};
performRequest
(performRequest,
Data::SponsoredReportResult::Id
());
}
}
//
namespace
void
FillSponsored
(
const
Ui::Menu::MenuCallback &addAction,
std::shared_ptr<ChatHelpers::Show> show,
SponsoredPhrases phrases,
const
Data::SponsoredMessages::Details &details,
Data::SponsoredReportAction report,
SponsoredMenuSettings settings) {
const
auto
session = &show->
session
();
const
auto
&info = details.
info
;
const
auto
dark = settings.
dark
;
if
(!settings.
skipInfo
&& !info.
empty
()) {
auto
fillSubmenu = [&](not_null<Ui::PopupMenu*> menu) {
const
auto
allText =
ranges::accumulate
(
info,
TextWithEntities
(),
[](TextWithEntities a, TextWithEntities b) {
return
a.
text
.
isEmpty
() ? b : a.
append
(
'
\n
'
).
append
(b);
}).
text
;
const
auto
callback = [=] {
TextUtilities::SetClipboardText
({ allText });
show->
showToast
(
tr::lng_text_copied
(tr::now));
};
for
(
const
auto
&i : info) {
auto
item = base::make_unique_q<Ui::Menu::MultilineAction>(
menu->
menu
(),
dark ? st::storiesMenu : st::defaultMenu,
(dark
? st::historySponsorInfoItemDark
: st::historySponsorInfoItem),
st::historyHasCustomEmojiPosition,
base::duplicate
(i));
item->
clicks
(
) |
rpl::on_next
(callback, menu->
lifetime
());
menu->
addAction
(
std::move
(item));
if
(i != details.
info
.
back
()) {
menu->
addSeparator
();
}
}
};
addAction
({
.
text
=
tr::lng_sponsored_info_menu
(tr::now),
.
handler
=
nullptr
,
.
icon
= (dark
? &st::mediaMenuIconChannel
: &st::menuIconChannel),
.
fillSubmenu
=
std::move
(fillSubmenu),
});
addAction
({
.
separatorSt
= (dark
? &st::mediaviewMenuSeparator
: &st::expandedMenuSeparator),
.
isSeparator
=
true
,
});
}
if
(details.
canReport
) {
if
(!settings.
skipAbout
) {
addAction
(
tr::lng_sponsored_menu_revenued_about
(tr::now), [=] {
show->
show
(
Box
(AboutBox, show, phrases, details, report));
}, (dark ? &st::mediaMenuIconInfo : &st::menuIconInfo));
}
addAction
(
tr::lng_sponsored_menu_revenued_report
(tr::now), [=] {
ShowReportSponsoredBox
(show, report);
}, (dark ? &st::mediaMenuIconBlock : &st::menuIconBlock));
addAction
({
.
separatorSt
= (dark
? &st::mediaviewMenuSeparator
: &st::expandedMenuSeparator),
.
isSeparator
=
true
,
});
}
addAction
(
tr::lng_sponsored_hide_ads
(tr::now), [=] {
if
(session->
premium
()) {
using
Result = Data::SponsoredReportResult;
report.
callback
(
Result::Id
(
"
-1
"
), [](
const
auto
&) {});
}
else
{
ShowPremiumPreviewBox
(show, PremiumFeature::NoAds);
}
}, (dark ? &st::mediaMenuIconCancel : &st::menuIconCancel));
}
void
FillSponsored
(
const
Ui::Menu::MenuCallback &addAction,
std::shared_ptr<ChatHelpers::Show> show,
const
FullMsgId &fullId,
SponsoredMenuSettings settings) {
const
auto
session = &show->
session
();
FillSponsored
(
addAction,
show,
PhrasesForMessage
(fullId),
session->
sponsoredMessages
().
lookupDetails
(fullId),
session->
sponsoredMessages
().
createReportCallback
(fullId),
settings);
}
void
ShowSponsored
(
not_null<Ui::RpWidget*> parent,
std::shared_ptr<ChatHelpers::Show> show,
const
FullMsgId &fullId) {
const
auto
menu = Ui::CreateChild<Ui::PopupMenu>(
parent.
get
(),
st::popupMenuWithIcons);
FillSponsored
(
Ui::Menu::CreateAddActionCallback
(menu),
show,
fullId);
menu->
popup
(
QCursor::pos
());
}
void
ShowSponsoredAbout
(
std::shared_ptr<ChatHelpers::Show> show,
const
FullMsgId &fullId) {
const
auto
session = &show->
session
();
show->
showBox
(
Box
([=](not_null<Ui::GenericBox*> box) {
AboutBox
(
box,
show,
PhrasesForMessage
(fullId),
session->
sponsoredMessages
().
lookupDetails
(fullId),
session->
sponsoredMessages
().
createReportCallback
(fullId));
}));
}
}
//
namespace Menu
Back
|
FazBrowse Home
|
New Git URL