| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /*
- 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"
- #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();
- }
- };
- }
- } // namespace Api
|