2017-05-02 11:56:39 +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.
|
2017-05-02 11:56:39 +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
|
2017-05-02 11:56:39 +00:00
|
|
|
*/
|
|
|
|
#include "boxes/rate_call_box.h"
|
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-05-02 11:56:39 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/input_fields.h"
|
|
|
|
#include "mainwindow.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2018-11-26 11:55:02 +00:00
|
|
|
#include "apiwrap.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_calls.h"
|
2017-05-02 11:56:39 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kMaxRating = 5;
|
2018-10-17 11:38:07 +00:00
|
|
|
constexpr auto kRateCallCommentLengthMax = 200;
|
2017-05-02 11:56:39 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
RateCallBox::RateCallBox(
|
|
|
|
QWidget*,
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
uint64 callId,
|
|
|
|
uint64 callAccessHash)
|
|
|
|
: _session(session)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&_session->mtp())
|
2019-07-25 18:55:11 +00:00
|
|
|
, _callId(callId)
|
2017-05-09 19:33:50 +00:00
|
|
|
, _callAccessHash(callAccessHash) {
|
2017-05-02 11:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RateCallBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_call_rate_label());
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
2017-05-02 11:56:39 +00:00
|
|
|
|
|
|
|
for (auto i = 0; i < kMaxRating; ++i) {
|
2019-07-25 18:55:11 +00:00
|
|
|
_stars.emplace_back(this, st::callRatingStar);
|
2017-05-02 11:56:39 +00:00
|
|
|
_stars.back()->setClickedCallback([this, value = i + 1] { ratingChanged(value); });
|
|
|
|
_stars.back()->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateMaxHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RateCallBox::resizeEvent(QResizeEvent *e) {
|
|
|
|
BoxContent::resizeEvent(e);
|
|
|
|
|
2017-05-09 19:33:50 +00:00
|
|
|
auto starsWidth = (_stars.size() * st::callRatingStar.width);
|
|
|
|
auto starLeft = (width() - starsWidth) / 2;
|
|
|
|
auto starTop = st::callRatingStarTop;
|
2017-05-02 11:56:39 +00:00
|
|
|
for (auto &star : _stars) {
|
|
|
|
star->moveToLeft(starLeft, starTop);
|
|
|
|
starLeft += star->width();
|
|
|
|
}
|
|
|
|
if (_comment) {
|
|
|
|
_comment->moveToLeft(st::callRatingPadding.left(), _stars.back()->bottomNoMargins() + st::callRatingCommentTop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RateCallBox::ratingChanged(int value) {
|
|
|
|
Expects(value > 0 && value <= kMaxRating);
|
|
|
|
if (!_rating) {
|
|
|
|
clearButtons();
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_send_button(), [this] { send(); });
|
|
|
|
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
2017-05-02 11:56:39 +00:00
|
|
|
}
|
|
|
|
_rating = value;
|
|
|
|
|
|
|
|
for (auto i = 0; i < kMaxRating; ++i) {
|
|
|
|
_stars[i]->setIconOverride((i < value) ? &st::callRatingStarFilled : nullptr);
|
|
|
|
_stars[i]->setRippleColorOverride((i < value) ? &st::lightButtonBgOver : nullptr);
|
|
|
|
}
|
|
|
|
if (value < kMaxRating) {
|
|
|
|
if (!_comment) {
|
2018-05-20 17:42:30 +00:00
|
|
|
_comment.create(
|
|
|
|
this,
|
|
|
|
st::callRatingComment,
|
|
|
|
Ui::InputField::Mode::MultiLine,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_call_rate_comment());
|
2017-05-02 11:56:39 +00:00
|
|
|
_comment->show();
|
2020-06-18 18:04:16 +00:00
|
|
|
_comment->setSubmitSettings(Core::App().settings().sendSubmitWay());
|
2018-10-17 11:38:07 +00:00
|
|
|
_comment->setMaxLength(kRateCallCommentLengthMax);
|
2017-05-02 11:56:39 +00:00
|
|
|
_comment->resize(width() - (st::callRatingPadding.left() + st::callRatingPadding.right()), _comment->height());
|
|
|
|
|
|
|
|
updateMaxHeight();
|
2018-05-31 12:20:28 +00:00
|
|
|
connect(_comment, &Ui::InputField::resized, [=] { commentResized(); });
|
|
|
|
connect(_comment, &Ui::InputField::submitted, [=] { send(); });
|
|
|
|
connect(_comment, &Ui::InputField::cancelled, [=] { closeBox(); });
|
2017-05-02 11:56:39 +00:00
|
|
|
}
|
|
|
|
_comment->setFocusFast();
|
|
|
|
} else if (_comment) {
|
|
|
|
_comment.destroy();
|
|
|
|
updateMaxHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RateCallBox::setInnerFocus() {
|
|
|
|
if (_comment) {
|
|
|
|
_comment->setFocusFast();
|
|
|
|
} else {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void RateCallBox::commentResized() {
|
2017-05-02 11:56:39 +00:00
|
|
|
updateMaxHeight();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void RateCallBox::send() {
|
2017-05-02 11:56:39 +00:00
|
|
|
Expects(_rating > 0 && _rating <= kMaxRating);
|
2018-05-31 12:20:28 +00:00
|
|
|
|
2017-05-02 11:56:39 +00:00
|
|
|
if (_requestId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto comment = _comment ? _comment->getLastText().trimmed() : QString();
|
2019-11-27 08:02:56 +00:00
|
|
|
_requestId = _api.request(MTPphone_SetCallRating(
|
2019-03-15 13:34:47 +00:00
|
|
|
MTP_flags(0),
|
2018-11-26 11:55:02 +00:00
|
|
|
MTP_inputPhoneCall(MTP_long(_callId), MTP_long(_callAccessHash)),
|
|
|
|
MTP_int(_rating),
|
|
|
|
MTP_string(comment)
|
|
|
|
)).done([=](const MTPUpdates &updates) {
|
2019-07-25 18:55:11 +00:00
|
|
|
_session->api().applyUpdates(updates);
|
2017-05-02 11:56:39 +00:00
|
|
|
closeBox();
|
2021-03-12 12:48:00 +00:00
|
|
|
}).fail([=](const MTP::Error &error) { closeBox(); }).send();
|
2017-05-02 11:56:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RateCallBox::updateMaxHeight() {
|
2017-05-09 19:33:50 +00:00
|
|
|
auto newHeight = st::callRatingPadding.top() + st::callRatingStarTop + _stars.back()->heightNoMargins() + st::callRatingPadding.bottom();
|
2017-05-02 11:56:39 +00:00
|
|
|
if (_comment) {
|
|
|
|
newHeight += st::callRatingCommentTop + _comment->height();
|
|
|
|
}
|
2017-05-09 19:33:50 +00:00
|
|
|
setDimensions(st::boxWideWidth, newHeight);
|
2017-05-02 11:56:39 +00:00
|
|
|
}
|