2022-04-17 10:16:48 +00:00
|
|
|
/*
|
|
|
|
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_peer.h"
|
2022-04-17 11:48:53 +00:00
|
|
|
#include "data/data_photo.h"
|
2022-04-17 10:16:48 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "ui/boxes/report_box.h"
|
2023-05-02 09:33:19 +00:00
|
|
|
#include "ui/layers/show.h"
|
2022-04-17 10:16:48 +00:00
|
|
|
|
|
|
|
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 SendReport(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<Ui::Show> show,
|
2022-04-17 10:16:48 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Ui::ReportReason reason,
|
|
|
|
const QString &comment,
|
2022-04-17 11:48:53 +00:00
|
|
|
std::variant<v::null_t, MessageIdsList, not_null<PhotoData*>> data) {
|
2023-05-02 09:33:19 +00:00
|
|
|
auto done = [=] {
|
|
|
|
show->showToast(tr::lng_report_thanks(tr::now));
|
|
|
|
};
|
2022-04-17 11:48:53 +00:00
|
|
|
v::match(data, [&](v::null_t) {
|
2022-04-17 10:16:48 +00:00
|
|
|
peer->session().api().request(MTPaccount_ReportPeer(
|
|
|
|
peer->input,
|
|
|
|
ReasonToTL(reason),
|
|
|
|
MTP_string(comment)
|
2022-04-17 11:48:53 +00:00
|
|
|
)).done(std::move(done)).send();
|
|
|
|
}, [&](const MessageIdsList &ids) {
|
2022-04-17 10:16:48 +00:00
|
|
|
auto apiIds = QVector<MTPint>();
|
|
|
|
apiIds.reserve(ids.size());
|
|
|
|
for (const auto &fullId : ids) {
|
|
|
|
apiIds.push_back(MTP_int(fullId.msg));
|
|
|
|
}
|
|
|
|
peer->session().api().request(MTPmessages_Report(
|
|
|
|
peer->input,
|
|
|
|
MTP_vector<MTPint>(apiIds),
|
|
|
|
ReasonToTL(reason),
|
|
|
|
MTP_string(comment)
|
2022-04-17 11:48:53 +00:00
|
|
|
)).done(std::move(done)).send();
|
|
|
|
}, [&](not_null<PhotoData*> photo) {
|
|
|
|
peer->session().api().request(MTPaccount_ReportProfilePhoto(
|
|
|
|
peer->input,
|
|
|
|
photo->mtpInput(),
|
|
|
|
ReasonToTL(reason),
|
|
|
|
MTP_string(comment)
|
|
|
|
)).done(std::move(done)).send();
|
|
|
|
});
|
2022-04-17 10:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Api
|