2016-06-06 10:29:51 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-06 10:29:51 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-06 10:29:51 +00:00
|
|
|
*/
|
2016-10-31 12:29:26 +00:00
|
|
|
#include "boxes/report_box.h"
|
2016-06-06 10:29:51 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_peer.h"
|
2020-02-08 18:45:38 +00:00
|
|
|
#include "main/main_session.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2018-05-10 14:15:16 +00:00
|
|
|
#include "ui/toast/toast.h"
|
2016-08-16 16:53:10 +00:00
|
|
|
#include "mainwindow.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/core_settings.h"
|
|
|
|
#include "core/application.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_profile.h"
|
2016-06-06 10:29:51 +00:00
|
|
|
|
2018-10-17 11:38:07 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kReportReasonLengthMax = 200;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2018-05-10 14:15:16 +00:00
|
|
|
ReportBox::ReportBox(QWidget*, not_null<PeerData*> peer)
|
2020-06-11 16:09:46 +00:00
|
|
|
: _peer(peer)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&_peer->session().mtp()) {
|
2018-05-10 14:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ReportBox::ReportBox(QWidget*, not_null<PeerData*> peer, MessageIdsList ids)
|
|
|
|
: _peer(peer)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&_peer->session().mtp())
|
2018-05-10 14:15:16 +00:00
|
|
|
, _ids(std::move(ids)) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle([&] {
|
2018-05-10 14:15:16 +00:00
|
|
|
if (_ids) {
|
2019-06-18 15:00:55 +00:00
|
|
|
return tr::lng_report_message_title();
|
2018-05-10 14:15:16 +00:00
|
|
|
} else if (_peer->isUser()) {
|
2019-06-18 15:00:55 +00:00
|
|
|
return tr::lng_report_bot_title();
|
2018-05-10 14:15:16 +00:00
|
|
|
} else if (_peer->isMegagroup()) {
|
2019-06-18 15:00:55 +00:00
|
|
|
return tr::lng_report_group_title();
|
2018-05-10 14:15:16 +00:00
|
|
|
} else {
|
2019-06-18 15:00:55 +00:00
|
|
|
return tr::lng_report_title();
|
2018-05-10 14:15:16 +00:00
|
|
|
}
|
2019-06-18 15:00:55 +00:00
|
|
|
}());
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_report_button(), [=] { report(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2016-06-06 10:29:51 +00:00
|
|
|
|
2018-05-10 14:15:16 +00:00
|
|
|
_reasonGroup = std::make_shared<Ui::RadioenumGroup<Reason>>(
|
|
|
|
Reason::Spam);
|
|
|
|
const auto createButton = [&](
|
|
|
|
object_ptr<Ui::Radioenum<Reason>> &button,
|
|
|
|
Reason reason,
|
2019-06-19 15:09:03 +00:00
|
|
|
const QString &text) {
|
2018-05-10 14:15:16 +00:00
|
|
|
button.create(
|
|
|
|
this,
|
|
|
|
_reasonGroup,
|
|
|
|
reason,
|
2019-06-19 15:09:03 +00:00
|
|
|
text,
|
2018-05-10 14:15:16 +00:00
|
|
|
st::defaultBoxCheckbox);
|
|
|
|
};
|
2019-06-19 15:09:03 +00:00
|
|
|
createButton(_reasonSpam, Reason::Spam, tr::lng_report_reason_spam(tr::now));
|
|
|
|
createButton(_reasonViolence, Reason::Violence, tr::lng_report_reason_violence(tr::now));
|
2019-03-25 12:07:31 +00:00
|
|
|
if (_ids) {
|
2019-06-19 15:09:03 +00:00
|
|
|
createButton(_reasonChildAbuse, Reason::ChildAbuse, tr::lng_report_reason_child_abuse(tr::now));
|
2019-03-25 12:07:31 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
createButton(_reasonPornography, Reason::Pornography, tr::lng_report_reason_pornography(tr::now));
|
|
|
|
createButton(_reasonOther, Reason::Other, tr::lng_report_reason_other(tr::now));
|
2018-05-10 14:15:16 +00:00
|
|
|
_reasonGroup->setChangedCallback([=](Reason value) {
|
|
|
|
reasonChanged(value);
|
|
|
|
});
|
2016-06-06 10:29:51 +00:00
|
|
|
|
|
|
|
updateMaxHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::resizeEvent(QResizeEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2017-07-04 13:59:00 +00:00
|
|
|
_reasonSpam->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), st::boxOptionListPadding.top() + _reasonSpam->getMargins().top());
|
2016-12-13 17:07:56 +00:00
|
|
|
_reasonViolence->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonSpam->bottomNoMargins() + st::boxOptionListSkip);
|
2019-03-25 12:07:31 +00:00
|
|
|
if (_ids) {
|
|
|
|
_reasonChildAbuse->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonViolence->bottomNoMargins() + st::boxOptionListSkip);
|
|
|
|
_reasonPornography->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonChildAbuse->bottomNoMargins() + st::boxOptionListSkip);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
_reasonPornography->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonViolence->bottomNoMargins() + st::boxOptionListSkip);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
_reasonOther->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonPornography->bottomNoMargins() + st::boxOptionListSkip);
|
2016-06-06 10:29:51 +00:00
|
|
|
|
|
|
|
if (_reasonOtherText) {
|
2016-12-02 19:16:35 +00:00
|
|
|
_reasonOtherText->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left() - st::defaultInputField.textMargins.left(), _reasonOther->bottomNoMargins() + st::newGroupDescriptionPadding.top());
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
void ReportBox::reasonChanged(Reason reason) {
|
|
|
|
if (reason == Reason::Other) {
|
2016-06-06 10:29:51 +00:00
|
|
|
if (!_reasonOtherText) {
|
2018-05-20 17:42:30 +00:00
|
|
|
_reasonOtherText.create(
|
|
|
|
this,
|
|
|
|
st::profileReportReasonOther,
|
|
|
|
Ui::InputField::Mode::MultiLine,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_report_reason_description());
|
2016-06-06 10:29:51 +00:00
|
|
|
_reasonOtherText->show();
|
2020-06-18 18:04:16 +00:00
|
|
|
_reasonOtherText->setSubmitSettings(Core::App().settings().sendSubmitWay());
|
2018-10-17 11:38:07 +00:00
|
|
|
_reasonOtherText->setMaxLength(kReportReasonLengthMax);
|
2016-06-06 10:29:51 +00:00
|
|
|
_reasonOtherText->resize(width() - (st::boxPadding.left() + st::boxOptionListPadding.left() + st::boxPadding.right()), _reasonOtherText->height());
|
|
|
|
|
|
|
|
updateMaxHeight();
|
2018-05-31 12:20:28 +00:00
|
|
|
connect(_reasonOtherText, &Ui::InputField::resized, [=] { reasonResized(); });
|
|
|
|
connect(_reasonOtherText, &Ui::InputField::submitted, [=] { report(); });
|
|
|
|
connect(_reasonOtherText, &Ui::InputField::cancelled, [=] { closeBox(); });
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
2016-12-20 13:03:51 +00:00
|
|
|
_reasonOtherText->setFocusFast();
|
2016-06-06 10:29:51 +00:00
|
|
|
} else if (_reasonOtherText) {
|
|
|
|
_reasonOtherText.destroy();
|
|
|
|
updateMaxHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void ReportBox::setInnerFocus() {
|
2016-06-06 10:29:51 +00:00
|
|
|
if (_reasonOtherText) {
|
2016-12-20 13:03:51 +00:00
|
|
|
_reasonOtherText->setFocusFast();
|
2016-06-06 10:29:51 +00:00
|
|
|
} else {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void ReportBox::reasonResized() {
|
2016-06-06 10:29:51 +00:00
|
|
|
updateMaxHeight();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void ReportBox::report() {
|
2020-06-11 16:09:46 +00:00
|
|
|
if (_requestId) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-06 10:29:51 +00:00
|
|
|
|
|
|
|
if (_reasonOtherText && _reasonOtherText->getLastText().trimmed().isEmpty()) {
|
|
|
|
_reasonOtherText->showError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-10 14:15:16 +00:00
|
|
|
const auto reason = [&] {
|
2017-03-18 11:55:04 +00:00
|
|
|
switch (_reasonGroup->value()) {
|
2017-03-18 21:06:10 +00:00
|
|
|
case Reason::Spam: return MTP_inputReportReasonSpam();
|
|
|
|
case Reason::Violence: return MTP_inputReportReasonViolence();
|
2019-03-25 12:07:31 +00:00
|
|
|
case Reason::ChildAbuse: return MTP_inputReportReasonChildAbuse();
|
2017-03-18 21:06:10 +00:00
|
|
|
case Reason::Pornography: return MTP_inputReportReasonPornography();
|
|
|
|
case Reason::Other: return MTP_inputReportReasonOther(MTP_string(_reasonOtherText->getLastText()));
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
2017-03-18 11:55:04 +00:00
|
|
|
Unexpected("Bad reason group value.");
|
2018-05-10 14:15:16 +00:00
|
|
|
}();
|
|
|
|
if (_ids) {
|
|
|
|
auto ids = QVector<MTPint>();
|
|
|
|
for (const auto &fullId : *_ids) {
|
|
|
|
ids.push_back(MTP_int(fullId.msg));
|
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
_requestId = _api.request(MTPmessages_Report(
|
|
|
|
_peer->input,
|
|
|
|
MTP_vector<MTPint>(ids),
|
|
|
|
reason
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
reportDone(result);
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
reportFail(error);
|
|
|
|
}).send();
|
2018-05-10 14:15:16 +00:00
|
|
|
} else {
|
2020-06-11 16:09:46 +00:00
|
|
|
_requestId = _api.request(MTPaccount_ReportPeer(
|
|
|
|
_peer->input,
|
|
|
|
reason
|
|
|
|
)).done([=](const MTPBool &result) {
|
|
|
|
reportDone(result);
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
reportFail(error);
|
|
|
|
}).send();
|
2018-05-10 14:15:16 +00:00
|
|
|
}
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::reportDone(const MTPBool &result) {
|
|
|
|
_requestId = 0;
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(tr::lng_report_thanks(tr::now));
|
2018-05-10 14:15:16 +00:00
|
|
|
closeBox();
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:09:46 +00:00
|
|
|
void ReportBox::reportFail(const RPCError &error) {
|
2016-06-06 10:29:51 +00:00
|
|
|
_requestId = 0;
|
|
|
|
if (_reasonOtherText) {
|
|
|
|
_reasonOtherText->showError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::updateMaxHeight() {
|
2019-03-25 12:07:31 +00:00
|
|
|
const auto buttonsCount = _ids ? 5 : 4;
|
|
|
|
auto newHeight = st::boxOptionListPadding.top() + _reasonSpam->getMargins().top() + buttonsCount * _reasonSpam->heightNoMargins() + (buttonsCount - 1) * st::boxOptionListSkip + _reasonSpam->getMargins().bottom() + st::boxOptionListPadding.bottom();
|
2019-06-18 14:07:45 +00:00
|
|
|
|
2016-06-06 10:29:51 +00:00
|
|
|
if (_reasonOtherText) {
|
2016-12-13 17:07:56 +00:00
|
|
|
newHeight += st::newGroupDescriptionPadding.top() + _reasonOtherText->height() + st::newGroupDescriptionPadding.bottom();
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWidth, newHeight);
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|