Add version for MessageExtendedMedia::Unsupported.

This commit is contained in:
levlam 2022-09-22 15:30:12 +03:00
parent 2440ebda56
commit 1fd5452c8f
4 changed files with 35 additions and 0 deletions

View File

@ -3224,6 +3224,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
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()) {
is_content_changed = true;
}
break;
}
case MessageContentType::LiveLocation: {
@ -5716,6 +5720,10 @@ bool need_reget_message_content(const MessageContent *content) {
const auto *m = static_cast<const MessageUnsupported *>(content);
return m->version != MessageUnsupported::CURRENT_VERSION;
}
case MessageContentType::Invoice: {
const auto *m = static_cast<const MessageInvoice *>(content);
return m->input_invoice.extended_media.need_reget();
}
default:
return false;
}

View File

@ -82,6 +82,9 @@ MessageExtendedMedia::MessageExtendedMedia(
default:
break;
}
if (type_ == Type::Unsupported) {
unsupported_version_ = CURRENT_VERSION;
}
break;
}
default:

View File

@ -23,6 +23,11 @@ class MessageExtendedMedia {
Type type_ = Type::Empty;
FormattedText caption_;
static constexpr int32 CURRENT_VERSION = 1;
// for Unsupported
int32 unsupported_version_ = 0;
// for Preview
int32 duration_ = 0;
Dimensions dimensions_;
@ -57,6 +62,14 @@ class MessageExtendedMedia {
void append_file_ids(const Td *td, vector<FileId> &file_ids) const;
int32 get_unsupported_version() const {
return unsupported_version_;
}
bool need_reget() const {
return type_ == Type::Unsupported && unsupported_version_ < CURRENT_VERSION;
}
template <class StorerT>
void store(StorerT &storer) const;

View File

@ -18,6 +18,7 @@ namespace td {
template <class StorerT>
void MessageExtendedMedia::store(StorerT &storer) const {
bool has_caption = !caption_.text.empty();
bool has_unsupported_version = unsupported_version_ != 0;
bool has_duration = duration_ != 0;
bool has_dimensions = dimensions_.width != 0 || dimensions_.height != 0;
bool has_minithumbnail = !minithumbnail_.empty();
@ -25,6 +26,7 @@ void MessageExtendedMedia::store(StorerT &storer) const {
bool has_video = video_file_id_.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_caption);
STORE_FLAG(has_unsupported_version);
STORE_FLAG(has_duration);
STORE_FLAG(has_dimensions);
STORE_FLAG(has_minithumbnail);
@ -35,6 +37,9 @@ void MessageExtendedMedia::store(StorerT &storer) const {
if (has_caption) {
td::store(caption_, storer);
}
if (has_unsupported_version) {
td::store(unsupported_version_, storer);
}
if (has_duration) {
td::store(duration_, storer);
}
@ -56,6 +61,7 @@ void MessageExtendedMedia::store(StorerT &storer) const {
template <class ParserT>
void MessageExtendedMedia::parse(ParserT &parser) {
bool has_caption;
bool has_unsupported_version;
bool has_duration;
bool has_dimensions;
bool has_minithumbnail;
@ -63,6 +69,7 @@ void MessageExtendedMedia::parse(ParserT &parser) {
bool has_video;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_caption);
PARSE_FLAG(has_unsupported_version);
PARSE_FLAG(has_duration);
PARSE_FLAG(has_dimensions);
PARSE_FLAG(has_minithumbnail);
@ -73,6 +80,9 @@ void MessageExtendedMedia::parse(ParserT &parser) {
if (has_caption) {
td::parse(caption_, parser);
}
if (has_unsupported_version) {
td::parse(unsupported_version_, parser);
}
if (has_duration) {
td::parse(duration_, parser);
}
@ -104,6 +114,7 @@ void MessageExtendedMedia::parse(ParserT &parser) {
photo_ = Photo();
video_file_id_ = FileId();
type_ = Type::Unsupported;
unsupported_version_ = 0;
}
}