mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Moved RateCallBox to td_ui.
This commit is contained in:
parent
93ae5e71f7
commit
78f0cf908e
7 changed files with 187 additions and 168 deletions
|
@ -233,8 +233,6 @@ PRIVATE
|
||||||
boxes/phone_banned_box.h
|
boxes/phone_banned_box.h
|
||||||
boxes/pin_messages_box.cpp
|
boxes/pin_messages_box.cpp
|
||||||
boxes/pin_messages_box.h
|
boxes/pin_messages_box.h
|
||||||
boxes/rate_call_box.cpp
|
|
||||||
boxes/rate_call_box.h
|
|
||||||
boxes/self_destruction_box.cpp
|
boxes/self_destruction_box.cpp
|
||||||
boxes/self_destruction_box.h
|
boxes/self_destruction_box.h
|
||||||
boxes/send_files_box.cpp
|
boxes/send_files_box.cpp
|
||||||
|
|
|
@ -1,143 +0,0 @@
|
||||||
/*
|
|
||||||
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/rate_call_box.h"
|
|
||||||
|
|
||||||
#include "lang/lang_keys.h"
|
|
||||||
#include "ui/boxes/confirm_box.h"
|
|
||||||
#include "ui/widgets/labels.h"
|
|
||||||
#include "ui/widgets/buttons.h"
|
|
||||||
#include "ui/widgets/input_fields.h"
|
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "main/main_session.h"
|
|
||||||
#include "core/application.h"
|
|
||||||
#include "core/core_settings.h"
|
|
||||||
#include "apiwrap.h"
|
|
||||||
#include "styles/style_layers.h"
|
|
||||||
#include "styles/style_calls.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
constexpr auto kMaxRating = 5;
|
|
||||||
constexpr auto kRateCallCommentLengthMax = 200;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
RateCallBox::RateCallBox(
|
|
||||||
QWidget*,
|
|
||||||
not_null<Main::Session*> session,
|
|
||||||
uint64 callId,
|
|
||||||
uint64 callAccessHash)
|
|
||||||
: _session(session)
|
|
||||||
, _api(&_session->mtp())
|
|
||||||
, _callId(callId)
|
|
||||||
, _callAccessHash(callAccessHash) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void RateCallBox::prepare() {
|
|
||||||
setTitle(tr::lng_call_rate_label());
|
|
||||||
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
|
||||||
|
|
||||||
for (auto i = 0; i < kMaxRating; ++i) {
|
|
||||||
_stars.emplace_back(this, st::callRatingStar);
|
|
||||||
_stars.back()->setClickedCallback([this, value = i + 1] { ratingChanged(value); });
|
|
||||||
_stars.back()->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateMaxHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RateCallBox::resizeEvent(QResizeEvent *e) {
|
|
||||||
BoxContent::resizeEvent(e);
|
|
||||||
|
|
||||||
auto starsWidth = (_stars.size() * st::callRatingStar.width);
|
|
||||||
auto starLeft = (width() - starsWidth) / 2;
|
|
||||||
auto starTop = st::callRatingStarTop;
|
|
||||||
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();
|
|
||||||
addButton(tr::lng_send_button(), [this] { send(); });
|
|
||||||
addButton(tr::lng_cancel(), [this] { closeBox(); });
|
|
||||||
}
|
|
||||||
_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) {
|
|
||||||
_comment.create(
|
|
||||||
this,
|
|
||||||
st::callRatingComment,
|
|
||||||
Ui::InputField::Mode::MultiLine,
|
|
||||||
tr::lng_call_rate_comment());
|
|
||||||
_comment->show();
|
|
||||||
_comment->setSubmitSettings(Core::App().settings().sendSubmitWay());
|
|
||||||
_comment->setMaxLength(kRateCallCommentLengthMax);
|
|
||||||
_comment->resize(width() - (st::callRatingPadding.left() + st::callRatingPadding.right()), _comment->height());
|
|
||||||
|
|
||||||
updateMaxHeight();
|
|
||||||
connect(_comment, &Ui::InputField::resized, [=] { commentResized(); });
|
|
||||||
connect(_comment, &Ui::InputField::submitted, [=] { send(); });
|
|
||||||
connect(_comment, &Ui::InputField::cancelled, [=] { closeBox(); });
|
|
||||||
}
|
|
||||||
_comment->setFocusFast();
|
|
||||||
} else if (_comment) {
|
|
||||||
_comment.destroy();
|
|
||||||
updateMaxHeight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RateCallBox::setInnerFocus() {
|
|
||||||
if (_comment) {
|
|
||||||
_comment->setFocusFast();
|
|
||||||
} else {
|
|
||||||
setFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RateCallBox::commentResized() {
|
|
||||||
updateMaxHeight();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RateCallBox::send() {
|
|
||||||
Expects(_rating > 0 && _rating <= kMaxRating);
|
|
||||||
|
|
||||||
if (_requestId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto comment = _comment ? _comment->getLastText().trimmed() : QString();
|
|
||||||
_requestId = _api.request(MTPphone_SetCallRating(
|
|
||||||
MTP_flags(0),
|
|
||||||
MTP_inputPhoneCall(MTP_long(_callId), MTP_long(_callAccessHash)),
|
|
||||||
MTP_int(_rating),
|
|
||||||
MTP_string(comment)
|
|
||||||
)).done([=](const MTPUpdates &updates) {
|
|
||||||
_session->api().applyUpdates(updates);
|
|
||||||
closeBox();
|
|
||||||
}).fail([=](const MTP::Error &error) { closeBox(); }).send();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RateCallBox::updateMaxHeight() {
|
|
||||||
auto newHeight = st::callRatingPadding.top() + st::callRatingStarTop + _stars.back()->heightNoMargins() + st::callRatingPadding.bottom();
|
|
||||||
if (_comment) {
|
|
||||||
newHeight += st::callRatingCommentTop + _comment->height();
|
|
||||||
}
|
|
||||||
setDimensions(st::boxWideWidth, newHeight);
|
|
||||||
}
|
|
|
@ -13,7 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
#include "boxes/rate_call_box.h"
|
#include "ui/boxes/rate_call_box.h"
|
||||||
#include "calls/calls_instance.h"
|
#include "calls/calls_instance.h"
|
||||||
#include "base/openssl_help.h"
|
#include "base/openssl_help.h"
|
||||||
#include "base/random.h"
|
#include "base/random.h"
|
||||||
|
@ -571,7 +571,31 @@ bool Call::handleUpdate(const MTPPhoneCall &call) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.is_need_rating() && _id && _accessHash) {
|
if (data.is_need_rating() && _id && _accessHash) {
|
||||||
Ui::show(Box<RateCallBox>(&_user->session(), _id, _accessHash));
|
const auto session = &_user->session();
|
||||||
|
const auto callId = _id;
|
||||||
|
const auto callAccessHash = _accessHash;
|
||||||
|
const auto box = Ui::show(Box<Ui::RateCallBox>(
|
||||||
|
Core::App().settings().sendSubmitWay()));
|
||||||
|
const auto sender = box->lifetime().make_state<MTP::Sender>(
|
||||||
|
&session->mtp());
|
||||||
|
box->sends(
|
||||||
|
) | rpl::take(
|
||||||
|
1 // Instead of keeping requestId.
|
||||||
|
) | rpl::start_with_next([=](const Ui::RateCallBox::Result &r) {
|
||||||
|
sender->request(MTPphone_SetCallRating(
|
||||||
|
MTP_flags(0),
|
||||||
|
MTP_inputPhoneCall(
|
||||||
|
MTP_long(callId),
|
||||||
|
MTP_long(callAccessHash)),
|
||||||
|
MTP_int(r.rating),
|
||||||
|
MTP_string(r.comment)
|
||||||
|
)).done([=](const MTPUpdates &updates) {
|
||||||
|
session->api().applyUpdates(updates);
|
||||||
|
box->closeBox();
|
||||||
|
}).fail([=] {
|
||||||
|
box->closeBox();
|
||||||
|
}).send();
|
||||||
|
}, box->lifetime());
|
||||||
}
|
}
|
||||||
const auto reason = data.vreason();
|
const auto reason = data.vreason();
|
||||||
if (reason && reason->type() == mtpc_phoneCallDiscardReasonDisconnect) {
|
if (reason && reason->type() == mtpc_phoneCallDiscardReasonDisconnect) {
|
||||||
|
|
|
@ -31,9 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "mainwidget.h"
|
|
||||||
#include "mtproto/mtproto_config.h"
|
#include "mtproto/mtproto_config.h"
|
||||||
#include "boxes/rate_call_box.h"
|
|
||||||
#include "app.h" // App::quitting
|
#include "app.h" // App::quitting
|
||||||
|
|
||||||
#include <tgcalls/VideoCaptureInterface.h>
|
#include <tgcalls/VideoCaptureInterface.h>
|
||||||
|
|
144
Telegram/SourceFiles/ui/boxes/rate_call_box.cpp
Normal file
144
Telegram/SourceFiles/ui/boxes/rate_call_box.cpp
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
/*
|
||||||
|
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 "ui/boxes/rate_call_box.h"
|
||||||
|
|
||||||
|
#include "lang/lang_keys.h"
|
||||||
|
#include "ui/widgets/buttons.h"
|
||||||
|
#include "ui/widgets/input_fields.h"
|
||||||
|
#include "styles/style_layers.h"
|
||||||
|
#include "styles/style_calls.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kMaxRating = 5;
|
||||||
|
constexpr auto kRateCallCommentLengthMax = 200;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
RateCallBox::RateCallBox(QWidget*, InputSubmitSettings sendWay)
|
||||||
|
: _sendWay(sendWay) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void RateCallBox::prepare() {
|
||||||
|
setTitle(tr::lng_call_rate_label());
|
||||||
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
|
|
||||||
|
for (auto i = 0; i < kMaxRating; ++i) {
|
||||||
|
_stars.emplace_back(this, st::callRatingStar);
|
||||||
|
_stars.back()->setClickedCallback([this, value = i + 1] {
|
||||||
|
ratingChanged(value);
|
||||||
|
});
|
||||||
|
_stars.back()->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMaxHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RateCallBox::resizeEvent(QResizeEvent *e) {
|
||||||
|
BoxContent::resizeEvent(e);
|
||||||
|
|
||||||
|
const auto starsWidth = (_stars.size() * st::callRatingStar.width);
|
||||||
|
auto starLeft = (width() - starsWidth) / 2;
|
||||||
|
const auto starTop = st::callRatingStarTop;
|
||||||
|
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();
|
||||||
|
addButton(tr::lng_send_button(), [=] { send(); });
|
||||||
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
|
}
|
||||||
|
_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) {
|
||||||
|
_comment.create(
|
||||||
|
this,
|
||||||
|
st::callRatingComment,
|
||||||
|
Ui::InputField::Mode::MultiLine,
|
||||||
|
tr::lng_call_rate_comment());
|
||||||
|
_comment->show();
|
||||||
|
_comment->setSubmitSettings(_sendWay);
|
||||||
|
_comment->setMaxLength(kRateCallCommentLengthMax);
|
||||||
|
_comment->resize(
|
||||||
|
width()
|
||||||
|
- st::callRatingPadding.left()
|
||||||
|
- st::callRatingPadding.right(),
|
||||||
|
_comment->height());
|
||||||
|
|
||||||
|
updateMaxHeight();
|
||||||
|
connect(_comment, &InputField::resized, [=] {
|
||||||
|
commentResized();
|
||||||
|
});
|
||||||
|
connect(_comment, &InputField::submitted, [=] { send(); });
|
||||||
|
connect(_comment, &InputField::cancelled, [=] { closeBox(); });
|
||||||
|
}
|
||||||
|
_comment->setFocusFast();
|
||||||
|
} else if (_comment) {
|
||||||
|
_comment.destroy();
|
||||||
|
updateMaxHeight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RateCallBox::setInnerFocus() {
|
||||||
|
if (_comment) {
|
||||||
|
_comment->setFocusFast();
|
||||||
|
} else {
|
||||||
|
setFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RateCallBox::commentResized() {
|
||||||
|
updateMaxHeight();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RateCallBox::send() {
|
||||||
|
Expects(_rating > 0 && _rating <= kMaxRating);
|
||||||
|
_sends.fire({
|
||||||
|
.rating = _rating,
|
||||||
|
.comment = _comment ? _comment->getLastText().trimmed() : QString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void RateCallBox::updateMaxHeight() {
|
||||||
|
auto newHeight = st::callRatingPadding.top()
|
||||||
|
+ st::callRatingStarTop
|
||||||
|
+ _stars.back()->heightNoMargins()
|
||||||
|
+ st::callRatingPadding.bottom();
|
||||||
|
if (_comment) {
|
||||||
|
newHeight += st::callRatingCommentTop + _comment->height();
|
||||||
|
}
|
||||||
|
setDimensions(st::boxWideWidth, newHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<RateCallBox::Result> RateCallBox::sends() const {
|
||||||
|
return _sends.events();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Ui
|
|
@ -8,25 +8,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "boxes/abstract_box.h"
|
#include "boxes/abstract_box.h"
|
||||||
#include "mtproto/sender.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class InputField;
|
|
||||||
class FlatLabel;
|
|
||||||
class IconButton;
|
|
||||||
} // namespace Ui
|
|
||||||
|
|
||||||
namespace Main {
|
class InputField;
|
||||||
class Session;
|
class IconButton;
|
||||||
} // namespace Main
|
enum class InputSubmitSettings;
|
||||||
|
|
||||||
class RateCallBox : public Ui::BoxContent {
|
class RateCallBox : public Ui::BoxContent {
|
||||||
public:
|
public:
|
||||||
RateCallBox(
|
RateCallBox(QWidget*, InputSubmitSettings sendWay);
|
||||||
QWidget*,
|
|
||||||
not_null<Main::Session*> session,
|
struct Result {
|
||||||
uint64 callId,
|
int rating = 0;
|
||||||
uint64 callAccessHash);
|
QString comment;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<Result> sends() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
@ -40,16 +38,14 @@ private:
|
||||||
void send();
|
void send();
|
||||||
void commentResized();
|
void commentResized();
|
||||||
|
|
||||||
const not_null<Main::Session*> _session;
|
const InputSubmitSettings _sendWay;
|
||||||
MTP::Sender _api;
|
|
||||||
|
|
||||||
uint64 _callId = 0;
|
|
||||||
uint64 _callAccessHash = 0;
|
|
||||||
int _rating = 0;
|
int _rating = 0;
|
||||||
|
|
||||||
std::vector<object_ptr<Ui::IconButton>> _stars;
|
std::vector<object_ptr<Ui::IconButton>> _stars;
|
||||||
object_ptr<Ui::InputField> _comment = { nullptr };
|
object_ptr<Ui::InputField> _comment = { nullptr };
|
||||||
|
|
||||||
mtpRequestId _requestId = 0;
|
rpl::event_stream<Result> _sends;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Ui
|
|
@ -116,6 +116,8 @@ PRIVATE
|
||||||
ui/boxes/country_select_box.h
|
ui/boxes/country_select_box.h
|
||||||
ui/boxes/edit_invite_link.cpp
|
ui/boxes/edit_invite_link.cpp
|
||||||
ui/boxes/edit_invite_link.h
|
ui/boxes/edit_invite_link.h
|
||||||
|
ui/boxes/rate_call_box.cpp
|
||||||
|
ui/boxes/rate_call_box.h
|
||||||
ui/boxes/report_box.cpp
|
ui/boxes/report_box.cpp
|
||||||
ui/boxes/report_box.h
|
ui/boxes/report_box.h
|
||||||
ui/boxes/single_choice_box.cpp
|
ui/boxes/single_choice_box.cpp
|
||||||
|
|
Loading…
Add table
Reference in a new issue