Better MessageUnsupported support.

GitOrigin-RevId: 7b2b83c83e8b602dfd371fb5c9c598b3a5c31839
This commit is contained in:
levlam 2018-12-25 20:47:37 +03:00
parent 480772c4cf
commit 4ec320cd0a
5 changed files with 54 additions and 11 deletions

View File

@ -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<const MessageUnsupported *>(content);
store(m->version, storer);
break;
}
case MessageContentType::Venue: {
auto m = static_cast<const MessageVenue *>(content);
store(m->venue, storer);
@ -1067,9 +1075,16 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
content = std::move(m);
break;
}
case MessageContentType::Unsupported:
content = make_unique<MessageUnsupported>();
case MessageContentType::Unsupported: {
auto m = make_unique<MessageUnsupported>();
if (parser.version() >= static_cast<int32>(Version::AddMessageUnsupportedVersion)) {
parse(m->version, parser);
} else {
m->version = 0;
}
content = std::move(m);
break;
}
case MessageContentType::Venue: {
auto m = make_unique<MessageVenue>();
parse(m->venue, parser);
@ -1270,7 +1285,7 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
}
if (is_bad) {
LOG(ERROR) << "Load a message with an invalid content of type " << content_type;
content = make_unique<MessageUnsupported>();
content = make_unique<MessageUnsupported>(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<const MessageUnsupported *>(old_content);
auto new_ = static_cast<const MessageUnsupported *>(new_content);
if (old_->version != new_->version) {
is_content_changed = true;
}
break;
}
default:
UNREACHABLE();
break;
@ -4119,9 +4140,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
return make_tl_object<td_api::messageText>(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<td_api::messageUnsupported>();
}
case MessageContentType::Venue: {
const MessageVenue *m = static_cast<const MessageVenue *>(content);
return make_tl_object<td_api::messageVenue>(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<const MessageUnsupported *>(content);
return message_unsupported->version != MessageUnsupported::CURRENT_VERSION;
}
default:
return false;
}
}
void update_expired_message_content(unique_ptr<MessageContent> &content) {
switch (content->get_type()) {
case MessageContentType::Photo:

View File

@ -218,6 +218,8 @@ vector<FileId> 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<MessageContent> &content);
void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content);

View File

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

View File

@ -2039,7 +2039,6 @@ void NotificationManager::get_current_state(vector<td_api::object_ptr<td_api::Up
void NotificationManager::flush_all_notifications() {
flush_all_pending_notifications();
flush_all_pending_updates(true, "flush_all_notifications");
CHECK(pending_notification_update_count_ == 0);
}
void NotificationManager::destroy_all_notifications() {
@ -2071,6 +2070,8 @@ void NotificationManager::on_pending_notification_update_count_changed(int32 dif
bool had_pending = pending_notification_update_count_ != 0;
pending_notification_update_count_ += diff;
CHECK(pending_notification_update_count_ >= 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<td_api::updateHavePendingNotifications>(have_pending);

View File

@ -26,6 +26,7 @@ enum class Version : int32 {
AddVenueType,
AddTermsOfService,
AddContactVcard,
AddMessageUnsupportedVersion,
Next
};