Add InputInvoice::is_equal_but_different.

This commit is contained in:
levlam 2022-09-24 22:55:03 +03:00
parent b10983acfa
commit bb69175aab
5 changed files with 20 additions and 12 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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;

View File

@ -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<telegram_api::InputMedia> 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_ &&

View File

@ -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 {