From a6e13a9f9e5540a6953bf34476ac262459697ff0 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 11 Oct 2023 23:13:10 +0300 Subject: [PATCH] Added dummy layer class for boosts. --- Telegram/CMakeLists.txt | 4 + Telegram/Resources/langs/lang.strings | 13 +++ .../info/boosts/info_boosts_inner_widget.cpp | 38 +++++++ .../info/boosts/info_boosts_inner_widget.h | 49 +++++++++ .../info/boosts/info_boosts_widget.cpp | 103 ++++++++++++++++++ .../info/boosts/info_boosts_widget.h | 59 ++++++++++ Telegram/SourceFiles/info/info_controller.h | 1 + 7 files changed, 267 insertions(+) create mode 100644 Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp create mode 100644 Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h create mode 100644 Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp create mode 100644 Telegram/SourceFiles/info/boosts/info_boosts_widget.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 4a73bf094..83d0818ba 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -829,6 +829,10 @@ PRIVATE info/info_top_bar.h info/info_wrap_widget.cpp info/info_wrap_widget.h + info/boosts/info_boosts_inner_widget.cpp + info/boosts/info_boosts_inner_widget.h + info/boosts/info_boosts_widget.cpp + info/boosts/info_boosts_widget.h info/common_groups/info_common_groups_inner_widget.cpp info/common_groups/info_common_groups_inner_widget.h info/common_groups/info_common_groups_widget.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 503f0a020..a2ac91c50 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4127,6 +4127,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_chart_title_group_day" = "Views by hours"; "lng_chart_title_group_week" = "Top days of week"; +"lng_boosts_title" = "Boosts"; +"lng_boosts_level" = "Level"; +"lng_boosts_existing" = "Existing boosts"; +"lng_boosts_premium_audience" = "Premium subscribers"; +"lng_boosts_next_level" = "Boosts to level up"; +"lng_boosts_list_title#one" = "{count} booster"; +"lng_boosts_list_title#other" = "{count} boosters"; +"lng_boosts_list_subtext" = "Your channel is currently boosted by these users."; +"lng_boosts_show_more" = "Show More Boosts"; +"lng_boosts_list_status" = "boost expires on {date}"; +"lng_boosts_link_title" = "Link for boosting"; +"lng_boosts_link_subtext" = "Share this link with your subscribers to get more boosts."; + // Wnd specific "lng_wnd_choose_program_menu" = "Choose Default Program..."; diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp new file mode 100644 index 000000000..77fc82ca9 --- /dev/null +++ b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.cpp @@ -0,0 +1,38 @@ +/* +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 "info/boosts/info_boosts_inner_widget.h" + +namespace Info::Boosts { + +InnerWidget::InnerWidget( + QWidget *parent, + not_null controller, + not_null peer) +: VerticalLayout(parent) +, _controller(controller) +, _peer(peer) { +} + +rpl::producer InnerWidget::scrollToRequests() const { + return _scrollToRequests.events(); +} + +auto InnerWidget::showRequests() const -> rpl::producer { + return _showRequests.events(); +} + +void InnerWidget::showFinished() { + _showFinished.fire({}); +} + +not_null InnerWidget::peer() const { + return _peer; +} + +} // namespace Info::Boosts + diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h new file mode 100644 index 000000000..f5442a115 --- /dev/null +++ b/Telegram/SourceFiles/info/boosts/info_boosts_inner_widget.h @@ -0,0 +1,49 @@ +/* +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 +*/ +#pragma once + +#include "ui/widgets/scroll_area.h" +#include "ui/wrap/vertical_layout.h" + +namespace Info { +class Controller; +} // namespace Info + +namespace Info::Boosts { + +class Memento; + +class InnerWidget final : public Ui::VerticalLayout { +public: + struct ShowRequest final { + }; + + InnerWidget( + QWidget *parent, + not_null controller, + not_null peer); + + [[nodiscard]] not_null peer() const; + + [[nodiscard]] rpl::producer scrollToRequests() const; + [[nodiscard]] rpl::producer showRequests() const; + + void showFinished(); + +private: + not_null _controller; + not_null _peer; + + rpl::event_stream _scrollToRequests; + rpl::event_stream _showRequests; + rpl::event_stream<> _showFinished; + rpl::event_stream _loaded; + +}; + +} // namespace Info::Boosts diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp b/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp new file mode 100644 index 000000000..c5b651304 --- /dev/null +++ b/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp @@ -0,0 +1,103 @@ +/* +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 "info/boosts/info_boosts_widget.h" + +#include "info/boosts/info_boosts_inner_widget.h" +#include "info/info_controller.h" +#include "info/info_memento.h" +#include "lang/lang_keys.h" + +namespace Info::Boosts { + +Memento::Memento(not_null controller) +: ContentMemento(Info::Statistics::Tag{ + controller->statisticsPeer(), + {} +}) { +} + +Memento::Memento(not_null peer) +: ContentMemento(Info::Statistics::Tag{ peer, {} }) { +} + +Memento::~Memento() = default; + +Section Memento::section() const { + return Section(Section::Type::Boosts); +} + +object_ptr Memento::createWidget( + QWidget *parent, + not_null controller, + const QRect &geometry) { + auto result = object_ptr(parent, controller); + result->setInternalState(geometry, this); + return result; +} + +Widget::Widget( + QWidget *parent, + not_null controller) +: ContentWidget(parent, controller) +, _inner(setInnerWidget( + object_ptr( + this, + controller, + controller->statisticsPeer()))) { + _inner->showRequests( + ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { + }, _inner->lifetime()); + _inner->scrollToRequests( + ) | rpl::start_with_next([=](const Ui::ScrollToRequest &request) { + scrollTo(request); + }, _inner->lifetime()); +} + +not_null Widget::peer() const { + return _inner->peer(); +} + +bool Widget::showInternal(not_null memento) { + return false; +} + +rpl::producer Widget::title() { + return tr::lng_boosts_title(); +} + +void Widget::setInternalState( + const QRect &geometry, + not_null memento) { + setGeometry(geometry); + Ui::SendPendingMoveResizeEvents(this); + // restoreState(memento); +} + +rpl::producer Widget::desiredShadowVisibility() const { + return rpl::single(true); +} + +void Widget::showFinished() { + _inner->showFinished(); +} + +std::shared_ptr Widget::doCreateMemento() { + auto result = std::make_shared(controller()); + // saveState(result.get()); + return result; +} + +std::shared_ptr Make(not_null peer) { + return std::make_shared( + std::vector>( + 1, + std::make_shared(peer))); +} + +} // namespace Info::Boosts + diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_widget.h b/Telegram/SourceFiles/info/boosts/info_boosts_widget.h new file mode 100644 index 000000000..a53dd07df --- /dev/null +++ b/Telegram/SourceFiles/info/boosts/info_boosts_widget.h @@ -0,0 +1,59 @@ +/* +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 +*/ +#pragma once + +#include "info/info_content_widget.h" + +namespace Info::Boosts { + +class InnerWidget; + +class Memento final : public ContentMemento { +public: + Memento(not_null controller); + Memento(not_null peer); + ~Memento(); + + object_ptr createWidget( + QWidget *parent, + not_null controller, + const QRect &geometry) override; + + Section section() const override; + +}; + +class Widget final : public ContentWidget { +public: + Widget(QWidget *parent, not_null controller); + + bool showInternal(not_null memento) override; + rpl::producer title() override; + rpl::producer desiredShadowVisibility() const override; + void showFinished() override; + + [[nodiscard]] not_null peer() const; + [[nodiscard]] FullMsgId contextId() const; + + void setInternalState( + const QRect &geometry, + not_null memento); + +private: + void saveState(not_null memento); + void restoreState(not_null memento); + + std::shared_ptr doCreateMemento() override; + + const not_null _inner; + +}; + +[[nodiscard]] std::shared_ptr Make(not_null peer); + +} // namespace Info::Boosts diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index 88fbf07ed..cb779f37f 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -125,6 +125,7 @@ public: Stories, PollResults, Statistics, + Boosts, }; using SettingsType = ::Settings::Type; using MediaType = Storage::SharedMediaType;