diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 7bb5edab..3323946c 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -417,10 +417,15 @@ class MessageChatSetTtl : public MessageContent { } }; -class MessageUnsupported - : public MessageContent { // TODO save a layer in which the message was received to - // automatically reget it if the layer changes +class MessageUnsupported : public MessageContent { public: + static constexpr int32 CURRENT_VERSION = 1; + int32 version = CURRENT_VERSION; + + MessageUnsupported() = default; + explicit MessageUnsupported(int32 version) : version(version) { + } + MessageContentType get_type() const override { return MessageContentType::Unsupported; } @@ -782,8 +787,11 @@ static void store(const MessageContent *content, StorerT &storer) { store(m->web_page_id, storer); break; } - case MessageContentType::Unsupported: + case MessageContentType::Unsupported: { + auto m = static_cast(content); + store(m->version, storer); break; + } case MessageContentType::Venue: { auto m = static_cast(content); store(m->venue, storer); @@ -1067,9 +1075,16 @@ static void parse(unique_ptr &content, ParserT &parser) { content = std::move(m); break; } - case MessageContentType::Unsupported: - content = make_unique(); + case MessageContentType::Unsupported: { + auto m = make_unique(); + if (parser.version() >= static_cast(Version::AddMessageUnsupportedVersion)) { + parse(m->version, parser); + } else { + m->version = 0; + } + content = std::move(m); break; + } case MessageContentType::Venue: { auto m = make_unique(); parse(m->venue, parser); @@ -1270,7 +1285,7 @@ static void parse(unique_ptr &content, ParserT &parser) { } if (is_bad) { LOG(ERROR) << "Load a message with an invalid content of type " << content_type; - content = make_unique(); + content = make_unique(0); } } @@ -2976,8 +2991,14 @@ void merge_message_contents(Td *td, MessageContent *old_content, MessageContent } break; } - case MessageContentType::Unsupported: + case MessageContentType::Unsupported: { + auto old_ = static_cast(old_content); + auto new_ = static_cast(new_content); + if (old_->version != new_->version) { + is_content_changed = true; + } break; + } default: UNREACHABLE(); break; @@ -4119,9 +4140,8 @@ tl_object_ptr get_message_content_object(const MessageCo return make_tl_object(get_formatted_text_object(m->text), td->web_pages_manager_->get_web_page_object(m->web_page_id)); } - case MessageContentType::Unsupported: { + case MessageContentType::Unsupported: return make_tl_object(); - } case MessageContentType::Venue: { const MessageVenue *m = static_cast(content); return make_tl_object(m->venue.get_venue_object()); @@ -4494,6 +4514,18 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte } } +bool need_reget_message_content(const MessageContent *content) { + CHECK(content != nullptr); + switch (content->get_type()) { + case MessageContentType::Unsupported: { + auto message_unsupported = static_cast(content); + return message_unsupported->version != MessageUnsupported::CURRENT_VERSION; + } + default: + return false; + } +} + void update_expired_message_content(unique_ptr &content) { switch (content->get_type()) { case MessageContentType::Photo: diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index 0dba1f33..beee9680 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -218,6 +218,8 @@ vector get_message_content_file_ids(const MessageContent *content, const string get_message_content_search_text(const Td *td, const MessageContent *content); +bool need_reget_message_content(const MessageContent *content); + void update_expired_message_content(unique_ptr &content); void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index e587cb4e..a958056b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -21188,6 +21188,13 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq on_dialog_updated(dialog_id, "update_has_contact_registered_message"); } + if (message_id.is_server() && dialog_id.get_type() != DialogType::SecretChat && + need_reget_message_content(m->content.get())) { + FullMessageId full_message_id{dialog_id, message_id}; + LOG(INFO) << "Reget from server " << full_message_id; + get_messages_from_server({full_message_id}, Auto()); + } + if (from_update && message_id.is_server() && dialog_id.get_type() == DialogType::Channel) { int32 new_participant_count = get_message_content_new_participant_count(m->content.get()); if (new_participant_count != 0) { diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index d496218e..0d77a3d8 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2039,7 +2039,6 @@ void NotificationManager::get_current_state(vector= 0); + VLOG(notifications) << "Update pending notification count with diff " << diff << " to " + << pending_notification_update_count_; bool have_pending = pending_notification_update_count_ != 0; if (had_pending != have_pending && !is_destroyed_) { auto update = td_api::make_object(have_pending); diff --git a/td/telegram/Version.h b/td/telegram/Version.h index 5c2582a3..46bc1f11 100644 --- a/td/telegram/Version.h +++ b/td/telegram/Version.h @@ -26,6 +26,7 @@ enum class Version : int32 { AddVenueType, AddTermsOfService, AddContactVcard, + AddMessageUnsupportedVersion, Next };