From bb69175aabc802fde8fbcf70a05aded7fb49a602 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 24 Sep 2022 22:55:03 +0300 Subject: [PATCH] Add InputInvoice::is_equal_but_different. --- td/telegram/InputInvoice.cpp | 12 ++++++++---- td/telegram/InputInvoice.h | 2 ++ td/telegram/MessageContent.cpp | 4 +--- td/telegram/MessageExtendedMedia.cpp | 8 +++++++- td/telegram/MessageExtendedMedia.h | 6 ++---- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/td/telegram/InputInvoice.cpp b/td/telegram/InputInvoice.cpp index 1ff0999f4..4c07eb1db 100644 --- a/td/telegram/InputInvoice.cpp +++ b/td/telegram/InputInvoice.cpp @@ -34,10 +34,10 @@ static bool operator==(const Invoice &lhs, const Invoice &rhs) { bool operator==(const InputInvoice &lhs, const InputInvoice &rhs) { return lhs.title_ == rhs.title_ && lhs.description_ == rhs.description_ && lhs.photo_ == rhs.photo_ && - lhs.start_parameter_ == rhs.start_parameter_ && lhs.invoice_ == rhs.invoice_ && - lhs.total_amount_ == rhs.total_amount_ && lhs.receipt_message_id_ == rhs.receipt_message_id_ && - lhs.payload_ == rhs.payload_ && lhs.provider_token_ == rhs.provider_token_ && - lhs.provider_data_ == rhs.provider_data_ && lhs.extended_media_ == rhs.extended_media_; + lhs.start_parameter_ == rhs.start_parameter_ && lhs.invoice_ == rhs.invoice_ && lhs.payload_ == rhs.payload_ && + lhs.provider_token_ == rhs.provider_token_ && lhs.provider_data_ == rhs.provider_data_ && + lhs.extended_media_ == rhs.extended_media_ && lhs.total_amount_ == rhs.total_amount_ && + lhs.receipt_message_id_ == rhs.receipt_message_id_; } bool operator!=(const InputInvoice &lhs, const InputInvoice &rhs) { @@ -363,6 +363,10 @@ bool InputInvoice::has_media_timestamp() const { return extended_media_.has_media_timestamp(); } +bool InputInvoice::is_equal_but_different(const InputInvoice &other) const { + return extended_media_.is_equal_but_different(other.extended_media_); +} + const FormattedText *InputInvoice::get_caption() const { return extended_media_.get_caption(); } diff --git a/td/telegram/InputInvoice.h b/td/telegram/InputInvoice.h index fa4a49468..b15ddc365 100644 --- a/td/telegram/InputInvoice.h +++ b/td/telegram/InputInvoice.h @@ -87,6 +87,8 @@ struct InputInvoice { bool has_media_timestamp() const; + bool is_equal_but_different(const InputInvoice &other) const; + const FormattedText *get_caption() const; int32 get_duration(const Td *td) const; diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index d169e0df2..bc3aa222e 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3225,9 +3225,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo new_->input_invoice.update_from(old_->input_invoice); if (old_->input_invoice != new_->input_invoice) { need_update = true; - } - if (old_->input_invoice.extended_media_.get_unsupported_version() != - new_->input_invoice.extended_media_.get_unsupported_version()) { + } else if (old_->input_invoice.is_equal_but_different(new_->input_invoice)) { is_content_changed = true; } break; diff --git a/td/telegram/MessageExtendedMedia.cpp b/td/telegram/MessageExtendedMedia.cpp index 3bb17bd6e..84c8108a3 100644 --- a/td/telegram/MessageExtendedMedia.cpp +++ b/td/telegram/MessageExtendedMedia.cpp @@ -142,7 +142,7 @@ bool MessageExtendedMedia::update_to(Td *td, if (!new_extended_media.is_media() && is_media()) { return false; } - if (*this != new_extended_media || get_unsupported_version() != new_extended_media.get_unsupported_version()) { + if (*this != new_extended_media || is_equal_but_different(new_extended_media)) { *this = std::move(new_extended_media); return true; } @@ -290,6 +290,11 @@ telegram_api::object_ptr MessageExtendedMedia::get_inp return nullptr; } +bool MessageExtendedMedia::is_equal_but_different(const MessageExtendedMedia &other) const { + return type_ == Type::Unsupported && other.type_ == Type::Unsupported && + unsupported_version_ != other.unsupported_version_; +} + bool operator==(const MessageExtendedMedia &lhs, const MessageExtendedMedia &rhs) { if (lhs.type_ != rhs.type_ || lhs.caption_ != rhs.caption_) { return false; @@ -298,6 +303,7 @@ bool operator==(const MessageExtendedMedia &lhs, const MessageExtendedMedia &rhs case MessageExtendedMedia::Type::Empty: return true; case MessageExtendedMedia::Type::Unsupported: + // don't compare unsupported_version_ return true; case MessageExtendedMedia::Type::Preview: return lhs.duration_ == rhs.duration_ && lhs.dimensions_ == rhs.dimensions_ && diff --git a/td/telegram/MessageExtendedMedia.h b/td/telegram/MessageExtendedMedia.h index cffc9b5cb..cbc080bc2 100644 --- a/td/telegram/MessageExtendedMedia.h +++ b/td/telegram/MessageExtendedMedia.h @@ -70,10 +70,6 @@ class MessageExtendedMedia { void delete_thumbnail(Td *td); - int32 get_unsupported_version() const { - return unsupported_version_; - } - bool need_reget() const { return type_ == Type::Unsupported && unsupported_version_ < CURRENT_VERSION; } @@ -86,6 +82,8 @@ class MessageExtendedMedia { return type_ == Type::Video; } + bool is_equal_but_different(const MessageExtendedMedia &other) const; + int32 get_duration(const Td *td) const; const FormattedText *get_caption() const {