From fedf29adb16b249a654fd1d5ac9e673e70ccc047 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 27 Dec 2019 15:15:16 +0300 Subject: [PATCH] Fix timestamp highlights when editing media. --- Telegram/SourceFiles/data/data_session.cpp | 1 + .../history/history_item_components.cpp | 10 +++-- .../history/history_item_components.h | 3 +- .../SourceFiles/history/history_message.cpp | 40 ++++++++++--------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 745dcb626c..dcef064314 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1681,6 +1681,7 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) { existing->indexAsNewItem(); existing->contributeToSlowmode(data.vdate().v); requestItemTextRefresh(existing); + updateDependentMessages(existing); if (existing->mainView()) { checkSavedGif(existing); return true; diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index d380b4d746..f0b7bb9f06 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_user.h" #include "data/data_file_origin.h" +#include "data/data_document.h" #include "main/main_session.h" #include "window/window_session_controller.h" #include "facades.h" @@ -179,6 +180,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { bool HistoryMessageReply::updateData( not_null holder, bool force) { + const auto guard = gsl::finally([&] { refreshReplyToDocument(); }); if (!force) { if (replyToMsg || !replyToMsgId) { return true; @@ -358,11 +360,13 @@ void HistoryMessageReply::paint( } } -DocumentData *HistoryMessageReply::replyToDocument() const { +void HistoryMessageReply::refreshReplyToDocument() { + replyToDocumentId = 0; if (const auto media = replyToMsg ? replyToMsg->media() : nullptr) { - return media->document(); + if (const auto document = media->document()) { + replyToDocumentId = document->id; + } } - return nullptr; } ReplyMarkupClickHandler::ReplyMarkupClickHandler( diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 92e42c445b..8ce45e0d83 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -142,10 +142,11 @@ struct HistoryMessageReply : public RuntimeComponent holder); - [[nodiscard]] DocumentData *replyToDocument() const; + [[nodiscard]] void refreshReplyToDocument(); MsgId replyToMsgId = 0; HistoryItem *replyToMsg = nullptr; + DocumentId replyToDocumentId = 0; ClickHandlerPtr replyToLnk; mutable Ui::Text::String replyToName, replyToText; mutable int replyToVersion = 0; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 35248b8f69..0c9ee4d346 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -699,9 +699,9 @@ int HistoryMessage::viewsCount() const { bool HistoryMessage::updateDependencyItem() { if (const auto reply = Get()) { - const auto document = reply->replyToDocument(); + const auto documentId = reply->replyToDocumentId; const auto result = reply->updateData(this, true); - if (document != reply->replyToDocument() + if (documentId != reply->replyToDocumentId && generateLocalEntitiesByReply()) { reapplyText(); } @@ -902,6 +902,7 @@ void HistoryMessage::returnSavedMedia() { history()->owner().groups().refreshMessage(this, true); } else { history()->owner().requestItemViewRefresh(this); + history()->owner().updateDependentMessages(this); } } @@ -1167,21 +1168,22 @@ TextWithEntities HistoryMessage::withLocalEntities( return textWithEntities; } if (const auto reply = Get()) { - if (const auto document = reply->replyToDocument()) { - if (document->isVideoFile() || document->isSong()) { - using namespace HistoryView; - const auto duration = document->getDuration(); - const auto base = (duration > 0) - ? DocumentTimestampLinkBase( - document, - reply->replyToMsg->fullId()) - : QString(); - if (!base.isEmpty()) { - return AddTimestampLinks( - textWithEntities, - duration, - base); - } + const auto document = reply->replyToDocumentId + ? history()->owner().document(reply->replyToDocumentId).get() + : nullptr; + if (document && (document->isVideoFile() || document->isSong())) { + using namespace HistoryView; + const auto duration = document->getDuration(); + const auto base = (duration > 0) + ? DocumentTimestampLinkBase( + document, + reply->replyToMsg->fullId()) + : QString(); + if (!base.isEmpty()) { + return AddTimestampLinks( + textWithEntities, + duration, + base); } } } @@ -1353,9 +1355,9 @@ void HistoryMessage::setRealId(MsgId newId) { void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) { if (const auto reply = Get()) { - const auto document = reply->replyToDocument(); + const auto documentId = reply->replyToDocumentId; reply->itemRemoved(this, dependency); - if (document != reply->replyToDocument() + if (documentId != reply->replyToDocumentId && generateLocalEntitiesByReply()) { reapplyText(); }