Refactored variables for edit media in HistoryItem.

- Replaced _isLocalUpdateMedia with client flag.
 - Removed _isEditingMedia.
This commit is contained in:
23rd 2019-04-04 13:22:59 +03:00
parent a9fa49e372
commit a6d0fa433e
6 changed files with 20 additions and 27 deletions

View File

@ -4676,6 +4676,7 @@ void ApiWrap::editUploadedFile(
item->clearSavedMedia(); item->clearSavedMedia();
item->setIsLocalUpdateMedia(true); item->setIsLocalUpdateMedia(true);
applyUpdates(result); applyUpdates(result);
item->setIsLocalUpdateMedia(false);
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
QString err = error.type(); QString err = error.type();
if (err == qstr("MESSAGE_NOT_MODIFIED")) { if (err == qstr("MESSAGE_NOT_MODIFIED")) {

View File

@ -174,7 +174,6 @@ namespace App {
checkEntitiesAndViewsUpdate(m.c_message()); checkEntitiesAndViewsUpdate(m.c_message());
} }
existing->applyEdition(message); existing->applyEdition(message);
existing->setIsLocalUpdateMedia(false);
} }
}); });
} }

View File

@ -123,27 +123,16 @@ public:
bool hasUnreadMediaFlag() const; bool hasUnreadMediaFlag() const;
void markMediaRead(); void markMediaRead();
bool isEditingMedia() const {
return _isEditingMedia;
}
void setIsEditingMedia(bool 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 savePreviousMedia() { void savePreviousMedia() {
_savedMedia = _media->clone(this); _savedMedia = _media->clone(this);
} }
bool isEditingMedia() const {
return _savedMedia != nullptr;
}
void clearSavedMedia() { void clearSavedMedia() {
_isEditingMedia = false;
_savedMedia = nullptr; _savedMedia = nullptr;
} }
@ -164,6 +153,16 @@ public:
bool isGroupEssential() const { bool isGroupEssential() const {
return _flags & MTPDmessage_ClientFlag::f_is_group_essential; return _flags & MTPDmessage_ClientFlag::f_is_group_essential;
} }
bool isLocalUpdateMedia() const {
return _flags & MTPDmessage_ClientFlag::f_is_local_update_media;
}
void setIsLocalUpdateMedia(bool flag) {
if (flag) {
_flags |= MTPDmessage_ClientFlag::f_is_local_update_media;
} else {
_flags &= ~MTPDmessage_ClientFlag::f_is_local_update_media;
}
}
bool isGroupMigrate() const { bool isGroupMigrate() const {
return isGroupEssential() && isEmpty(); return isGroupEssential() && isEmpty();
} }
@ -335,8 +334,6 @@ protected:
int _textWidth = -1; int _textWidth = -1;
int _textHeight = 0; int _textHeight = 0;
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;

View File

@ -620,7 +620,7 @@ bool HistoryMessage::allowsEdit(TimeId now) const {
&& !isTooOldForEdit(now) && !isTooOldForEdit(now)
&& (!_media || _media->allowsEdit()) && (!_media || _media->allowsEdit())
&& !isUnsupportedMessage() && !isUnsupportedMessage()
&& !_isEditingMedia; && !isEditingMedia();
} }
bool HistoryMessage::uploading() const { bool HistoryMessage::uploading() const {
@ -769,7 +769,6 @@ void HistoryMessage::returnSavedMedia() {
} else { } else {
history()->owner().requestItemViewRefresh(this); history()->owner().requestItemViewRefresh(this);
} }
_isEditingMedia = false;
} }
void HistoryMessage::setMedia(const MTPMessageMedia &media) { void HistoryMessage::setMedia(const MTPMessageMedia &media) {
@ -928,7 +927,7 @@ void HistoryMessage::applyEdition(const MTPDmessage &message) {
textWithEntities.entities = TextUtilities::EntitiesFromMTP(message.ventities.v); textWithEntities.entities = TextUtilities::EntitiesFromMTP(message.ventities.v);
} }
setReplyMarkup(message.has_reply_markup() ? (&message.vreply_markup) : nullptr); setReplyMarkup(message.has_reply_markup() ? (&message.vreply_markup) : nullptr);
if (!_isLocalUpdateMedia) { if (!isLocalUpdateMedia()) {
refreshMedia(message.has_media() ? (&message.vmedia) : nullptr); refreshMedia(message.has_media() ? (&message.vmedia) : nullptr);
} }
setViewsCount(message.has_views() ? message.vviews.v : -1); setViewsCount(message.has_views() ? message.vviews.v : -1);
@ -959,10 +958,7 @@ void HistoryMessage::updateSentMedia(const MTPMessageMedia *media) {
} }
_flags &= ~MTPDmessage_ClientFlag::f_from_inline_bot; _flags &= ~MTPDmessage_ClientFlag::f_from_inline_bot;
} else { } else {
if (_isEditingMedia) { if (!media || !_media || !_media->updateSentMedia(*media)) {
_savedMedia = _media->clone(this);
refreshSentMedia(media);
} else if (!media || !_media || !_media->updateSentMedia(*media)) {
refreshSentMedia(media); refreshSentMedia(media);
} }
} }

View File

@ -4263,7 +4263,6 @@ void HistoryWidget::sendFileConfirmed(
auto localEntities = TextUtilities::EntitiesToMTP(caption.entities); auto localEntities = TextUtilities::EntitiesToMTP(caption.entities);
if (itemToEdit) { if (itemToEdit) {
itemToEdit->setIsEditingMedia(true);
if (const auto id = itemToEdit->groupId()) { if (const auto id = itemToEdit->groupId()) {
groupId = id.value; groupId = id.value;
} }

View File

@ -53,8 +53,9 @@ enum class MTPDmessage_ClientFlag : uint32 {
//// message is attached to previous one when displaying the history //// message is attached to previous one when displaying the history
//f_attach_to_previous = (1U << 25), //f_attach_to_previous = (1U << 25),
//// message is attached to next one when displaying the history // message's edited media is generated on the client
//f_attach_to_next = (1U << 24), // and should not update media from server
f_is_local_update_media = (1U << 24),
// message was sent from inline bot, need to re-set media when sent // message was sent from inline bot, need to re-set media when sent
f_from_inline_bot = (1U << 23), f_from_inline_bot = (1U << 23),