From 4a60c5766174bd576394ee29d34f9fd801422f70 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 19 Jun 2024 04:53:33 +0300 Subject: [PATCH] Added dummy files of bot earn section. --- Telegram/CMakeLists.txt | 4 + Telegram/Resources/langs/lang.strings | 2 + .../info/bot/earn/info_earn_inner_widget.cpp | 69 ++++++++++ .../info/bot/earn/info_earn_inner_widget.h | 69 ++++++++++ .../info/bot/earn/info_earn_widget.cpp | 125 ++++++++++++++++++ .../info/bot/earn/info_earn_widget.h | 68 ++++++++++ Telegram/SourceFiles/info/info_controller.h | 1 + 7 files changed, 338 insertions(+) create mode 100644 Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.cpp create mode 100644 Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.h create mode 100644 Telegram/SourceFiles/info/bot/earn/info_earn_widget.cpp create mode 100644 Telegram/SourceFiles/info/bot/earn/info_earn_widget.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 6c4bce205..39dc186cc 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -887,6 +887,10 @@ PRIVATE history/history_view_highlight_manager.h history/history_widget.cpp history/history_widget.h + info/bot/earn/info_earn_inner_widget.cpp + info/bot/earn/info_earn_inner_widget.h + info/bot/earn/info_earn_widget.cpp + info/bot/earn/info_earn_widget.h info/channel_statistics/boosts/create_giveaway_box.cpp info/channel_statistics/boosts/create_giveaway_box.h info/channel_statistics/boosts/giveaway/giveaway_list_controllers.cpp diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7d7ff8f2d..ce2f75f76 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -5186,6 +5186,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_channel_earn_chart_overriden_detail_currency" = "Revenue in TON"; "lng_channel_earn_chart_overriden_detail_usd" = "Revenue in USD"; +"lng_bot_earn_title" = "Stars Balance"; + "lng_contact_add" = "Add"; "lng_contact_send_message" = "message"; diff --git a/Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.cpp b/Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.cpp new file mode 100644 index 000000000..04c134a07 --- /dev/null +++ b/Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.cpp @@ -0,0 +1,69 @@ +/* +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/bot/earn/info_earn_inner_widget.h" + +#include "data/data_user.h" +#include "info/bot/earn/info_earn_widget.h" +#include "info/info_controller.h" + +namespace Info::BotEarn { +namespace { +} // namespace + +InnerWidget::InnerWidget( + QWidget *parent, + not_null controller, + not_null peer) +: VerticalLayout(parent) +, _controller(controller) +, _peer(peer) +, _show(controller->uiShow()) { +} + +void InnerWidget::load() { +} + +void InnerWidget::fill() { +} + +void InnerWidget::saveState(not_null memento) { + memento->setState(base::take(_state)); +} + +void InnerWidget::restoreState(not_null memento) { + _state = memento->state(); + if (_state) { + fill(); + } else { + load(); + } + Ui::RpWidget::resizeToWidth(width()); +} + +rpl::producer InnerWidget::scrollToRequests() const { + return _scrollToRequests.events(); +} + +auto InnerWidget::showRequests() const -> rpl::producer { + return _showRequests.events(); +} + +void InnerWidget::showFinished() { + _showFinished.fire({}); +} + +void InnerWidget::setInnerFocus() { + _focusRequested.fire({}); +} + +not_null InnerWidget::peer() const { + return _peer; +} + +} // namespace Info::BotEarn + diff --git a/Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.h b/Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.h new file mode 100644 index 000000000..b121b3dc0 --- /dev/null +++ b/Telegram/SourceFiles/info/bot/earn/info_earn_inner_widget.h @@ -0,0 +1,69 @@ +/* +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 "data/data_channel_earn.h" +#include "ui/widgets/scroll_area.h" +#include "ui/wrap/vertical_layout.h" + +namespace Ui { +class Show; +} // namespace Ui + +namespace Info { +class Controller; +} // namespace Info + +namespace Info::BotEarn { + +class Memento; + +[[nodiscard]] QImage IconCurrency( + const style::FlatLabel &label, + const QColor &c); + +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(); + void setInnerFocus(); + + void saveState(not_null memento); + void restoreState(not_null memento); + +private: + void load(); + void fill(); + + not_null _controller; + not_null _peer; + std::shared_ptr _show; + + Data::EarnStatistics _state; + + rpl::event_stream _scrollToRequests; + rpl::event_stream _showRequests; + rpl::event_stream<> _showFinished; + rpl::event_stream<> _focusRequested; + rpl::event_stream _loaded; + +}; + +} // namespace Info::BotEarn diff --git a/Telegram/SourceFiles/info/bot/earn/info_earn_widget.cpp b/Telegram/SourceFiles/info/bot/earn/info_earn_widget.cpp new file mode 100644 index 000000000..59ddb37aa --- /dev/null +++ b/Telegram/SourceFiles/info/bot/earn/info_earn_widget.cpp @@ -0,0 +1,125 @@ +/* +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/bot/earn/info_earn_widget.h" + +#include "info/bot/earn/info_earn_inner_widget.h" +#include "info/info_controller.h" +#include "info/info_memento.h" +#include "lang/lang_keys.h" + +namespace Info::BotEarn { + +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::BotEarn); +} + +void Memento::setState(SavedState state) { + _state = std::move(state); +} + +Memento::SavedState Memento::state() { + return base::take(_state); +} + +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 (memento->statisticsPeer() == peer()); +} + +rpl::producer Widget::title() { + return tr::lng_bot_earn_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(); +} + +void Widget::setInnerFocus() { + _inner->setInnerFocus(); +} + +std::shared_ptr Widget::doCreateMemento() { + auto result = std::make_shared(controller()); + saveState(result.get()); + return result; +} + +void Widget::saveState(not_null memento) { + memento->setScrollTop(scrollTopSave()); + _inner->saveState(memento); +} + +void Widget::restoreState(not_null memento) { + _inner->restoreState(memento); + scrollTopRestore(memento->scrollTop()); +} + +std::shared_ptr Make(not_null peer) { + return std::make_shared( + std::vector>( + 1, + std::make_shared(peer))); +} + +} // namespace Info::BotEarn diff --git a/Telegram/SourceFiles/info/bot/earn/info_earn_widget.h b/Telegram/SourceFiles/info/bot/earn/info_earn_widget.h new file mode 100644 index 000000000..f66d8b39f --- /dev/null +++ b/Telegram/SourceFiles/info/bot/earn/info_earn_widget.h @@ -0,0 +1,68 @@ +/* +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 "data/data_channel_earn.h" +#include "info/info_content_widget.h" + +namespace Info::BotEarn { + +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; + + using SavedState = Data::EarnStatistics; + + void setState(SavedState states); + [[nodiscard]] SavedState state(); + +private: + SavedState _state; + +}; + +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; + void setInnerFocus() override; + + [[nodiscard]] not_null peer() 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::BotEarn diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index 628d50bca..de0337d26 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -135,6 +135,7 @@ public: Statistics, Boosts, ChannelEarn, + BotEarn, }; using SettingsType = ::Settings::Type; using MediaType = Storage::SharedMediaType;