FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tdesktop/Telegram/SourceFiles/api/api_report.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
/
api
/
api_report.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
200 lines (181 loc) · 5.37 KB
Breadcrumbs
tdesktop
/
Telegram
/
SourceFiles
/
api
/
api_report.cpp
Copy path
File metadata and controls
200 lines (181 loc) · 5.37 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
/*
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_report.h
"
#
include
"
apiwrap.h
"
#
include
"
data/data_session.h
"
#
include
"
data/data_peer.h
"
#
include
"
data/data_channel.h
"
#
include
"
data/data_photo.h
"
#
include
"
data/data_report.h
"
#
include
"
data/data_user.h
"
#
include
"
lang/lang_keys.h
"
#
include
"
main/main_session.h
"
#
include
"
ui/boxes/report_box_graphics.h
"
#
include
"
ui/layers/show.h
"
namespace
Api
{
namespace
{
MTPreportReason
ReasonToTL
(
const
Ui::ReportReason &reason) {
using
Reason = Ui::ReportReason;
switch
(reason) {
case
Reason::Spam:
return
MTP_inputReportReasonSpam
();
case
Reason::Fake:
return
MTP_inputReportReasonFake
();
case
Reason::Violence:
return
MTP_inputReportReasonViolence
();
case
Reason::ChildAbuse:
return
MTP_inputReportReasonChildAbuse
();
case
Reason::Pornography:
return
MTP_inputReportReasonPornography
();
case
Reason::Copyright:
return
MTP_inputReportReasonCopyright
();
case
Reason::IllegalDrugs:
return
MTP_inputReportReasonIllegalDrugs
();
case
Reason::PersonalDetails:
return
MTP_inputReportReasonPersonalDetails
();
case
Reason::Other:
return
MTP_inputReportReasonOther
();
}
Unexpected
(
"
Bad reason group value.
"
);
}
}
//
namespace
void
SendPhotoReport
(
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> peer,
Ui::ReportReason reason,
const
QString &comment,
not_null<PhotoData*> photo) {
peer->
session
().
api
().
request
(
MTPaccount_ReportProfilePhoto
(
peer->
input
(),
photo->
mtpInput
(),
ReasonToTL
(reason),
MTP_string
(comment)
)).
done
([=] {
show->
showToast
(
tr::lng_report_thanks
(tr::now));
}).
send
();
}
auto
CreateReportMessagesOrStoriesCallback
(
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> peer)
-> Fn<void(Data::ReportInput, Fn<
void
(ReportResult)>)> {
using
TLChoose = MTPDreportResultChooseOption;
using
TLAddComment = MTPDreportResultAddComment;
using
TLReported = MTPDreportResultReported;
using
Result = ReportResult;
struct
State
final
{
#
ifdef
_DEBUG
~State
() {
qDebug
() <<
"
Messages or Stories Report ~State().
"
;
}
#
endif
mtpRequestId requestId =
0
;
};
const
auto
state = std::make_shared<State>();
return
[=](
Data::ReportInput reportInput,
Fn<
void
(Result)> done) {
auto
apiIds = QVector<MTPint>();
apiIds.
reserve
(reportInput.
ids
.
size
() + reportInput.
stories
.
size
());
for
(
const
auto
&id : reportInput.
ids
) {
apiIds.
push_back
(
MTP_int
(id));
}
for
(
const
auto
&story : reportInput.
stories
) {
apiIds.
push_back
(
MTP_int
(story));
}
const
auto
received = [=](
const
MTPReportResult &result,
mtpRequestId requestId) {
if
(state->
requestId
!= requestId) {
return
;
}
state->
requestId
=
0
;
done
(result.
match
([&](
const
TLChoose &data) {
const
auto
t =
qs
(data.
vtitle
());
auto
list =
Result::Options
();
list.
reserve
(data.
voptions
().
v
.
size
());
for
(
const
auto
&tl : data.
voptions
().
v
) {
list.
emplace_back
(Result::Option{
.
id
= tl.
data
().
voption
().
v
,
.
text
=
qs
(tl.
data
().
vtext
()),
});
}
return
Result{ .
options
=
std::move
(list), .
title
= t };
}, [&](
const
TLAddComment &data) -> Result {
return
{
.
commentOption
= ReportResult::CommentOption{
.
optional
= data.
is_optional
(),
.
id
= data.
voption
().
v
,
}
};
}, [&](
const
TLReported &data) -> Result {
return
{ .
successful
=
true
};
}));
};
const
auto
fail = [=](
const
MTP
::Error &error) {
state->
requestId
=
0
;
done
({ .
error
= error.
type
() });
};
if
(!reportInput.
stories
.
empty
()) {
state->
requestId
= peer->
session
().
api
().
request
(
MTPstories_Report
(
peer->
input
(),
MTP_vector<MTPint>(apiIds),
MTP_bytes
(reportInput.
optionId
),
MTP_string
(reportInput.
comment
))
).
done
(received).
fail
(fail).
send
();
}
else
{
state->
requestId
= peer->
session
().
api
().
request
(
MTPmessages_Report
(
peer->
input
(),
MTP_vector<MTPint>(apiIds),
MTP_bytes
(reportInput.
optionId
),
MTP_string
(reportInput.
comment
))
).
done
(received).
fail
(fail).
send
();
}
};
}
ReactionReportCapabilities
GetReactionReportCapabilities
(
not_null<PeerData*> group,
not_null<PeerData*> participant) {
const
auto
channel = group->
asMegagroup
();
return
channel
? ReactionReportCapabilities{
.
canReport
= channel->
isPublic
() && !participant->
isSelf
(),
.
canBan
= channel->
canRestrictParticipant
(participant),
}
:
ReactionReportCapabilities
();
}
void
ReportReaction
(
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> group,
MsgId messageId,
not_null<PeerData*> participant) {
group->
session
().
api
().
request
(
MTPmessages_ReportReaction
(
group->
input
(),
MTP_int
(messageId.
bare
),
participant->
input
()
)).
done
([=] {
if
(show) {
show->
showToast
(
tr::lng_report_thanks
(tr::now));
}
}).
send
();
}
void
ReportSpam
(
not_null<PeerData*> sender,
const
MessageIdsList &ids) {
if
(ids.
empty
()) {
return
;
}
const
auto
peer = sender->
owner
().
peer
(ids.
front
().
peer
);
const
auto
channel = peer->
asChannel
();
if
(!channel) {
return
;
}
auto
msgIds = QVector<MTPint>();
msgIds.
reserve
(ids.
size
());
for
(
const
auto
&fullId : ids) {
msgIds.
push_back
(
MTP_int
(fullId.
msg
));
}
sender->
session
().
api
().
request
(
MTPchannels_ReportSpam
(
channel->
inputChannel
(),
sender->
input
(),
MTP_vector<MTPint>(msgIds)
)).
send
();
}
}
//
namespace Api
Back
|
FazBrowse Home
|
New Git URL