diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 3640db677..087a53798 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -235,6 +235,7 @@ MediaPhoto::MediaPhoto( not_null photo) : Media(parent) , _photo(photo) { + Auth().data().registerPhotoItem(_photo, parent); } MediaPhoto::MediaPhoto( @@ -244,9 +245,11 @@ MediaPhoto::MediaPhoto( : Media(parent) , _photo(photo) , _chat(chat) { + Auth().data().registerPhotoItem(_photo, parent); } MediaPhoto::~MediaPhoto() { + Auth().data().unregisterPhotoItem(_photo, parent()); } std::unique_ptr MediaPhoto::clone(not_null parent) { diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 217fc9973..9fb4df499 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -107,19 +107,19 @@ void Session::animationLoadSettingsChanged() { } void Session::notifyPhotoLayoutChanged(not_null photo) { - if (const auto i = _photoViews.find(photo); i != end(_photoViews)) { - for (const auto view : i->second) { - notifyViewLayoutChange(view); + if (const auto i = _photoItems.find(photo); i != end(_photoItems)) { + for (const auto item : i->second) { + notifyItemLayoutChange(item); } } } void Session::notifyDocumentLayoutChanged( not_null document) { - const auto i = _documentViews.find(document); - if (i != end(_documentViews)) { - for (const auto view : i->second) { - notifyViewLayoutChange(view); + const auto i = _documentItems.find(document); + if (i != end(_documentItems)) { + for (const auto item : i->second) { + notifyItemLayoutChange(item); } } if (const auto items = InlineBots::Layout::documentItems()) { @@ -133,10 +133,10 @@ void Session::notifyDocumentLayoutChanged( void Session::requestDocumentViewRepaint( not_null document) { - const auto i = _documentViews.find(document); - if (i != end(_documentViews)) { - for (const auto view : i->second) { - requestViewRepaint(view); + const auto i = _documentItems.find(document); + if (i != end(_documentItems)) { + for (const auto item : i->second) { + requestItemRepaint(item); } } } @@ -148,6 +148,17 @@ void Session::markMediaRead(not_null document) { } } +void Session::notifyItemLayoutChange(not_null item) { + _itemLayoutChanges.fire_copy(item); + enumerateItemViews(item, [&](not_null view) { + notifyViewLayoutChange(view); + }); +} + +rpl::producer> Session::itemLayoutChanged() const { + return _itemLayoutChanges.events(); +} + void Session::notifyViewLayoutChange(not_null view) { _viewLayoutChanges.fire_copy(view); } @@ -1131,38 +1142,20 @@ void Session::gameApplyFields( notifyGameUpdateDelayed(game); } -void Session::registerPhotoView( +void Session::registerPhotoItem( not_null photo, - not_null view) { - _photoViews[photo].insert(view); + not_null item) { + _photoItems[photo].insert(item); } -void Session::unregisterPhotoView( +void Session::unregisterPhotoItem( not_null photo, - not_null view) { - const auto i = _photoViews.find(photo); - if (i != _photoViews.end()) { + not_null item) { + const auto i = _photoItems.find(photo); + if (i != _photoItems.end()) { auto &items = i->second; - if (items.remove(view) && items.empty()) { - _photoViews.erase(i); - } - } -} - -void Session::registerDocumentView( - not_null document, - not_null view) { - _documentViews[document].insert(view); -} - -void Session::unregisterDocumentView( - not_null document, - not_null view) { - const auto i = _documentViews.find(document); - if (i != _documentViews.end()) { - auto &items = i->second; - if (items.remove(view) && items.empty()) { - _documentViews.erase(i); + if (items.remove(item) && items.empty()) { + _photoItems.erase(i); } } } diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index fc270994e..e9caf0735 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -60,6 +60,8 @@ public: }; void notifyItemIdChange(IdChange event); rpl::producer itemIdChanged() const; + void notifyItemLayoutChange(not_null item); + rpl::producer> itemLayoutChanged() const; void notifyViewLayoutChange(not_null view); rpl::producer> viewLayoutChanged() const; void requestItemRepaint(not_null item); @@ -273,18 +275,12 @@ public: not_null original, const MTPGame &data); - void registerPhotoView( + void registerPhotoItem( not_null photo, - not_null view); - void unregisterPhotoView( + not_null item); + void unregisterPhotoItem( not_null photo, - not_null view); - void registerDocumentView( - not_null document, - not_null view); - void unregisterDocumentView( - not_null document, - not_null view); + not_null item); void registerDocumentItem( not_null document, not_null item); @@ -439,6 +435,7 @@ private: base::Observable _moreChatsLoaded; base::Observable _queryItemVisibility; rpl::event_stream _itemIdChanges; + rpl::event_stream> _itemLayoutChanges; rpl::event_stream> _viewLayoutChanges; rpl::event_stream> _itemRepaintRequest; rpl::event_stream> _viewRepaintRequest; @@ -473,16 +470,13 @@ private: std::unique_ptr> _photos; std::map< not_null, - base::flat_set>> _photoViews; + base::flat_set>> _photoItems; std::unordered_map< DocumentId, std::unique_ptr> _documents; std::map< not_null, base::flat_set>> _documentItems; - std::map< - not_null, - base::flat_set>> _documentViews; std::unordered_map< WebPageId, std::unique_ptr> _webpages; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index 9ee6a6ab5..87926ef47 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -231,6 +231,14 @@ InnerWidget::InnerWidget( refreshItem(view); } }, lifetime()); + Auth().data().viewLayoutChanged( + ) | rpl::start_with_next([this](auto view) { + if (view->delegate() == this) { + if (view->isUnderCursor()) { + updateSelected(); + } + } + }, lifetime()); Auth().data().animationPlayInlineRequest( ) | rpl::start_with_next([this](auto item) { if (const auto view = viewForItem(item)) { diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index a758667ce..a0f251200 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -245,7 +245,6 @@ HistoryPhoto::HistoryPhoto( } void HistoryPhoto::create(FullMsgId contextId, PeerData *chat) { - Auth().data().registerPhotoView(_data, _parent); setLinks( std::make_shared(_data, contextId, chat), std::make_shared(_data, contextId, chat), @@ -707,28 +706,11 @@ ImagePtr HistoryPhoto::replyPreview() { return _data->makeReplyPreview(); } -HistoryPhoto::~HistoryPhoto() { - Auth().data().unregisterPhotoView(_data, _parent); -} - -DocumentViewRegister::DocumentViewRegister( - not_null parent, - not_null document) -: _savedParent(parent) -, _savedDocument(document) { - Auth().data().registerDocumentView(_savedDocument, _savedParent); -} - -DocumentViewRegister::~DocumentViewRegister() { - Auth().data().unregisterDocumentView(_savedDocument, _savedParent); -} - HistoryVideo::HistoryVideo( not_null parent, not_null realParent, not_null document) : HistoryFileMedia(parent) -, DocumentViewRegister(parent, document) , _data(document) , _thumbw(1) , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { @@ -1197,7 +1179,6 @@ HistoryDocument::HistoryDocument( not_null parent, not_null document) : HistoryFileMedia(parent) -, DocumentViewRegister(parent, document) , _data(document) { const auto item = parent->data(); auto caption = createCaption(item); @@ -1934,7 +1915,6 @@ HistoryGif::HistoryGif( not_null parent, not_null document) : HistoryFileMedia(parent) -, DocumentViewRegister(parent, document) , _data(document) , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { const auto item = parent->data(); @@ -2782,7 +2762,6 @@ HistorySticker::HistorySticker( not_null parent, not_null document) : HistoryMedia(parent) -, DocumentViewRegister(parent, document) , _data(document) , _emoji(_data->sticker()->alt) { _data->thumb->load(); diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index 9e1d07c29..aa2cce723 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -200,8 +200,6 @@ public: return _data->loaded(); } - ~HistoryPhoto(); - protected: float64 dataProgress() const override; bool dataFinished() const override; @@ -228,20 +226,7 @@ private: }; -class DocumentViewRegister { -public: - DocumentViewRegister( - not_null parent, - not_null document); - ~DocumentViewRegister(); - -private: - not_null _savedParent; - not_null _savedDocument; - -}; - -class HistoryVideo : public HistoryFileMedia, public DocumentViewRegister { +class HistoryVideo : public HistoryFileMedia { public: HistoryVideo( not_null parent, @@ -333,7 +318,6 @@ private: class HistoryDocument : public HistoryFileMedia - , public DocumentViewRegister , public RuntimeComposer { public: HistoryDocument( @@ -415,7 +399,7 @@ private: }; -class HistoryGif : public HistoryFileMedia, public DocumentViewRegister { +class HistoryGif : public HistoryFileMedia { public: HistoryGif( not_null parent, @@ -516,7 +500,7 @@ private: }; -class HistorySticker : public HistoryMedia, public DocumentViewRegister { +class HistorySticker : public HistoryMedia { public: HistorySticker( not_null parent, diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 478cc12ae..92b03be30 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -665,11 +665,9 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null cont }); Auth().data().viewLayoutChanged( ) | rpl::start_with_next([this](auto view) { - if (_peer && _list) { - if (view == view->data()->mainView()) { - if (view->isUnderCursor()) { - _list->onUpdateSelected(); - } + if (view == view->data()->mainView()) { + if (view->isUnderCursor() && _list) { + _list->onUpdateSelected(); } } }, lifetime()); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 7ca133fd3..cc4fb8fb7 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -240,6 +240,14 @@ ListWidget::ListWidget( refreshItem(view); } }, lifetime()); + Auth().data().viewLayoutChanged( + ) | rpl::start_with_next([this](auto view) { + if (view->delegate() == this) { + if (view->isUnderCursor()) { + updateSelected(); + } + } + }, lifetime()); Auth().data().animationPlayInlineRequest( ) | rpl::start_with_next([this](auto item) { if (const auto view = viewForItem(item)) { diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index 4852c093e..fb7b71582 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -561,10 +561,10 @@ void ListWidget::start() { ObservableViewer( Auth().downloader().taskFinished() ) | rpl::start_with_next([this] { update(); }, lifetime()); - //Auth().data().itemLayoutChanged( // #TODO - //) | rpl::start_with_next([this](auto item) { - // itemLayoutChanged(item); - //}, lifetime()); + Auth().data().itemLayoutChanged( + ) | rpl::start_with_next([this](auto item) { + itemLayoutChanged(item); + }, lifetime()); Auth().data().itemRemoved( ) | rpl::start_with_next([this](auto item) { itemRemoved(item); diff --git a/Telegram/SourceFiles/media/player/media_player_float.cpp b/Telegram/SourceFiles/media/player/media_player_float.cpp index b773ff542..dd5f1ba8b 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.cpp +++ b/Telegram/SourceFiles/media/player/media_player_float.cpp @@ -50,12 +50,7 @@ Float::Float( prepareShadow(); - rpl::merge( - //Auth().data().viewLayoutChanged( // #TODO not needed? - //) | rpl::map( - // [](auto view) { return view->data(); } - //), - Auth().data().itemRepaintRequest() + Auth().data().itemRepaintRequest( ) | rpl::start_with_next([this](auto item) { if (_item == item) { repaintItem();