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"
|
2016-10-31 12:29:26 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-06-06 10:29:51 +00:00
|
|
|
#include "styles/style_profile.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"
|
2016-08-16 16:53:10 +00:00
|
|
|
#include "mainwindow.h"
|
2016-06-06 10:29:51 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
ReportBox::ReportBox(QWidget*, PeerData *peer) : _peer(peer)
|
2017-03-18 21:06:10 +00:00
|
|
|
, _reasonGroup(std::make_shared<Ui::RadioenumGroup<Reason>>(Reason::Spam))
|
|
|
|
, _reasonSpam(this, _reasonGroup, Reason::Spam, lang(lng_report_reason_spam), st::defaultBoxCheckbox)
|
|
|
|
, _reasonViolence(this, _reasonGroup, Reason::Violence, lang(lng_report_reason_violence), st::defaultBoxCheckbox)
|
|
|
|
, _reasonPornography(this, _reasonGroup, Reason::Pornography, lang(lng_report_reason_pornography), st::defaultBoxCheckbox)
|
|
|
|
, _reasonOther(this, _reasonGroup, Reason::Other, lang(lng_report_reason_other), st::defaultBoxCheckbox) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::prepare() {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(_peer->isUser() ? lng_report_bot_title : (_peer->isMegagroup() ? lng_report_group_title : lng_report_title)));
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_report_button), [this] { onReport(); });
|
|
|
|
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
2016-06-06 10:29:51 +00:00
|
|
|
|
2017-03-18 21:06:10 +00:00
|
|
|
_reasonGroup->setChangedCallback([this](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);
|
|
|
|
_reasonPornography->moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _reasonViolence->bottomNoMargins() + st::boxOptionListSkip);
|
|
|
|
_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) {
|
2017-05-30 15:21:05 +00:00
|
|
|
_reasonOtherText.create(this, st::profileReportReasonOther, langFactory(lng_report_reason_description));
|
2016-06-06 10:29:51 +00:00
|
|
|
_reasonOtherText->show();
|
2016-12-09 18:56:01 +00:00
|
|
|
_reasonOtherText->setCtrlEnterSubmit(Ui::CtrlEnterSubmit::Both);
|
2016-06-06 10:29:51 +00:00
|
|
|
_reasonOtherText->setMaxLength(MaxPhotoCaption);
|
|
|
|
_reasonOtherText->resize(width() - (st::boxPadding.left() + st::boxOptionListPadding.left() + st::boxPadding.right()), _reasonOtherText->height());
|
|
|
|
|
|
|
|
updateMaxHeight();
|
2017-05-02 11:56:39 +00:00
|
|
|
connect(_reasonOtherText, SIGNAL(resized()), this, SLOT(onReasonResized()));
|
2016-06-06 10:29:51 +00:00
|
|
|
connect(_reasonOtherText, SIGNAL(submitted(bool)), this, SLOT(onReport()));
|
|
|
|
connect(_reasonOtherText, SIGNAL(cancelled()), this, SLOT(onClose()));
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-02 11:56:39 +00:00
|
|
|
void ReportBox::onReasonResized() {
|
2016-06-06 10:29:51 +00:00
|
|
|
updateMaxHeight();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::onReport() {
|
|
|
|
if (_requestId) return;
|
|
|
|
|
|
|
|
if (_reasonOtherText && _reasonOtherText->getLastText().trimmed().isEmpty()) {
|
|
|
|
_reasonOtherText->showError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto getReason = [this]() {
|
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();
|
|
|
|
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.");
|
2016-06-06 10:29:51 +00:00
|
|
|
};
|
2016-12-09 06:19:55 +00:00
|
|
|
_requestId = MTP::send(MTPaccount_ReportPeer(_peer->input, getReason()), rpcDone(&ReportBox::reportDone), rpcFail(&ReportBox::reportFail));
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::reportDone(const MTPBool &result) {
|
|
|
|
_requestId = 0;
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lang(lng_report_thanks)));
|
2016-06-06 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ReportBox::reportFail(const RPCError &error) {
|
|
|
|
if (MTP::isDefaultHandledError(error)) return false;
|
|
|
|
|
|
|
|
_requestId = 0;
|
|
|
|
if (_reasonOtherText) {
|
|
|
|
_reasonOtherText->showError();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportBox::updateMaxHeight() {
|
2017-07-04 13:59:00 +00:00
|
|
|
auto newHeight = st::boxOptionListPadding.top() + _reasonSpam->getMargins().top() + 4 * _reasonSpam->heightNoMargins() + 3 * st::boxOptionListSkip + _reasonSpam->getMargins().bottom() + st::boxOptionListPadding.bottom();
|
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
|
|
|
}
|