diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index aa18732b31..d380b4d746 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -358,6 +358,13 @@ void HistoryMessageReply::paint( } } +DocumentData *HistoryMessageReply::replyToDocument() const { + if (const auto media = replyToMsg ? replyToMsg->media() : nullptr) { + return media->document(); + } + return nullptr; +} + ReplyMarkupClickHandler::ReplyMarkupClickHandler( int row, int column, diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 3cbcbb8fc4..92e42c445b 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -130,18 +130,20 @@ struct HistoryMessageReply : public RuntimeComponent holder); + [[nodiscard]] DocumentData *replyToDocument() const; + MsgId replyToMsgId = 0; HistoryItem *replyToMsg = nullptr; ClickHandlerPtr replyToLnk; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 077f7477ab..35248b8f69 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -17,7 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_location_manager.h" #include "history/history_service.h" #include "history/view/history_view_service_message.h" -#include "history/view/history_view_context_menu.h" // For CopyPostLink(). +#include "history/view/history_view_context_menu.h" // CopyPostLink. +#include "history/view/media/history_view_media.h" // AddTimestampLinks. #include "chat_helpers/stickers_emoji_pack.h" #include "main/main_session.h" #include "boxes/share_box.h" @@ -698,7 +699,13 @@ int HistoryMessage::viewsCount() const { bool HistoryMessage::updateDependencyItem() { if (const auto reply = Get()) { - return reply->updateData(this, true); + const auto document = reply->replyToDocument(); + const auto result = reply->updateData(this, true); + if (document != reply->replyToDocument() + && generateLocalEntitiesByReply()) { + reapplyText(); + } + return result; } return true; } @@ -1150,6 +1157,37 @@ Storage::SharedMediaTypesMask HistoryMessage::sharedMediaTypes() const { return result; } +bool HistoryMessage::generateLocalEntitiesByReply() const { + return !_media || _media->webpage(); +} + +TextWithEntities HistoryMessage::withLocalEntities( + const TextWithEntities &textWithEntities) const { + if (!generateLocalEntitiesByReply()) { + 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); + } + } + } + } + return textWithEntities; +} + void HistoryMessage::setText(const TextWithEntities &textWithEntities) { for_const (auto &entity, textWithEntities.entities) { auto type = entity.type(); @@ -1168,7 +1206,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { clearIsolatedEmoji(); _text.setMarkedText( st::messageTextStyle, - textWithEntities, + withLocalEntities(textWithEntities), Ui::ItemTextOptions(this)); if (!textWithEntities.text.isEmpty() && _text.isEmpty()) { // If server has allowed some text that we've trim-ed entirely, @@ -1184,6 +1222,11 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { _textHeight = 0; } +void HistoryMessage::reapplyText() { + setText(originalText()); + history()->owner().requestItemResize(this); +} + void HistoryMessage::setEmptyText() { clearIsolatedEmoji(); _text.setMarkedText( @@ -1309,8 +1352,13 @@ void HistoryMessage::setRealId(MsgId newId) { } void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) { - if (auto reply = Get()) { + if (const auto reply = Get()) { + const auto document = reply->replyToDocument(); reply->itemRemoved(this, dependency); + if (document != reply->replyToDocument() + && generateLocalEntitiesByReply()) { + reapplyText(); + } } } diff --git a/Telegram/SourceFiles/history/history_message.h b/Telegram/SourceFiles/history/history_message.h index c9904c1606..8b783edf91 100644 --- a/Telegram/SourceFiles/history/history_message.h +++ b/Telegram/SourceFiles/history/history_message.h @@ -198,6 +198,10 @@ private: const MTPDmessageFwdHeader &data); void refreshMessageBadge(); + [[nodiscard]] bool generateLocalEntitiesByReply() const; + [[nodiscard]] TextWithEntities withLocalEntities( + const TextWithEntities &textWithEntities) const; + void reapplyText(); Ui::Text::String _messageBadge; diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 376034e56d..4dc07ec9b6 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -423,7 +423,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms if (radial || (!streamingMode && ((!_data->loaded() && !_data->loading()) || !autoplay))) { - const auto radialOpacity = item->isSending() + const auto radialOpacity = (item->isSending() || _data->uploading()) ? 1. : streamed ? streamed->waitingOpacity() @@ -873,6 +873,7 @@ void Gif::drawGrouped( if (displayLoading && (!streamed || item->isSending() + || _data->uploading() || (cornerDownload && _data->loading()))) { ensureAnimation(); if (!_animation->radial.animating()) { @@ -930,7 +931,7 @@ void Gif::drawGrouped( if (radial || (!streamingMode && ((!_data->loaded() && !_data->loading()) || !autoplay))) { - const auto radialOpacity = item->isSending() + const auto radialOpacity = (item->isSending() || _data->uploading()) ? 1. : streamed ? streamed->waitingOpacity() @@ -1423,6 +1424,7 @@ bool Gif::dataLoaded() const { bool Gif::needInfoDisplay() const { return _data->isVideoFile() || _parent->data()->isSending() + || _data->uploading() || _parent->isUnderCursor(); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.cpp b/Telegram/SourceFiles/history/view/media/history_view_media.cpp index f3e78e69cc..e2b51e604f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media.cpp @@ -32,7 +32,17 @@ namespace { return (ok1 && ok2 && ok3) ? result : -1; } -[[nodiscard]] TextWithEntities AddTimestampLinks( +} // namespace + +QString DocumentTimestampLinkBase( + not_null document, + FullMsgId context) { + return QString( + "doc%1_%2_%3" + ).arg(document->id).arg(context.channel).arg(context.msg); +} + +TextWithEntities AddTimestampLinks( TextWithEntities text, TimeId duration, const QString &base) { @@ -92,16 +102,6 @@ namespace { return text; } -} // namespace - -QString DocumentTimestampLinkBase( - not_null document, - FullMsgId context) { - return QString( - "doc%1_%2_%3" - ).arg(document->id).arg(context.channel).arg(context.msg); -} - Storage::SharedMediaTypesMask Media::sharedMediaTypes() const { return {}; } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.h b/Telegram/SourceFiles/history/view/media/history_view_media.h index 2ba8f45c70..96335abaeb 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media.h @@ -43,6 +43,10 @@ enum class MediaInBubbleState { [[nodiscard]] QString DocumentTimestampLinkBase( not_null document, FullMsgId context); +[[nodiscard]] TextWithEntities AddTimestampLinks( + TextWithEntities text, + TimeId duration, + const QString &base); class Media : public Object { public: diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 65eb03a6a7..6b673d9154 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 65eb03a6a78ffe09cd8f644edfe14560854b89eb +Subproject commit 6b673d9154cd596b9c648b130f334c166af36875