Fix timestamp highlights when editing media.

This commit is contained in:
John Preston 2019-12-27 15:15:16 +03:00
parent 1ba052cc13
commit fedf29adb1
4 changed files with 31 additions and 23 deletions

View File

@ -1681,6 +1681,7 @@ bool Session::checkEntitiesAndViewsUpdate(const MTPDmessage &data) {
existing->indexAsNewItem(); existing->indexAsNewItem();
existing->contributeToSlowmode(data.vdate().v); existing->contributeToSlowmode(data.vdate().v);
requestItemTextRefresh(existing); requestItemTextRefresh(existing);
updateDependentMessages(existing);
if (existing->mainView()) { if (existing->mainView()) {
checkSavedGif(existing); checkSavedGif(existing);
return true; return true;

View File

@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_document.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "facades.h" #include "facades.h"
@ -179,6 +180,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const {
bool HistoryMessageReply::updateData( bool HistoryMessageReply::updateData(
not_null<HistoryMessage*> holder, not_null<HistoryMessage*> holder,
bool force) { bool force) {
const auto guard = gsl::finally([&] { refreshReplyToDocument(); });
if (!force) { if (!force) {
if (replyToMsg || !replyToMsgId) { if (replyToMsg || !replyToMsgId) {
return true; 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) { if (const auto media = replyToMsg ? replyToMsg->media() : nullptr) {
return media->document(); if (const auto document = media->document()) {
replyToDocumentId = document->id;
}
} }
return nullptr;
} }
ReplyMarkupClickHandler::ReplyMarkupClickHandler( ReplyMarkupClickHandler::ReplyMarkupClickHandler(

View File

@ -142,10 +142,11 @@ struct HistoryMessageReply : public RuntimeComponent<HistoryMessageReply, Histor
void setReplyToLinkFrom( void setReplyToLinkFrom(
not_null<HistoryMessage*> holder); not_null<HistoryMessage*> holder);
[[nodiscard]] DocumentData *replyToDocument() const; [[nodiscard]] void refreshReplyToDocument();
MsgId replyToMsgId = 0; MsgId replyToMsgId = 0;
HistoryItem *replyToMsg = nullptr; HistoryItem *replyToMsg = nullptr;
DocumentId replyToDocumentId = 0;
ClickHandlerPtr replyToLnk; ClickHandlerPtr replyToLnk;
mutable Ui::Text::String replyToName, replyToText; mutable Ui::Text::String replyToName, replyToText;
mutable int replyToVersion = 0; mutable int replyToVersion = 0;

View File

@ -699,9 +699,9 @@ int HistoryMessage::viewsCount() const {
bool HistoryMessage::updateDependencyItem() { bool HistoryMessage::updateDependencyItem() {
if (const auto reply = Get<HistoryMessageReply>()) { if (const auto reply = Get<HistoryMessageReply>()) {
const auto document = reply->replyToDocument(); const auto documentId = reply->replyToDocumentId;
const auto result = reply->updateData(this, true); const auto result = reply->updateData(this, true);
if (document != reply->replyToDocument() if (documentId != reply->replyToDocumentId
&& generateLocalEntitiesByReply()) { && generateLocalEntitiesByReply()) {
reapplyText(); reapplyText();
} }
@ -902,6 +902,7 @@ void HistoryMessage::returnSavedMedia() {
history()->owner().groups().refreshMessage(this, true); history()->owner().groups().refreshMessage(this, true);
} else { } else {
history()->owner().requestItemViewRefresh(this); history()->owner().requestItemViewRefresh(this);
history()->owner().updateDependentMessages(this);
} }
} }
@ -1167,21 +1168,22 @@ TextWithEntities HistoryMessage::withLocalEntities(
return textWithEntities; return textWithEntities;
} }
if (const auto reply = Get<HistoryMessageReply>()) { if (const auto reply = Get<HistoryMessageReply>()) {
if (const auto document = reply->replyToDocument()) { const auto document = reply->replyToDocumentId
if (document->isVideoFile() || document->isSong()) { ? history()->owner().document(reply->replyToDocumentId).get()
using namespace HistoryView; : nullptr;
const auto duration = document->getDuration(); if (document && (document->isVideoFile() || document->isSong())) {
const auto base = (duration > 0) using namespace HistoryView;
? DocumentTimestampLinkBase( const auto duration = document->getDuration();
document, const auto base = (duration > 0)
reply->replyToMsg->fullId()) ? DocumentTimestampLinkBase(
: QString(); document,
if (!base.isEmpty()) { reply->replyToMsg->fullId())
return AddTimestampLinks( : QString();
textWithEntities, if (!base.isEmpty()) {
duration, return AddTimestampLinks(
base); textWithEntities,
} duration,
base);
} }
} }
} }
@ -1353,9 +1355,9 @@ void HistoryMessage::setRealId(MsgId newId) {
void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) { void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) {
if (const auto reply = Get<HistoryMessageReply>()) { if (const auto reply = Get<HistoryMessageReply>()) {
const auto document = reply->replyToDocument(); const auto documentId = reply->replyToDocumentId;
reply->itemRemoved(this, dependency); reply->itemRemoved(this, dependency);
if (document != reply->replyToDocument() if (documentId != reply->replyToDocumentId
&& generateLocalEntitiesByReply()) { && generateLocalEntitiesByReply()) {
reapplyText(); reapplyText();
} }