Fixed switching between sections of Premium Settings.

This commit is contained in:
23rd 2022-08-25 03:38:32 +03:00 committed by John Preston
parent 857f56d5b4
commit e03eaaaa98

View file

@ -470,7 +470,8 @@ public:
TopBarUser( TopBarUser(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<PeerData*> peer); not_null<PeerData*> peer,
rpl::producer<> showFinished);
void setPaused(bool paused) override; void setPaused(bool paused) override;
void setTextPosition(int x, int y) override; void setTextPosition(int x, int y) override;
@ -510,7 +511,8 @@ private:
TopBarUser::TopBarUser( TopBarUser::TopBarUser(
not_null<QWidget*> parent, not_null<QWidget*> parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<PeerData*> peer) not_null<PeerData*> peer,
rpl::producer<> showFinished)
: TopBarAbstract(parent) : TopBarAbstract(parent)
, _content(this) , _content(this)
, _title(_content, st::settingsPremiumUserTitle) , _title(_content, st::settingsPremiumUserTitle)
@ -619,8 +621,12 @@ TopBarUser::TopBarUser(
_content->resize(size.width(), maximumHeight()); _content->resize(size.width(), maximumHeight());
}, lifetime()); }, lifetime());
sizeValue( rpl::combine(
) | rpl::start_with_next([=](const QSize &size) { rpl::single(
false
) | rpl::then(std::move(showFinished) | rpl::map_to(true)),
sizeValue()
) | rpl::start_with_next([=](bool showFinished, const QSize &size) {
_content->resize(size.width(), maximumHeight()); _content->resize(size.width(), maximumHeight());
_content->moveToLeft(0, -(_content->height() - size.height())); _content->moveToLeft(0, -(_content->height() - size.height()));
@ -628,11 +634,15 @@ TopBarUser::TopBarUser(
const auto shown = (minimumHeight() * 2 > size.height()); const auto shown = (minimumHeight() * 2 > size.height());
if (_smallTop.shown != shown) { if (_smallTop.shown != shown) {
_smallTop.shown = shown; _smallTop.shown = shown;
_smallTop.animation.start( if (!showFinished) {
[=] { _smallTop.widget->update(); }, _smallTop.widget->update();
_smallTop.shown ? 0. : 1., } else {
_smallTop.shown ? 1. : 0., _smallTop.animation.start(
st::infoTopBarDuration); [=] { _smallTop.widget->update(); },
_smallTop.shown ? 0. : 1.,
_smallTop.shown ? 1. : 0.,
st::infoTopBarDuration);
}
} }
}, lifetime()); }, lifetime());
@ -1284,7 +1294,8 @@ QPointer<Ui::RpWidget> Premium::createPinnedToTop(
return Ui::CreateChild<TopBarUser>( return Ui::CreateChild<TopBarUser>(
parent.get(), parent.get(),
_controller, _controller,
peerWithPremium); peerWithPremium,
_showFinished.events());
} }
return Ui::CreateChild<TopBar>( return Ui::CreateChild<TopBar>(
parent.get(), parent.get(),
@ -1373,10 +1384,12 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
return nullptr; return nullptr;
} }
const auto emojiStatusData = Ref::EmojiStatus::Parse(_ref);
auto buttonText = [&]() -> std::optional<rpl::producer<QString>> { auto buttonText = [&]() -> std::optional<rpl::producer<QString>> {
if (const auto emojiData = Ref::EmojiStatus::Parse(_ref)) { if (emojiStatusData) {
auto &data = _controller->session().data(); auto &data = _controller->session().data();
if (const auto peer = data.peer(emojiData.peerId)) { if (const auto peer = data.peer(emojiStatusData.peerId)) {
return Info::Profile::EmojiStatusIdValue( return Info::Profile::EmojiStatusIdValue(
peer peer
) | rpl::map([](DocumentId id) { ) | rpl::map([](DocumentId id) {
@ -1395,6 +1408,18 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
[ref = _ref] { return ref; }, [ref = _ref] { return ref; },
std::move(buttonText), std::move(buttonText),
}); });
if (emojiStatusData) {
// "Learn More" should open the general Premium Settings
// so we override the button callback.
// To have ability to jump back to the User Premium Settings
// we should replace the ref explicitly.
_subscribe->setClickedCallback([=] {
const auto ref = _ref;
const auto controller = _controller;
ShowPremium(controller, QString());
controller->setPremiumRef(ref);
});
}
_showFinished.events( _showFinished.events(
) | rpl::take(1) | rpl::start_with_next([=] { ) | rpl::take(1) | rpl::start_with_next([=] {