From 145dda843e6fb605b23f94cad3a01ae3ee50f383 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 30 Mar 2019 21:26:20 +0300 Subject: [PATCH] Added initial local reference for edited media. --- Telegram/SourceFiles/apiwrap.cpp | 2 ++ Telegram/SourceFiles/app.cpp | 17 +++++++++++++---- Telegram/SourceFiles/history/history_item.h | 8 ++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index a88097c10..c5c4402ee 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4639,6 +4639,7 @@ void ApiWrap::editUploadedPhoto( sentEntities )).done([=](const MTPUpdates &result) { item->clearSavedMedia(); + item->setIsLocalUpdateMedia(true); applyUpdates(result); }).fail([=](const RPCError &error) { QString err = error.type(); @@ -4702,6 +4703,7 @@ void ApiWrap::editUploadedDocument( sentEntities )).done([=](const MTPUpdates &result) { item->clearSavedMedia(); + item->setIsLocalUpdateMedia(true); applyUpdates(result); }).fail([=](const RPCError &error) { QString err = error.type(); diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 16f7ac0d6..d7faa350f 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -159,9 +159,9 @@ namespace App { return false; } - void updateEditedMessage(const MTPMessage &message) { - message.match([](const MTPDmessageEmpty &) { - }, [](const auto &message) { + void updateEditedMessage(const MTPMessage &m) { + m.match([](const MTPDmessageEmpty &) { + }, [&m](const auto &message) { auto peerId = peerFromMTP(message.vto_id); if (message.has_from_id() && peerId == Auth().userPeerId()) { peerId = peerFromUser(message.vfrom_id); @@ -170,7 +170,16 @@ namespace App { peerToChannel(peerId), message.vid.v); if (existing) { - existing->applyEdition(message); + auto update = true; + if (existing->isLocalUpdateMedia()) { + if (checkEntitiesAndViewsUpdate(m.c_message())) { + update = false; + existing->setIsLocalUpdateMedia(false); + } + } + if (update) { + existing->applyEdition(message); + } } }); } diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 3a693ef1d..3980c6126 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -130,6 +130,13 @@ public: _isEditingMedia = edit; } + bool isLocalUpdateMedia() const { + return _isLocalUpdateMedia; + } + void setIsLocalUpdateMedia(bool flag) { + _isLocalUpdateMedia = flag; + } + // For edit media in history_message. virtual void returnSavedMedia() {}; void clearSavedMedia() { @@ -326,6 +333,7 @@ protected: int _textHeight = 0; bool _isEditingMedia = false; + bool _isLocalUpdateMedia = false; std::unique_ptr _savedMedia; std::unique_ptr _media;