Add reregister_message_content.

GitOrigin-RevId: 53c250a8e805dba37dc4ee255472935762ee609a
This commit is contained in:
levlam 2020-01-25 03:50:23 +03:00
parent 21f1f4510c
commit 67e4871ea0
5 changed files with 39 additions and 14 deletions

View File

@ -3486,6 +3486,29 @@ void register_message_content(Td *td, const MessageContent *content, FullMessage
}
}
void reregister_message_content(Td *td, const MessageContent *old_content, const MessageContent *new_content,
FullMessageId full_message_id) {
if (full_message_id.get_message_id().is_scheduled()) {
return;
}
auto old_content_type = old_content->get_type();
auto new_content_type = new_content->get_type();
if (old_content_type == new_content_type) {
switch (old_content_type) {
case MessageContentType::Poll:
if (static_cast<const MessagePoll *>(old_content)->poll_id ==
static_cast<const MessagePoll *>(new_content)->poll_id) {
return;
}
break;
default:
return;
}
}
unregister_message_content(td, old_content, full_message_id);
register_message_content(td, new_content, full_message_id);
}
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id) {
if (full_message_id.get_message_id().is_scheduled()) {
return;

View File

@ -208,6 +208,9 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
void reregister_message_content(Td *td, const MessageContent *old_content, const MessageContent *new_content,
FullMessageId full_message_id);
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
unique_ptr<MessageContent> get_secret_message_content(

View File

@ -5744,15 +5744,17 @@ void MessagesManager::on_update_some_live_location_viewed(Promise<Unit> &&promis
promise.set_value(Unit());
}
void MessagesManager::on_update_message_content(FullMessageId full_message_id) {
void MessagesManager::on_external_update_message_content(FullMessageId full_message_id) {
const Dialog *d = get_dialog(full_message_id.get_dialog_id());
CHECK(d != nullptr);
const Message *m = get_message(d, full_message_id.get_message_id());
CHECK(m != nullptr);
auto live_location_date = m->is_failed_to_send ? 0 : m->date;
send_update_message_content(full_message_id.get_dialog_id(), m->message_id, m->content.get(), live_location_date,
m->is_content_secret, "on_update_message_content");
on_message_changed(d, m, true, "on_update_message_content");
m->is_content_secret, "on_external_update_message_content");
if (m->message_id == d->last_message_id) {
send_update_chat_last_message_impl(d, "on_external_update_message_content");
}
}
bool MessagesManager::update_message_contains_unread_mention(Dialog *d, Message *m, bool contains_unread_mention,
@ -11870,18 +11872,16 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
return;
}
unregister_message_content(td_, m->content.get(), full_message_id);
bool need_update = false;
bool is_content_changed = false;
merge_message_contents(td_, m->content.get(), new_content.get(), need_message_changed_warning(m), dialog_id, false,
is_content_changed, need_update);
if (is_content_changed || need_update) {
reregister_message_content(td_, m->content.get(), new_content.get(), full_message_id);
m->content = std::move(new_content);
m->is_content_secret = is_secret_message_content(m->ttl, MessageContentType::Text);
}
register_message_content(td_, m->content.get(), full_message_id);
if (need_update) {
send_update_message_content(dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret,
"on_update_sent_text_message");
@ -11914,10 +11914,12 @@ void MessagesManager::on_update_message_web_page(FullMessageId full_message_id,
CHECK(content->get_type() == MessageContentType::Text);
if (!have_web_page) {
unregister_message_content(td_, content, full_message_id);
set_message_content_web_page_id(content, WebPageId());
// don't need to send an update
register_message_content(td_, content, full_message_id);
on_message_changed(d, m, true, "on_update_message_web_page");
// don't need to send an update, because the web page was pending
on_message_changed(d, m, false, "on_update_message_web_page");
return;
}
@ -27333,12 +27335,9 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me
if (is_content_changed || need_update) {
if (is_message_in_dialog) {
unregister_message_content(td_, old_content.get(), {dialog_id, old_message->message_id});
reregister_message_content(td_, old_content.get(), new_content.get(), {dialog_id, old_message->message_id});
}
old_content = std::move(new_content);
if (is_message_in_dialog) {
register_message_content(td_, old_content.get(), {dialog_id, old_message->message_id});
}
update_message_content_file_id_remote(old_content.get(), old_file_id);
} else {
update_message_content_file_id_remote(old_content.get(), get_message_content_any_file_id(new_content.get()));

View File

@ -315,7 +315,7 @@ class MessagesManager : public Actor {
void on_update_some_live_location_viewed(Promise<Unit> &&promise);
void on_update_message_content(FullMessageId full_message_id);
void on_external_update_message_content(FullMessageId full_message_id);
void on_read_channel_inbox(ChannelId channel_id, MessageId max_message_id, int32 server_unread_count, int32 pts,
const char *source);

View File

@ -304,7 +304,7 @@ void PollManager::notify_on_poll_update(PollId poll_id) {
}
for (auto full_message_id : it->second) {
td_->messages_manager_->on_update_message_content(full_message_id);
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
}