diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index d87aca158e..2e04dd2e6f 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -149,12 +149,8 @@ Application::~Application() { // Depend on activeWindow() for now :( Shortcuts::Finish(); - _window.reset(); - - if (_mediaView) { - _mediaView->clearData(); - _mediaView = nullptr; - } + _window = nullptr; + _mediaView = nullptr; _domain->finish(); Local::finish(); diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index 4962508025..b7eebe925b 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -153,7 +153,6 @@ public: } base::Observable documentUpdated; - base::Observable, MsgId>> messageIdChanging; bool supportMode() const; Support::Helper &supportHelper() const; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 19d3b922b4..40e3f6f90b 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -321,46 +321,6 @@ OverlayWidget::OverlayWidget() connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); - // While we have one mediaview for all sessions we have to do this. - Core::App().domain().activeSessionValue( - ) | rpl::start_with_next([=](Main::Session *session) { - if (!isHidden()) { - close(); - } - clearData(); - setWindowIcon(Window::CreateIcon(session)); - if (session) { - // #TODO multi - subscribe(session->downloaderTaskFinished(), [=] { - if (!isHidden()) { - updateControls(); - } - }); - subscribe(session->calls().currentCallChanged(), [=](Calls::Call *call) { - if (!_streamed) { - return; - } - if (call) { - playbackPauseOnCall(); - } else { - playbackResumeOnCall(); - } - }); - subscribe(session->documentUpdated, [=](DocumentData *document) { - if (!isHidden()) { - documentUpdated(document); - } - }); - subscribe(session->messageIdChanging, [=](std::pair, MsgId> update) { - changingMsgId(update.first, update.second); - }); - } else { - _sharedMedia = nullptr; - _userPhotos = nullptr; - _collage = nullptr; - } - }, lifetime()); - #if defined Q_OS_UNIX && !defined Q_OS_MAC setWindowFlags(Qt::FramelessWindowHint | Qt::MaximizeUsingFullscreenGeometryHint); #else // Q_OS_UNIX && !Q_OS_MAC @@ -554,9 +514,9 @@ void OverlayWidget::documentUpdated(DocumentData *doc) { } } -void OverlayWidget::changingMsgId(not_null row, MsgId newId) { - if (row->fullId() == _msgid) { - _msgid = FullMsgId(_msgid.channel, newId); +void OverlayWidget::changingMsgId(not_null row, MsgId oldId) { + if (FullMsgId(row->channelId(), oldId) == _msgid) { + _msgid = row->fullId(); refreshMediaViewer(); } } @@ -1090,10 +1050,11 @@ void OverlayWidget::zoomUpdate(int32 &newZoom) { setZoomLevel(newZoom); } -void OverlayWidget::clearData() { +void OverlayWidget::clearSession() { if (!isHidden()) { hide(); } + _sessionLifetime.destroy(); if (!_animations.empty()) { _animations.clear(); _stateAnimation.stop(); @@ -1111,11 +1072,14 @@ void OverlayWidget::clearData() { _pip = nullptr; _fullScreenVideo = false; _caption.clear(); + _sharedMedia = nullptr; + _userPhotos = nullptr; + _collage = nullptr; _session = nullptr; } OverlayWidget::~OverlayWidget() { - delete base::take(_menu); + clearSession(); } void OverlayWidget::assignMediaPointer(DocumentData *document) { @@ -1963,8 +1927,10 @@ void OverlayWidget::clearControlsState() { } } -void OverlayWidget::showPhoto(not_null photo, HistoryItem *context) { - _session = &photo->session(); +void OverlayWidget::showPhoto( + not_null photo, + HistoryItem *context) { + setSession(&photo->session()); if (context) { setContext(context); @@ -1981,9 +1947,10 @@ void OverlayWidget::showPhoto(not_null photo, HistoryItem *context) activateControls(); } -void OverlayWidget::showPhoto(not_null photo, not_null context) { - _session = &photo->session(); - +void OverlayWidget::showPhoto( + not_null photo, + not_null context) { + setSession(&photo->session()); setContext(context); clearControlsState(); @@ -2012,7 +1979,7 @@ void OverlayWidget::showDocument( HistoryItem *context, const Data::CloudTheme &cloud, bool continueStreaming) { - _session = &document->session(); + setSession(&document->session()); if (context) { setContext(context); @@ -3545,6 +3512,59 @@ void OverlayWidget::setContext( _user = _peer ? _peer->asUser() : nullptr; } +void OverlayWidget::setSession(not_null session) { + if (_session == session) { + return; + } + + clearSession(); + _session = session; + setWindowIcon(Window::CreateIcon(session)); + + base::ObservableViewer( + session->downloaderTaskFinished() + ) | rpl::start_with_next([=] { + if (!isHidden()) { + updateControls(); + } + }, _sessionLifetime); + + base::ObservableViewer( + session->calls().currentCallChanged() + ) | rpl::start_with_next([=](Calls::Call *call) { + if (!_streamed) { + return; + } + if (call) { + playbackPauseOnCall(); + } else { + playbackResumeOnCall(); + } + }, _sessionLifetime); + + base::ObservableViewer( + session->documentUpdated + ) | rpl::start_with_next([=](DocumentData *document) { + if (!isHidden()) { + documentUpdated(document); + } + }, _sessionLifetime); + + session->data().itemIdChanged( + ) | rpl::start_with_next([=](const Data::Session::IdChange &change) { + changingMsgId(change.item, change.oldId); + }, _sessionLifetime); + + session->account().sessionChanges( + ) | rpl::start_with_next_done([=](Main::Session *value) { + if (value != session) { + clearSession(); + } + }, [=] { + clearSession(); + }, _sessionLifetime); +} + bool OverlayWidget::moveToNext(int delta) { if (!_index) { return false; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h index 43491bccd8..c1519b8926 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.h +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.h @@ -96,7 +96,7 @@ public: void notifyFileDialogShown(bool shown); - void clearData(); + void clearSession(); ~OverlayWidget(); @@ -169,6 +169,8 @@ private: void setVisibleHook(bool visible) override; + void setSession(not_null session); + void playbackControlsPlay() override; void playbackControlsPause() override; void playbackControlsSeekProgress(crl::time position) override; @@ -288,7 +290,7 @@ private: void updateThemePreviewGeometry(); void documentUpdated(DocumentData *doc); - void changingMsgId(not_null row, MsgId newId); + void changingMsgId(not_null row, MsgId oldId); [[nodiscard]] int contentRotation() const; [[nodiscard]] QRect contentRect() const; @@ -352,6 +354,7 @@ private: QBrush _transparentBrush; Main::Session *_session = nullptr; + rpl::lifetime _sessionLifetime; PhotoData *_photo = nullptr; DocumentData *_document = nullptr; std::shared_ptr _photoMedia;