diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 891f9e209..9997e77de 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -1364,7 +1364,10 @@ void RevokePublicLinkBox::prepare() { addButton(tr::lng_cancel(), [=] { closeBox(); }); - subscribe(_session->downloaderTaskFinished(), [=] { update(); }); + _session->downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); _inner->resizeToWidth(st::boxWideWidth); setDimensions(st::boxWideWidth, _innerTop + _inner->height()); diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 7f47d003a..6b729c03e 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -203,7 +203,10 @@ BackgroundBox::Inner::Inner( } requestPapers(); - subscribe(_session->downloaderTaskFinished(), [=] { update(); }); + _session->downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); using Update = Window::Theme::BackgroundUpdate; subscribe(Window::Theme::Background(), [=](const Update &update) { if (update.paletteChanged()) { diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index e3f45eae5..afffec247 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -419,9 +419,10 @@ BackgroundPreviewBox::BackgroundPreviewBox( if (_media) { _media->thumbnailWanted(_paper.fileOrigin()); } - subscribe(_controller->session().downloaderTaskFinished(), [=] { + _controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); } not_null BackgroundPreviewBox::delegate() { diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 15c8cdcdf..d0964956d 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -891,9 +891,10 @@ ConfirmInviteBox::ConfirmInviteBox( _photo = photo->createMediaView(); _photo->wanted(Data::PhotoSize::Small, Data::FileOrigin()); if (!_photo->image(Data::PhotoSize::Small)) { - subscribe(_session->downloaderTaskFinished(), [=] { + _session->downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); } } else { _photoEmpty = std::make_unique( diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 0c331acfa..2c32e27b5 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -291,7 +291,8 @@ EditCaptionBox::EditCaptionBox( Assert(_thumbnailImageLoaded || _refreshThumbnail); if (!_thumbnailImageLoaded) { - subscribe(_controller->session().downloaderTaskFinished(), [=] { + _controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { if (_thumbnailImageLoaded || (_photoMedia && !_photoMedia->image(PhotoSize::Large)) || (_documentMedia && !_documentMedia->thumbnail())) { @@ -299,7 +300,7 @@ EditCaptionBox::EditCaptionBox( } _refreshThumbnail(); update(); - }); + }, lifetime()); } _field.create( this, diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index a866b8a23..b227e6040 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -662,9 +662,10 @@ PeerListContent::PeerListContent( , _st(st) , _controller(controller) , _rowHeight(_st.item.height) { - subscribe(_controller->session().downloaderTaskFinished(), [=] { + _controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); using UpdateFlag = Data::PeerUpdate::Flag; _controller->session().changes().peerUpdates( diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 11f1264a5..006a8307d 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -570,9 +570,10 @@ ShareBox::Inner::Inner( update.oldFirstLetters); }, lifetime()); - subscribe(_navigation->session().downloaderTaskFinished(), [=] { + _navigation->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { if (update.paletteChanged()) { diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 7359a6e00..1e82dfe25 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -254,7 +254,10 @@ StickerSetBox::Inner::Inner( _controller->session().api().updateStickers(); - subscribe(_controller->session().downloaderTaskFinished(), [this] { update(); }); + _controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); setMouseTracking(true); } diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 4654798e7..f74aa951e 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -1002,10 +1002,12 @@ Main::Session &StickersBox::Inner::session() const { } void StickersBox::Inner::setup() { - subscribe(session().downloaderTaskFinished(), [this] { + session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); readVisibleSets(); - }); + }, lifetime()); + setMouseTracking(true); } diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp index 1442e8894..b44612e63 100644 --- a/Telegram/SourceFiles/calls/calls_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_panel.cpp @@ -446,9 +446,10 @@ void Panel::initLayout() { }, lifetime()); processUserPhoto(); - subscribe(_user->session().downloaderTaskFinished(), [=] { + _user->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { refreshUserPhoto(); - }); + }, lifetime()); createDefaultCacheImage(); Ui::Platform::InitOnTopPanel(this); diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 790adb725..f76d8b5a4 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -604,9 +604,10 @@ FieldAutocompleteInner::FieldAutocompleteInner( , _brows(brows) , _srows(srows) , _previewTimer([=] { showPreview(); }) { - subscribe( - controller->session().downloaderTaskFinished(), - [=] { update(); }); + controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); } void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { diff --git a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp index 1418490ce..526c17e08 100644 --- a/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/gifs_list_widget.cpp @@ -153,9 +153,10 @@ GifsListWidget::GifsListWidget( refreshSavedGifs(); }, lifetime()); - subscribe(controller->session().downloaderTaskFinished(), [this] { + controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); subscribe(controller->gifPauseLevelChanged(), [=] { if (!controller->isGifPausedAtLeastFor( diff --git a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp index 9c4be2153..691144550 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.cpp @@ -198,7 +198,7 @@ std::shared_ptr EmojiPack::image(EmojiPtr emoji) { if (!strong->image) { strong->load = nullptr; strong->image.emplace(std::move(image)); - _session->downloaderTaskFinished().notify(); + _session->notifyDownloaderTaskFinished(); } } } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 101ce96c8..e621f0ab2 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -105,9 +105,7 @@ struct StickerIcon { }; -class StickersListWidget::Footer - : public TabbedSelector::InnerFooter - , private base::Subscriber { +class StickersListWidget::Footer : public TabbedSelector::InnerFooter { public: explicit Footer(not_null parent); @@ -132,7 +130,7 @@ protected: void mousePressEvent(QMouseEvent *e) override; void mouseMoveEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override; - bool event(QEvent *e) override; + bool eventHook(QEvent *e) override; void processHideFinished() override; @@ -249,9 +247,10 @@ StickersListWidget::Footer::Footer(not_null parent) _iconsLeft = _iconsRight = st::emojiCategorySkip + st::stickerIconWidth; - subscribe(_pan->session().downloaderTaskFinished(), [=] { + _pan->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); } void StickersListWidget::Footer::clearHeavyData() { @@ -600,7 +599,7 @@ void StickersListWidget::Footer::finishDragging() { updateSelected(); } -bool StickersListWidget::Footer::event(QEvent *e) { +bool StickersListWidget::Footer::eventHook(QEvent *e) { if (e->type() == QEvent::TouchBegin) { } else if (e->type() == QEvent::Wheel) { if (!_icons.empty() @@ -609,7 +608,7 @@ bool StickersListWidget::Footer::event(QEvent *e) { scrollByWheelEvent(static_cast(e)); } } - return InnerFooter::event(e); + return InnerFooter::eventHook(e); } void StickersListWidget::Footer::scrollByWheelEvent( @@ -890,12 +889,13 @@ StickersListWidget::StickersListWidget( Box(controller, StickersBox::Section::Installed)); }); - subscribe(session().downloaderTaskFinished(), [=] { + session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { if (isVisible()) { update(); readVisibleFeatured(getVisibleTop(), getVisibleBottom()); } - }); + }, lifetime()); session().changes().peerUpdates( Data::PeerUpdate::Flag::StickersSet diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 045b28d99..6707f5da0 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -938,7 +938,7 @@ void TabbedSelector::Inner::panelHideFinished() { } TabbedSelector::InnerFooter::InnerFooter(QWidget *parent) -: TWidget(parent) { +: RpWidget(parent) { resize(st::emojiPanWidth, st::emojiFooterHeight); } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 0b3bfd305..6f78129e4 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -276,7 +276,7 @@ private: }; -class TabbedSelector::InnerFooter : public TWidget { +class TabbedSelector::InnerFooter : public Ui::RpWidget { public: InnerFooter(QWidget *parent); diff --git a/Telegram/SourceFiles/data/data_cloud_file.cpp b/Telegram/SourceFiles/data/data_cloud_file.cpp index e4051871d..b2c3679b4 100644 --- a/Telegram/SourceFiles/data/data_cloud_file.cpp +++ b/Telegram/SourceFiles/data/data_cloud_file.cpp @@ -26,7 +26,7 @@ void CloudImageView::set( not_null session, QImage image) { _image.emplace(std::move(image)); - session->downloaderTaskFinished().notify(); + session->notifyDownloaderTaskFinished(); } CloudImage::CloudImage() = default; diff --git a/Telegram/SourceFiles/data/data_cloud_themes.cpp b/Telegram/SourceFiles/data/data_cloud_themes.cpp index e4c3a724e..f23664d15 100644 --- a/Telegram/SourceFiles/data/data_cloud_themes.cpp +++ b/Telegram/SourceFiles/data/data_cloud_themes.cpp @@ -222,8 +222,7 @@ void CloudThemes::loadDocumentAndInvoke( return; } if (!alreadyWaiting) { - base::ObservableViewer( - _session->downloaderTaskFinished() + _session->downloaderTaskFinished( ) | rpl::filter([=, &value] { return value.documentMedia->loaded(); }) | rpl::start_with_next([=, &value] { diff --git a/Telegram/SourceFiles/data/data_document_media.cpp b/Telegram/SourceFiles/data/data_document_media.cpp index d8c222cba..51c890006 100644 --- a/Telegram/SourceFiles/data/data_document_media.cpp +++ b/Telegram/SourceFiles/data/data_document_media.cpp @@ -168,7 +168,7 @@ void DocumentMedia::setGoodThumbnail(QImage thumbnail) { return; } _goodThumbnail = std::make_unique(std::move(thumbnail)); - _owner->session().downloaderTaskFinished().notify(); + _owner->session().notifyDownloaderTaskFinished(); } Image *DocumentMedia::thumbnailInline() const { @@ -206,7 +206,7 @@ QSize DocumentMedia::thumbnailSize() const { void DocumentMedia::setThumbnail(QImage thumbnail) { _thumbnail = std::make_unique(std::move(thumbnail)); - _owner->session().downloaderTaskFinished().notify(); + _owner->session().notifyDownloaderTaskFinished(); } QByteArray DocumentMedia::videoThumbnailContent() const { diff --git a/Telegram/SourceFiles/data/data_photo_media.cpp b/Telegram/SourceFiles/data/data_photo_media.cpp index 0f5a908d3..1cf701921 100644 --- a/Telegram/SourceFiles/data/data_photo_media.cpp +++ b/Telegram/SourceFiles/data/data_photo_media.cpp @@ -82,7 +82,7 @@ void PhotoMedia::set(PhotoSize size, QImage image) { Qt::SmoothTransformation); } _images[index] = std::make_unique(std::move(image)); - _owner->session().downloaderTaskFinished().notify(); + _owner->session().notifyDownloaderTaskFinished(); } bool PhotoMedia::loaded() const { diff --git a/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp b/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp index 6c922191d..f9444cbb1 100644 --- a/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp +++ b/Telegram/SourceFiles/data/stickers/data_stickers_set.cpp @@ -34,7 +34,7 @@ void StickersSetThumbnailView::set( } else { _image = std::make_unique(std::move(image)); } - session->downloaderTaskFinished().notify(); + session->notifyDownloaderTaskFinished(); } Image *StickersSetThumbnailView::image() const { diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index a64d7f9bb..c5bb51fda 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -132,7 +132,10 @@ InnerWidget::InnerWidget( }); _cancelSearchFromUser->hide(); - subscribe(session().downloaderTaskFinished(), [=] { update(); }); + session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); subscribe(Core::App().notifications().settingsChanged(), [=]( Window::Notifications::ChangeType change) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 5391be57c..e6751e62a 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -305,7 +305,11 @@ HistoryWidget::HistoryWidget( , _topShadow(this) { setAcceptDrops(true); - subscribe(session().downloaderTaskFinished(), [=] { update(); }); + session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); + connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll())); _historyDown->addClickHandler([=] { historyDownClicked(); }); _unreadMentions->addClickHandler([=] { showNextUnreadMention(); }); diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 7ad029129..e3bcb5984 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -585,21 +585,27 @@ void ListWidget::start() { invalidatePaletteCache(); } }, lifetime()); - ObservableViewer( - session().downloaderTaskFinished() - ) | rpl::start_with_next([this] { update(); }, lifetime()); + + session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); + session().data().itemLayoutChanged( ) | rpl::start_with_next([this](auto item) { itemLayoutChanged(item); }, lifetime()); + session().data().itemRemoved( ) | rpl::start_with_next([this](auto item) { itemRemoved(item); }, lifetime()); + session().data().itemRepaintRequest( ) | rpl::start_with_next([this](auto item) { repaintItem(item); }, lifetime()); + _controller->mediaSourceQueryValue( ) | rpl::start_with_next([this]{ restart(); diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index f8f3252a1..23aee7c0e 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -58,9 +58,11 @@ Inner::Inner( setMouseTracking(true); setAttribute(Qt::WA_OpaquePaintEvent); - subscribe(_controller->session().downloaderTaskFinished(), [this] { + _controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); + subscribe(controller->gifPauseLevelChanged(), [this] { if (!_controller->isGifPausedAtLeastFor(Window::GifPauseReason::InlineResults)) { update(); diff --git a/Telegram/SourceFiles/main/main_session.cpp b/Telegram/SourceFiles/main/main_session.cpp index c080a6658..95f637d3e 100644 --- a/Telegram/SourceFiles/main/main_session.cpp +++ b/Telegram/SourceFiles/main/main_session.cpp @@ -181,7 +181,11 @@ Storage::Domain &Session::domainLocal() const { return _account->domainLocal(); } -base::Observable &Session::downloaderTaskFinished() { +void Session::notifyDownloaderTaskFinished() { + downloader().notifyTaskFinished(); +} + +rpl::producer<> Session::downloaderTaskFinished() const { return downloader().taskFinished(); } diff --git a/Telegram/SourceFiles/main/main_session.h b/Telegram/SourceFiles/main/main_session.h index 428f31468..01ad24f0a 100644 --- a/Telegram/SourceFiles/main/main_session.h +++ b/Telegram/SourceFiles/main/main_session.h @@ -121,7 +121,8 @@ public: -> const base::flat_set> &; // Shortcuts. - [[nodiscard]] base::Observable &downloaderTaskFinished(); + void notifyDownloaderTaskFinished(); + [[nodiscard]] rpl::producer<> downloaderTaskFinished() const; [[nodiscard]] MTP::DcId mainDcId() const; [[nodiscard]] MTP::Instance &mtp() const; [[nodiscard]] const MTP::ConfigFields &serverConfig() const; diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 1700cba3d..d34ddafbc 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -3530,8 +3530,7 @@ void OverlayWidget::setSession(not_null session) { _session = session; setWindowIcon(Window::CreateIcon(session)); - base::ObservableViewer( - session->downloaderTaskFinished() + session->downloaderTaskFinished( ) | rpl::start_with_next([=] { if (!isHidden()) { updateControls(); diff --git a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm index cf5c06f1d..7d59280d3 100644 --- a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm @@ -812,8 +812,7 @@ void AppendEmojiPacks( [self setNeedsDisplayInRect:PeerRectByIndex(userpicIndex)]; }; const auto listenToDownloaderFinished = [=] { - base::ObservableViewer( - _session->downloaderTaskFinished() + _session->downloaderTaskFinished( ) | rpl::start_with_next([=] { const auto all = ranges::all_of(_pins, [=](const auto &pin) { return (!pin->peer->hasUserpic()) @@ -1193,8 +1192,7 @@ void AppendEmojiPacks( [self updateImage]; return; } - base::ObservableViewer( - document->session().downloaderTaskFinished() + document->session().downloaderTaskFinished( ) | rpl::start_with_next([=] { _image = _media->getStickerSmall(); if (_image) { diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index 794fb24e6..23e9e8596 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -33,7 +33,11 @@ PeerListWidget::PeerListWidget( , _removeText(removeText) , _removeWidth(st::normalFont->width(_removeText)) { setMouseTracking(true); - subscribe(peer->session().downloaderTaskFinished(), [=] { update(); }); + + peer->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); } int PeerListWidget::resizeGetHeight(int newWidth) { diff --git a/Telegram/SourceFiles/storage/download_manager_mtproto.h b/Telegram/SourceFiles/storage/download_manager_mtproto.h index 41f91b32c..ea4baa44b 100644 --- a/Telegram/SourceFiles/storage/download_manager_mtproto.h +++ b/Telegram/SourceFiles/storage/download_manager_mtproto.h @@ -38,8 +38,11 @@ public: void enqueue(not_null task, int priority); void remove(not_null task); - [[nodiscard]] base::Observable &taskFinished() { - return _taskFinishedObservable; + void notifyTaskFinished() { + _taskFinished.fire({}); + } + [[nodiscard]] rpl::producer<> taskFinished() const { + return _taskFinished.events(); } int changeRequestedAmount(MTP::DcId dcId, int index, int delta); @@ -101,7 +104,7 @@ private: const not_null _api; - base::Observable _taskFinishedObservable; + rpl::event_stream<> _taskFinished; base::flat_map _balanceData; base::Timer _resetGenerationTimer; diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index d78a8ab36..8164c9690 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -140,7 +140,7 @@ void FileLoader::finishWithBytes(const QByteArray &data) { Platform::File::PostprocessDownloaded( QFileInfo(_file).absoluteFilePath()); } - _session->downloaderTaskFinished().notify(); + _session->notifyDownloaderTaskFinished(); _updates.fire_done(); } @@ -440,7 +440,7 @@ bool FileLoader::finalizeResult() { _cacheTag)); } } - _session->downloaderTaskFinished().notify(); + _session->notifyDownloaderTaskFinished(); _updates.fire_done(); return true; } diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 95761541d..a450730ea 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -639,8 +639,7 @@ void UserpicButton::setupPeerViewers() { update(); }, lifetime()); - base::ObservableViewer( - _peer->session().downloaderTaskFinished() + _peer->session().downloaderTaskFinished( ) | rpl::filter([=] { return _waiting; }) | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 2932e89ae..b159f6c6a 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_theme.h" #include "storage/file_download.h" #include "main/main_session.h" +#include "main/main_account.h" #include "history/history.h" #include "history/history_item.h" #include "platform/platform_specific.h" @@ -229,14 +230,16 @@ void Manager::showNextFromQueue() { void Manager::subscribeToSession(not_null session) { auto i = _subscriptions.find(session); if (i == _subscriptions.end()) { - i = _subscriptions.emplace(session, base::Subscription()).first; - session->lifetime().add([=] { + i = _subscriptions.emplace(session).first; + session->account().sessionChanges( + ) | rpl::start_with_next([=] { _subscriptions.remove(session); - }); - } else if (i->second) { + }, i->second.lifetime); + } else if (i->second.subscription) { return; } - i->second = session->downloaderTaskFinished().add_subscription([=] { + session->downloaderTaskFinished( + ) | rpl::start_with_next([=] { auto found = false; for (const auto ¬ification : _notifications) { if (const auto history = notification->maybeHistory()) { @@ -247,9 +250,9 @@ void Manager::subscribeToSession(not_null session) { } } if (!found) { - _subscriptions[session].destroy(); + _subscriptions[session].subscription.destroy(); } - }); + }, i->second.subscription); } void Manager::moveWidgets() { diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index 34307b586..78d3046b2 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -56,6 +56,10 @@ private: friend class internal::Widget; using Notification = internal::Notification; using HideAllButton = internal::HideAllButton; + struct SessionSubscription { + rpl::lifetime subscription; + rpl::lifetime lifetime; + }; [[nodiscard]] QPixmap hiddenUserpicPlaceholder() const; @@ -91,7 +95,7 @@ private: std::vector> _notifications; base::flat_map< not_null, - base::Subscription> _subscriptions; + SessionSubscription> _subscriptions; std::unique_ptr _hideAll; diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index fa04fbd81..a620abe79 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -666,8 +666,7 @@ void CloudList::subscribeToDownloadFinished() { if (_downloadFinishedLifetime) { return; } - base::ObservableViewer( - _window->session().downloaderTaskFinished() + _window->session().downloaderTaskFinished( ) | rpl::start_with_next([=] { auto &&waiting = _elements | ranges::view::filter(&Element::waiting); const auto still = ranges::count_if(waiting, [&](Element &element) { diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index b4723b80c..1ca3265f4 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -580,7 +580,10 @@ MainMenu::MainMenu( _version->setLink(1, std::make_shared(qsl("https://desktop.telegram.org/changelog"))); _version->setLink(2, std::make_shared([] { Ui::show(Box()); })); - subscribe(_controller->session().downloaderTaskFinished(), [=] { update(); }); + _controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { + update(); + }, lifetime()); _controller->session().changes().peerUpdates( _controller->session().user(), diff --git a/Telegram/SourceFiles/window/window_media_preview.cpp b/Telegram/SourceFiles/window/window_media_preview.cpp index 2b571a371..c1c28f640 100644 --- a/Telegram/SourceFiles/window/window_media_preview.cpp +++ b/Telegram/SourceFiles/window/window_media_preview.cpp @@ -36,9 +36,10 @@ MediaPreviewWidget::MediaPreviewWidget( , _controller(controller) , _emojiSize(Ui::Emoji::GetSizeLarge() / cIntRetinaFactor()) { setAttribute(Qt::WA_TransparentForMouseEvents); - subscribe(_controller->session().downloaderTaskFinished(), [=] { + _controller->session().downloaderTaskFinished( + ) | rpl::start_with_next([=] { update(); - }); + }, lifetime()); } QRect MediaPreviewWidget::updateArea() const {