From b4df7b4efd549b769a04d05ee0d018773bbaa3cb Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 11 May 2019 13:46:04 +0300 Subject: [PATCH] Replaced observable updatedNotifier() with rpl. --- Telegram/SourceFiles/mainwidget.cpp | 9 ++++++--- .../SourceFiles/media/player/media_player_instance.cpp | 2 +- .../SourceFiles/media/player/media_player_instance.h | 8 ++++---- .../SourceFiles/media/player/media_player_widget.cpp | 9 ++++++--- Telegram/SourceFiles/platform/mac/main_window_mac.mm | 5 ----- Telegram/SourceFiles/platform/mac/touchbar.mm | 5 +++++ 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 20de1df4cb..078a3e7630 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -386,9 +386,12 @@ MainWidget::MainWidget( connect(_dialogs, SIGNAL(cancelled()), this, SLOT(dialogsCancelled())); connect(this, SIGNAL(dialogsUpdated()), _dialogs, SLOT(onListScroll())); connect(_history, &HistoryWidget::cancelled, [=] { handleHistoryBack(); }); - subscribe( - Media::Player::instance()->updatedNotifier(), - [=](const Media::Player::TrackState &state) { handleAudioUpdate(state); }); + + Media::Player::instance()->updatedNotifier( + ) | rpl::start_with_next([=](const Media::Player::TrackState &state) { + handleAudioUpdate(state); + }, lifetime()); + subscribe(session().calls().currentCallChanged(), [this](Calls::Call *call) { setCurrentCall(call); }); session().data().currentExportView( diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index 60df88388a..dd4f416632 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -614,7 +614,7 @@ void Instance::emitUpdate(AudioMsgId::Type type, CheckCallback check) { if (data->streamed && !data->streamed->info.video.size.isEmpty()) { data->streamed->progress.updateState(state); } - _updatedNotifier.notify(state, true); + _updatedNotifier.fire_copy({state}); if (data->isPlaying && state.state == State::StoppedAtEnd) { if (data->repeatEnabled) { play(data->current); diff --git a/Telegram/SourceFiles/media/player/media_player_instance.h b/Telegram/SourceFiles/media/player/media_player_instance.h index ccec2dad0d..6441ac2c6c 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.h +++ b/Telegram/SourceFiles/media/player/media_player_instance.h @@ -131,9 +131,6 @@ public: base::Observable &playerWidgetOver() { return _playerWidgetOver; } - base::Observable &updatedNotifier() { - return _updatedNotifier; - } base::Observable &tracksFinishedNotifier() { return _tracksFinishedNotifier; } @@ -152,6 +149,9 @@ public: rpl::producer playerWidgetToggled() const { return _playerWidgetToggled.events(); } + rpl::producer updatedNotifier() const { + return _updatedNotifier.events(); + } void documentLoadProgress(DocumentData *document); @@ -254,12 +254,12 @@ private: base::Observable _switchToNextNotifier; base::Observable _playerWidgetOver; - base::Observable _updatedNotifier; base::Observable _tracksFinishedNotifier; base::Observable _trackChangedNotifier; base::Observable _repeatChangedNotifier; rpl::event_stream _playerWidgetToggled; + rpl::event_stream _updatedNotifier; rpl::lifetime _lifetime; }; diff --git a/Telegram/SourceFiles/media/player/media_player_widget.cpp b/Telegram/SourceFiles/media/player/media_player_widget.cpp index 411a868791..82125d2009 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.cpp +++ b/Telegram/SourceFiles/media/player/media_player_widget.cpp @@ -147,9 +147,6 @@ Widget::Widget(QWidget *parent) : RpWidget(parent) updateRepeatTrackIcon(); } }); - subscribe(instance()->updatedNotifier(), [this](const TrackState &state) { - handleSongUpdate(state); - }); subscribe(instance()->trackChangedNotifier(), [this](AudioMsgId::Type type) { if (type == _type) { handleSongChange(); @@ -165,6 +162,12 @@ Widget::Widget(QWidget *parent) : RpWidget(parent) } } }); + + instance()->updatedNotifier( + ) | rpl::start_with_next([=](const TrackState &state) { + handleSongUpdate(state); + }, lifetime()); + setType(AudioMsgId::Type::Song); _playPause->finishTransform(); } diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 080b384d5c..cf5fa6c363 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -413,11 +413,6 @@ MainWindow::MainWindow() _private->_touchBar = nullptr; } }); - - subscribe(Media::Player::instance()->updatedNotifier(), - [=](const Media::Player::TrackState &state) { - [_private->_touchBar handleTrackStateChange:state]; - }); } void MainWindow::closeWithoutDestroy() { diff --git a/Telegram/SourceFiles/platform/mac/touchbar.mm b/Telegram/SourceFiles/platform/mac/touchbar.mm index 28fbb093e8..083af63ef2 100644 --- a/Telegram/SourceFiles/platform/mac/touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/touchbar.mm @@ -283,6 +283,11 @@ NSString* FormatTime(int time) { [self setTouchBar:TouchBarType::AudioPlayer]; } }, self->lifetime); + + Media::Player::instance()->updatedNotifier( + ) | rpl::start_with_next([=](const Media::Player::TrackState &state) { + [self handleTrackStateChange:state]; + }, self->lifetime); Core::App().passcodeLockChanges( ) | rpl::start_with_next([=](bool locked) {