Added initial local reference for edited media.

This commit is contained in:
23rd 2019-03-30 21:26:20 +03:00 committed by John Preston
parent 6e69069ba2
commit 145dda843e
3 changed files with 23 additions and 4 deletions

View File

@ -4639,6 +4639,7 @@ void ApiWrap::editUploadedPhoto(
sentEntities sentEntities
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
item->clearSavedMedia(); item->clearSavedMedia();
item->setIsLocalUpdateMedia(true);
applyUpdates(result); applyUpdates(result);
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
QString err = error.type(); QString err = error.type();
@ -4702,6 +4703,7 @@ void ApiWrap::editUploadedDocument(
sentEntities sentEntities
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
item->clearSavedMedia(); item->clearSavedMedia();
item->setIsLocalUpdateMedia(true);
applyUpdates(result); applyUpdates(result);
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
QString err = error.type(); QString err = error.type();

View File

@ -159,9 +159,9 @@ namespace App {
return false; return false;
} }
void updateEditedMessage(const MTPMessage &message) { void updateEditedMessage(const MTPMessage &m) {
message.match([](const MTPDmessageEmpty &) { m.match([](const MTPDmessageEmpty &) {
}, [](const auto &message) { }, [&m](const auto &message) {
auto peerId = peerFromMTP(message.vto_id); auto peerId = peerFromMTP(message.vto_id);
if (message.has_from_id() && peerId == Auth().userPeerId()) { if (message.has_from_id() && peerId == Auth().userPeerId()) {
peerId = peerFromUser(message.vfrom_id); peerId = peerFromUser(message.vfrom_id);
@ -170,7 +170,16 @@ namespace App {
peerToChannel(peerId), peerToChannel(peerId),
message.vid.v); message.vid.v);
if (existing) { 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);
}
} }
}); });
} }

View File

@ -130,6 +130,13 @@ public:
_isEditingMedia = edit; _isEditingMedia = edit;
} }
bool isLocalUpdateMedia() const {
return _isLocalUpdateMedia;
}
void setIsLocalUpdateMedia(bool flag) {
_isLocalUpdateMedia = flag;
}
// For edit media in history_message. // For edit media in history_message.
virtual void returnSavedMedia() {}; virtual void returnSavedMedia() {};
void clearSavedMedia() { void clearSavedMedia() {
@ -326,6 +333,7 @@ protected:
int _textHeight = 0; int _textHeight = 0;
bool _isEditingMedia = false; bool _isEditingMedia = false;
bool _isLocalUpdateMedia = false;
std::unique_ptr<Data::Media> _savedMedia; std::unique_ptr<Data::Media> _savedMedia;
std::unique_ptr<Data::Media> _media; std::unique_ptr<Data::Media> _media;