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-09-17 13:26:53 +00:00
|
|
|
#include "data/data_session.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"
|
2020-09-17 13:26:53 +00:00
|
|
|
#include "history/history_item.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"
|
2020-09-17 13:26:53 +00:00
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "window/window_peer_menu.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));
|
2021-01-26 08:15:00 +00:00
|
|
|
createButton(_reasonFake, Reason::Fake, tr::lng_report_reason_fake(tr::now));
|
2019-06-19 15:09:03 +00:00
|
|
|
createButton(_reasonViolence, Reason::Violence, tr::lng_report_reason_violence(tr::now));
|
2021-01-26 08:15:00 +00:00
|
|
|
createButton(_reasonChildAbuse, Reason::ChildAbuse, tr::lng_report_reason_child_abuse(tr::now));
|
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());
|
2021-01-26 08:15:00 +00:00
|
|
|
_reasonFake->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonSpam->bottomNoMargins() + st::boxOptionListSkip);
|
|
|
|
_reasonViolence->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonFake->bottomNoMargins() + st::boxOptionListSkip);
|
|
|
|
_reasonChildAbuse->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonViolence->bottomNoMargins() + st::boxOptionListSkip);
|
|
|
|
_reasonPornography->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonChildAbuse->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();
|
2021-01-26 08:15:00 +00:00
|
|
|
case Reason::Fake: return MTP_inputReportReasonFake();
|
2017-03-18 21:06:10 +00:00
|
|
|
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() {
|
2021-01-26 08:15:00 +00:00
|
|
|
const auto buttonsCount = 6;
|
2019-03-25 12:07:31 +00:00
|
|
|
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
|
|
|
}
|
2020-09-17 13:26:53 +00:00
|
|
|
|
|
|
|
void BlockSenderFromRepliesBox(
|
|
|
|
not_null<Ui::GenericBox*> box,
|
|
|
|
not_null<Window::SessionController*> controller,
|
2020-09-25 12:31:36 +00:00
|
|
|
FullMsgId id) {
|
|
|
|
const auto item = controller->session().data().message(id);
|
2020-09-17 13:26:53 +00:00
|
|
|
Assert(item != nullptr);
|
|
|
|
|
|
|
|
PeerMenuBlockUserBox(
|
|
|
|
box,
|
|
|
|
&controller->window(),
|
|
|
|
item->senderOriginal(),
|
|
|
|
true,
|
2020-09-25 12:31:36 +00:00
|
|
|
Window::ClearReply{ id });
|
2020-09-17 13:26:53 +00:00
|
|
|
}
|