2022-04-17 10:30:08 +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 "boxes/report_messages_box.h"
|
|
|
|
|
|
|
|
#include "api/api_report.h"
|
|
|
|
#include "data/data_peer.h"
|
2022-04-17 11:48:53 +00:00
|
|
|
#include "data/data_photo.h"
|
2022-04-17 10:30:08 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "ui/boxes/report_box.h"
|
|
|
|
#include "ui/layers/generic_box.h"
|
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
|
2022-04-17 11:48:53 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
[[nodiscard]] object_ptr<Ui::BoxContent> Report(
|
2022-04-17 11:00:21 +00:00
|
|
|
not_null<PeerData*> peer,
|
2022-04-17 11:48:53 +00:00
|
|
|
std::variant<v::null_t, MessageIdsList, not_null<PhotoData*>> data) {
|
|
|
|
const auto source = v::match(data, [](const MessageIdsList &ids) {
|
|
|
|
return Ui::ReportSource::Message;
|
|
|
|
}, [](not_null<PhotoData*> photo) {
|
|
|
|
return photo->hasVideo()
|
|
|
|
? Ui::ReportSource::ProfileVideo
|
|
|
|
: Ui::ReportSource::ProfilePhoto;
|
|
|
|
}, [](v::null_t) {
|
|
|
|
Unexpected("Bad source report.");
|
|
|
|
return Ui::ReportSource::Bot;
|
|
|
|
});
|
2022-04-17 11:00:21 +00:00
|
|
|
return Box([=](not_null<Ui::GenericBox*> box) {
|
2022-04-17 11:48:53 +00:00
|
|
|
Ui::ReportReasonBox(box, source, [=](Ui::ReportReason reason) {
|
2022-04-17 11:00:21 +00:00
|
|
|
Ui::BoxShow(box).showBox(Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
const auto show = Ui::BoxShow(box);
|
|
|
|
Ui::ReportDetailsBox(box, [=](const QString &text) {
|
2022-04-17 11:47:32 +00:00
|
|
|
const auto toastParent = show.toastParent();
|
2022-04-17 11:48:53 +00:00
|
|
|
Api::SendReport(toastParent, peer, reason, text, data);
|
2022-04-17 11:00:21 +00:00
|
|
|
show.hideLayer();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2022-04-17 10:30:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-17 11:48:53 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
object_ptr<Ui::BoxContent> ReportItemsBox(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
MessageIdsList ids) {
|
|
|
|
return Report(peer, ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<Ui::BoxContent> ReportProfilePhotoBox(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<PhotoData*> photo) {
|
|
|
|
return Report(peer, photo);
|
|
|
|
}
|
|
|
|
|
2022-04-17 10:30:08 +00:00
|
|
|
void ShowReportPeerBox(
|
|
|
|
not_null<Window::SessionController*> window,
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
struct State {
|
2022-04-17 11:00:21 +00:00
|
|
|
QPointer<Ui::BoxContent> reasonBox;
|
|
|
|
QPointer<Ui::BoxContent> detailsBox;
|
2022-04-17 10:30:08 +00:00
|
|
|
MessageIdsList ids;
|
|
|
|
};
|
|
|
|
const auto state = std::make_shared<State>();
|
|
|
|
const auto chosen = [=](Ui::ReportReason reason) {
|
|
|
|
const auto send = [=](const QString &text) {
|
|
|
|
window->clearChooseReportMessages();
|
2022-04-17 11:47:32 +00:00
|
|
|
Api::SendReport(
|
|
|
|
Window::Show(window).toastParent(),
|
|
|
|
peer,
|
|
|
|
reason,
|
|
|
|
text,
|
|
|
|
std::move(state->ids));
|
2022-04-17 10:30:08 +00:00
|
|
|
if (const auto strong = state->reasonBox.data()) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
if (const auto strong = state->detailsBox.data()) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (reason == Ui::ReportReason::Fake
|
|
|
|
|| reason == Ui::ReportReason::Other) {
|
|
|
|
state->ids = {};
|
2022-04-17 11:00:21 +00:00
|
|
|
state->detailsBox = window->show(Box(Ui::ReportDetailsBox, send));
|
2022-04-17 10:30:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
window->showChooseReportMessages(peer, reason, [=](
|
|
|
|
MessageIdsList ids) {
|
|
|
|
state->ids = std::move(ids);
|
2022-04-17 11:00:21 +00:00
|
|
|
state->detailsBox = window->show(Box(Ui::ReportDetailsBox, send));
|
2022-04-17 10:30:08 +00:00
|
|
|
});
|
|
|
|
};
|
2022-04-17 11:00:21 +00:00
|
|
|
state->reasonBox = window->show(Box(
|
2022-04-17 10:30:08 +00:00
|
|
|
Ui::ReportReasonBox,
|
|
|
|
(peer->isBroadcast()
|
|
|
|
? Ui::ReportSource::Channel
|
|
|
|
: peer->isUser()
|
|
|
|
? Ui::ReportSource::Bot
|
|
|
|
: Ui::ReportSource::Group),
|
|
|
|
chosen));
|
|
|
|
}
|