Find MediaTimestamp entities in old messages.

This commit is contained in:
levlam 2021-08-09 19:37:47 +03:00
parent 0c3a9aebd8
commit 4b631b16bf
6 changed files with 34 additions and 3 deletions

View File

@ -4880,6 +4880,10 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
return nullptr;
}
FormattedText *get_message_content_text_mutable(MessageContent *content) {
return const_cast<FormattedText *>(get_message_content_text(content));
}
const FormattedText *get_message_content_text(const MessageContent *content) {
switch (content->get_type()) {
case MessageContentType::Text:

View File

@ -201,6 +201,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
bool is_content_secret, bool skip_bot_commands,
int32 max_media_timestamp);
FormattedText *get_message_content_text_mutable(MessageContent *content);
const FormattedText *get_message_content_text(const MessageContent *content);
const FormattedText *get_message_content_caption(const MessageContent *content);

View File

@ -83,6 +83,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity::Ty
StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &message_entity) {
string_builder << '[' << message_entity.type << ", offset = " << message_entity.offset
<< ", length = " << message_entity.length;
if (message_entity.media_timestamp >= 0) {
string_builder << ", media_timestamp = \"" << message_entity.media_timestamp << "\"";
}
if (!message_entity.argument.empty()) {
string_builder << ", argument = \"" << message_entity.argument << "\"";
}

View File

@ -74,8 +74,8 @@ class MessageEntity {
tl_object_ptr<td_api::textEntity> get_text_entity_object() const;
bool operator==(const MessageEntity &other) const {
return offset == other.offset && length == other.length && type == other.type && argument == other.argument &&
user_id == other.user_id;
return offset == other.offset && length == other.length && type == other.type &&
media_timestamp == other.media_timestamp && argument == other.argument && user_id == other.user_id;
}
bool operator<(const MessageEntity &other) const {

View File

@ -4859,6 +4859,8 @@ void MessagesManager::Message::store(StorerT &storer) const {
bool is_imported = is_forwarded && forward_info->is_imported;
bool has_ttl_period = ttl_period != 0;
bool has_max_reply_media_timestamp = max_reply_media_timestamp >= 0;
bool are_message_media_timestamp_entities_found = true;
bool has_flags3 = false;
BEGIN_STORE_FLAGS();
STORE_FLAG(is_channel_post);
STORE_FLAG(is_outgoing);
@ -4919,8 +4921,10 @@ void MessagesManager::Message::store(StorerT &storer) const {
STORE_FLAG(has_interaction_info_update_date);
STORE_FLAG(has_send_emoji);
STORE_FLAG(is_imported);
STORE_FLAG(has_ttl_period); // 25
STORE_FLAG(has_ttl_period);
STORE_FLAG(has_max_reply_media_timestamp);
STORE_FLAG(are_message_media_timestamp_entities_found);
STORE_FLAG(has_flags3);
END_STORE_FLAGS();
}
@ -5081,6 +5085,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
bool is_imported = false;
bool has_ttl_period = false;
bool has_max_reply_media_timestamp = false;
bool has_flags3 = false;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_channel_post);
PARSE_FLAG(is_outgoing);
@ -5143,6 +5148,12 @@ void MessagesManager::Message::parse(ParserT &parser) {
PARSE_FLAG(is_imported);
PARSE_FLAG(has_ttl_period);
PARSE_FLAG(has_max_reply_media_timestamp);
PARSE_FLAG(are_media_timestamp_entities_found);
PARSE_FLAG(has_flags3);
END_PARSE_FLAGS();
}
if (has_flags3) {
BEGIN_PARSE_FLAGS();
END_PARSE_FLAGS();
}
@ -32426,6 +32437,16 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
}
if (message->from_database && !message->are_media_timestamp_entities_found) {
auto text = get_message_content_text_mutable(message->content.get());
if (text != nullptr) {
fix_formatted_text(text->text, text->entities, true, true, true, false, false).ensure();
// always call to save are_media_timestamp_entities_found flag
on_message_changed(d, message.get(), false, "save media timestamp entities");
}
}
message->are_media_timestamp_entities_found = true;
LOG(INFO) << "Adding not found " << message_id << " to " << dialog_id << " from " << source;
if (d->is_empty) {
d->is_empty = false;

View File

@ -1038,6 +1038,7 @@ class MessagesManager final : public Actor {
bool is_mention_notification_disabled = false;
bool is_from_scheduled = false;
bool is_pinned = false;
bool are_media_timestamp_entities_found = false;
bool is_copy = false; // for send_message
bool from_background = false; // for send_message