diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index f508c5c159..8fdac0c290 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -923,6 +923,7 @@ namespace { : nullptr); existing->setViewsCount(m.has_views() ? m.vviews.v : -1); existing->indexAsNewItem(); + Auth().data().requestItemTextRefresh(existing); if (existing->mainView()) { App::checkSavedGif(existing); return true; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 2a42fadd22..2058dbce6b 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -256,6 +256,16 @@ rpl::producer> Session::itemViewRefreshRequest() const { return _itemViewRefreshRequest.events(); } +void Session::requestItemTextRefresh(not_null item) { + if (const auto i = _views.find(item); i != _views.end()) { + for (const auto view : i->second) { + if (const auto media = view->media()) { + media->parentTextUpdated(); + } + } + } +} + void Session::requestAnimationPlayInline(not_null item) { _animationPlayInlineRequest.fire_copy(item); } diff --git a/Telegram/SourceFiles/data/data_session.h b/Telegram/SourceFiles/data/data_session.h index 11ce8b635e..197345cf8b 100644 --- a/Telegram/SourceFiles/data/data_session.h +++ b/Telegram/SourceFiles/data/data_session.h @@ -80,6 +80,7 @@ public: [[nodiscard]] rpl::producer> viewResizeRequest() const; void requestItemViewRefresh(not_null item); [[nodiscard]] rpl::producer> itemViewRefreshRequest() const; + void requestItemTextRefresh(not_null item); void requestAnimationPlayInline(not_null item); [[nodiscard]] rpl::producer> animationPlayInlineRequest() const; void notifyHistoryUnloaded(not_null history); @@ -468,6 +469,7 @@ private: rpl::event_stream> _itemResizeRequest; rpl::event_stream> _viewResizeRequest; rpl::event_stream> _itemViewRefreshRequest; + rpl::event_stream> _itemTextRefreshRequest; rpl::event_stream> _animationPlayInlineRequest; rpl::event_stream> _itemRemoved; rpl::event_stream> _viewRemoved; diff --git a/Telegram/SourceFiles/history/history_media.h b/Telegram/SourceFiles/history/history_media.h index 11424a6c52..829aa8bbe5 100644 --- a/Telegram/SourceFiles/history/history_media.h +++ b/Telegram/SourceFiles/history/history_media.h @@ -222,6 +222,8 @@ public: // Should be called only by Data::Session. virtual void updateSharedContactUserId(UserId userId) { } + virtual void parentTextUpdated() { + } virtual ~HistoryMedia() = default; diff --git a/Telegram/SourceFiles/history/history_media_grouped.cpp b/Telegram/SourceFiles/history/history_media_grouped.cpp index 8856712a24..0c4da81924 100644 --- a/Telegram/SourceFiles/history/history_media_grouped.cpp +++ b/Telegram/SourceFiles/history/history_media_grouped.cpp @@ -13,12 +13,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_element.h" #include "history/view/history_view_cursor_state.h" #include "data/data_media_types.h" +#include "data/data_session.h" #include "storage/storage_shared_media.h" #include "lang/lang_keys.h" #include "ui/grouped_layout.h" #include "ui/text_options.h" -#include "styles/style_history.h" +#include "auth_session.h" #include "layout.h" +#include "styles/style_history.h" namespace { @@ -391,6 +393,10 @@ void HistoryGroupedMedia::updateNeedBubbleState() { _needBubble = computeNeedBubble(); } +void HistoryGroupedMedia::parentTextUpdated() { + Auth().data().requestViewResize(_parent); +} + bool HistoryGroupedMedia::needsBubble() const { return _needBubble; } diff --git a/Telegram/SourceFiles/history/history_media_grouped.h b/Telegram/SourceFiles/history/history_media_grouped.h index 69e47ca44e..dc398d772d 100644 --- a/Telegram/SourceFiles/history/history_media_grouped.h +++ b/Telegram/SourceFiles/history/history_media_grouped.h @@ -79,6 +79,8 @@ public: return true; } + void parentTextUpdated() override; + private: struct Part { Part(not_null item); diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index 2175741572..83d8c8fa23 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -681,6 +681,13 @@ bool HistoryPhoto::needsBubble() const { return false; } +void HistoryPhoto::parentTextUpdated() { + _caption = (_parent->media() == this) + ? createCaption(_parent->data()) + : Text(); + Auth().data().requestViewResize(_parent); +} + HistoryVideo::HistoryVideo( not_null parent, not_null realParent, @@ -1112,6 +1119,13 @@ bool HistoryVideo::needsBubble() const { return false; } +void HistoryVideo::parentTextUpdated() { + _caption = (_parent->media() == this) + ? createCaption(_parent->data()) + : Text(); + Auth().data().requestViewResize(_parent); +} + void HistoryVideo::updateStatusText() const { auto showPause = false; auto statusSize = 0; @@ -1832,6 +1846,20 @@ void HistoryDocument::refreshParentId(not_null realParent) { } } +void HistoryDocument::parentTextUpdated() { + auto caption = (_parent->media() == this) + ? createCaption(_parent->data()) + : Text(); + if (!caption.isEmpty()) { + AddComponents(HistoryDocumentCaptioned::Bit()); + auto captioned = Get(); + captioned->_caption = std::move(caption); + } else { + RemoveComponents(HistoryDocumentCaptioned::Bit()); + } + Auth().data().requestViewResize(_parent); +} + TextWithEntities HistoryDocument::getCaption() const { if (const auto captioned = Get()) { return captioned->_caption.originalTextWithEntities(); @@ -2543,6 +2571,13 @@ QString HistoryGif::additionalInfoString() const { return QString(); } +void HistoryGif::parentTextUpdated() { + _caption = (_parent->media() == this) + ? createCaption(_parent->data()) + : Text(); + Auth().data().requestViewResize(_parent); +} + int HistoryGif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const { int result = 0; if (forwarded) { diff --git a/Telegram/SourceFiles/history/history_media_types.h b/Telegram/SourceFiles/history/history_media_types.h index 55f7f7264d..ea967e8bfd 100644 --- a/Telegram/SourceFiles/history/history_media_types.h +++ b/Telegram/SourceFiles/history/history_media_types.h @@ -190,6 +190,8 @@ public: return _data->loaded(); } + void parentTextUpdated() override; + protected: float64 dataProgress() const override; bool dataFinished() const override; @@ -278,6 +280,8 @@ public: return isBubbleBottom() && _caption.isEmpty(); } + void parentTextUpdated() override; + protected: float64 dataProgress() const override; bool dataFinished() const override; @@ -354,6 +358,7 @@ public: void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed) override; void refreshParentId(not_null realParent) override; + void parentTextUpdated() override; protected: float64 dataProgress() const override; @@ -427,6 +432,8 @@ public: return _data->loaded(); } + void parentTextUpdated() override; + ~HistoryGif(); protected: diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 5978848629..fbe85c17f8 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -732,8 +732,6 @@ void HistoryMessage::refreshSentMedia(const MTPMessageMedia *media) { refreshMedia(media); if (wasGrouped) { Auth().data().groups().refreshMessage(this); - } else { - Auth().data().requestItemViewRefresh(this); } } @@ -957,7 +955,9 @@ Storage::SharedMediaTypesMask HistoryMessage::sharedMediaTypes() const { void HistoryMessage::setText(const TextWithEntities &textWithEntities) { for_const (auto &entity, textWithEntities.entities) { auto type = entity.type(); - if (type == EntityInTextUrl || type == EntityInTextCustomUrl || type == EntityInTextEmail) { + if (type == EntityInTextUrl + || type == EntityInTextCustomUrl + || type == EntityInTextEmail) { _flags |= MTPDmessage_ClientFlag::f_has_text_links; break; }