From 386fae952be0ee3f457b2195d5bb8775e7bf1f93 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 25 May 2021 13:35:38 +0300 Subject: [PATCH] Replaced observable in SessionController with rpl. --- Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp | 5 +++-- Telegram/SourceFiles/chat_helpers/gifs_list_widget.h | 3 +-- Telegram/SourceFiles/history/history_inner_widget.cpp | 8 +++++--- .../SourceFiles/inline_bots/inline_results_inner.cpp | 8 +++++--- .../SourceFiles/inline_bots/inline_results_inner.h | 3 +-- .../SourceFiles/window/window_session_controller.cpp | 10 ++++++---- .../SourceFiles/window/window_session_controller.h | 9 ++++----- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 5e1c93333d..abfde70849 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -188,12 +188,13 @@ GifsListWidget::GifsListWidget( update(); }, lifetime()); - subscribe(controller->gifPauseLevelChanged(), [=] { + controller->gifPauseLevelChanged( + ) | rpl::start_with_next([=] { if (!controller->isGifPausedAtLeastFor( Window::GifPauseReason::SavedGifs)) { update(); } - }); + }, lifetime()); } rpl::producer GifsListWidget::fileChosen() const { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h index 0f1bce421b..279934ea6a 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.h @@ -46,8 +46,7 @@ void AddGifAction( class GifsListWidget : public TabbedSelector::Inner - , public InlineBots::Layout::Context - , private base::Subscriber { + , public InlineBots::Layout::Context { public: using InlineChosen = TabbedSelector::InlineChosen; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index acadfbc67f..5b5a2bc3ad 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -169,11 +169,13 @@ HistoryInner::HistoryInner( notifyIsBotChanged(); setMouseTracking(true); - subscribe(_controller->gifPauseLevelChanged(), [this] { - if (!_controller->isGifPausedAtLeastFor(Window::GifPauseReason::Any)) { + _controller->gifPauseLevelChanged( + ) | rpl::start_with_next([=] { + if (!_controller->isGifPausedAtLeastFor( + Window::GifPauseReason::Any)) { update(); } - }); + }, lifetime()); subscribe(_controller->widget()->dragFinished(), [this] { mouseActionUpdate(QCursor::pos()); }); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp index 48b77fe2e1..fd9b1f9df2 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.cpp @@ -48,11 +48,13 @@ Inner::Inner( update(); }, lifetime()); - subscribe(controller->gifPauseLevelChanged(), [this] { - if (!_controller->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults)) { + controller->gifPauseLevelChanged( + ) | rpl::start_with_next([=] { + if (!_controller->isGifPausedAtLeastFor( + Window::GifPauseReason::InlineResults)) { update(); } - }); + }, lifetime()); _controller->session().changes().peerUpdates( Data::PeerUpdate::Flag::Rights diff --git a/Telegram/SourceFiles/inline_bots/inline_results_inner.h b/Telegram/SourceFiles/inline_bots/inline_results_inner.h index bcf58a49d0..a8932e7668 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_inner.h +++ b/Telegram/SourceFiles/inline_bots/inline_results_inner.h @@ -61,8 +61,7 @@ struct CacheEntry { class Inner : public Ui::RpWidget , public Ui::AbstractTooltipShower - , public Context - , private base::Subscriber { + , public Context { public: Inner(QWidget *parent, not_null controller); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index b6652e6416..310e1d3720 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -465,12 +465,14 @@ SessionController::SessionController( enableGifPauseReason(GifPauseReason::RoundPlaying); } - subscribe(session->api().fullPeerUpdated(), [=](PeerData *peer) { + base::ObservableViewer( + session->api().fullPeerUpdated() + ) | rpl::start_with_next([=](PeerData *peer) { if (peer == _showEditPeer) { _showEditPeer = nullptr; Ui::show(Box(this, peer)); } - }); + }, lifetime()); session->data().chatsListChanges( ) | rpl::filter([=](Data::Folder *folder) { @@ -753,7 +755,7 @@ void SessionController::enableGifPauseReason(GifPauseReason reason) { auto notify = (static_cast(_gifPauseReasons) < static_cast(reason)); _gifPauseReasons |= reason; if (notify) { - _gifPauseLevelChanged.notify(); + _gifPauseLevelChanged.fire({}); } } } @@ -762,7 +764,7 @@ void SessionController::disableGifPauseReason(GifPauseReason reason) { if (_gifPauseReasons & reason) { _gifPauseReasons &= ~reason; if (_gifPauseReasons < reason) { - _gifPauseLevelChanged.notify(); + _gifPauseLevelChanged.fire({}); } } } diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 201b04c9a7..5399ae8b0d 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include "base/flags.h" -#include "base/observer.h" #include "base/object_ptr.h" #include "base/weak_ptr.h" #include "base/timer.h" @@ -227,7 +226,7 @@ private: }; -class SessionController : public SessionNavigation, private base::Subscriber { +class SessionController : public SessionNavigation { public: SessionController( not_null session, @@ -275,8 +274,8 @@ public: void enableGifPauseReason(GifPauseReason reason); void disableGifPauseReason(GifPauseReason reason); - base::Observable &gifPauseLevelChanged() { - return _gifPauseLevelChanged; + rpl::producer<> gifPauseLevelChanged() const { + return _gifPauseLevelChanged.events(); } bool isGifPausedAtLeastFor(GifPauseReason reason) const; void floatPlayerAreaUpdated(); @@ -406,7 +405,7 @@ private: std::unique_ptr _filters; GifPauseReasons _gifPauseReasons = 0; - base::Observable _gifPauseLevelChanged; + rpl::event_stream<> _gifPauseLevelChanged; // Depends on _gifPause*. const std::unique_ptr _tabbedSelector;