Add source to register_message_content.

GitOrigin-RevId: 035429321a0fa15ea8918c634b19f12c21fc1d61
This commit is contained in:
levlam 2020-02-22 19:21:58 +03:00
parent 283a82cfa3
commit 04a002d9f3
7 changed files with 45 additions and 38 deletions

View File

@ -3174,20 +3174,22 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
return false;
}
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id) {
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id,
const char *source) {
switch (content->get_type()) {
case MessageContentType::Text:
return td->web_pages_manager_->register_web_page(static_cast<const MessageText *>(content)->web_page_id,
full_message_id);
full_message_id, source);
case MessageContentType::Poll:
return td->poll_manager_->register_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id);
return td->poll_manager_->register_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id,
source);
default:
return;
}
}
void reregister_message_content(Td *td, const MessageContent *old_content, const MessageContent *new_content,
FullMessageId full_message_id) {
FullMessageId full_message_id, const char *source) {
auto old_content_type = old_content->get_type();
auto new_content_type = new_content->get_type();
if (old_content_type == new_content_type) {
@ -3208,17 +3210,19 @@ void reregister_message_content(Td *td, const MessageContent *old_content, const
return;
}
}
unregister_message_content(td, old_content, full_message_id);
register_message_content(td, new_content, full_message_id);
unregister_message_content(td, old_content, full_message_id, source);
register_message_content(td, new_content, full_message_id, source);
}
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id) {
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id,
const char *source) {
switch (content->get_type()) {
case MessageContentType::Text:
return td->web_pages_manager_->unregister_web_page(static_cast<const MessageText *>(content)->web_page_id,
full_message_id);
full_message_id, source);
case MessageContentType::Poll:
return td->poll_manager_->unregister_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id);
return td->poll_manager_->unregister_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id,
source);
default:
return;
}

View File

@ -153,12 +153,13 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
bool merge_message_content_file_id(Td *td, MessageContent *message_content, FileId new_file_id);
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id, const char *source);
void reregister_message_content(Td *td, const MessageContent *old_content, const MessageContent *new_content,
FullMessageId full_message_id);
FullMessageId full_message_id, const char *source);
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id);
void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id,
const char *source);
unique_ptr<MessageContent> get_secret_message_content(
Td *td, string message_text, tl_object_ptr<telegram_api::encryptedFile> file,

View File

@ -10236,10 +10236,10 @@ void MessagesManager::on_message_ttl_expired(Dialog *d, Message *m) {
CHECK(m->ttl > 0);
CHECK(d->dialog_id.get_type() != DialogType::SecretChat);
ttl_unregister_message(d->dialog_id, m, Time::now(), "on_message_ttl_expired");
unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id});
unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id}, "on_message_ttl_expired");
remove_message_file_sources(d->dialog_id, m);
on_message_ttl_expired_impl(d, m);
register_message_content(td_, m->content.get(), {d->dialog_id, m->message_id});
register_message_content(td_, m->content.get(), {d->dialog_id, m->message_id}, "on_message_ttl_expired");
send_update_message_content(d->dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret,
"on_message_ttl_expired");
}
@ -11960,7 +11960,8 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
is_content_changed, need_update);
if (is_content_changed || need_update) {
reregister_message_content(td_, m->content.get(), new_content.get(), full_message_id);
reregister_message_content(td_, m->content.get(), new_content.get(), full_message_id,
"on_update_sent_text_message");
m->content = std::move(new_content);
m->is_content_secret = is_secret_message_content(m->ttl, MessageContentType::Text);
}
@ -11978,9 +11979,9 @@ void MessagesManager::delete_pending_message_web_page(FullMessageId full_message
CHECK(m != nullptr);
MessageContent *content = m->content.get();
unregister_message_content(td_, content, full_message_id);
unregister_message_content(td_, content, full_message_id, "delete_pending_message_web_page");
remove_message_content_web_page(content);
register_message_content(td_, content, full_message_id);
register_message_content(td_, content, full_message_id, "delete_pending_message_web_page");
// don't need to send an updateMessageContent, because the web page was pending
@ -12889,7 +12890,7 @@ void MessagesManager::on_message_deleted(Dialog *d, Message *m, bool is_permanen
UNREACHABLE();
}
ttl_unregister_message(d->dialog_id, m, Time::now(), source);
unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id});
unregister_message_content(td_, m->content.get(), {d->dialog_id, m->message_id}, "on_message_deleted");
if (m->notification_id.is_valid()) {
delete_notification_id_to_message_id_correspondence(d, m->notification_id, m->message_id);
}
@ -12935,7 +12936,7 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_scheduled_messag
cancel_send_deleted_message(d->dialog_id, result.get(), is_permanently_deleted);
unregister_message_content(td_, result->content.get(), {d->dialog_id, message_id});
unregister_message_content(td_, result->content.get(), {d->dialog_id, message_id}, "do_delete_scheduled_message");
return result;
}
@ -26431,7 +26432,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
add_message_file_sources(dialog_id, m);
register_message_content(td_, m->content.get(), {dialog_id, m->message_id});
register_message_content(td_, m->content.get(), {dialog_id, m->message_id}, "add_message_to_dialog");
if (*need_update && m->message_id.is_server() && message_content_type == MessageContentType::PinMessage) {
// always update pinned message from service message, even new pinned_message_id is invalid
@ -26600,7 +26601,7 @@ MessagesManager::Message *MessagesManager::add_scheduled_message_to_dialog(Dialo
add_message_file_sources(dialog_id, m);
register_message_content(td_, m->content.get(), {dialog_id, m->message_id});
register_message_content(td_, m->content.get(), {dialog_id, m->message_id}, "add_scheduled_message_to_dialog");
if (from_update) {
update_sent_message_contents(dialog_id, m);
@ -27363,7 +27364,8 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me
if (is_content_changed || need_update) {
if (is_message_in_dialog) {
reregister_message_content(td_, old_content.get(), new_content.get(), {dialog_id, old_message->message_id});
reregister_message_content(td_, old_content.get(), new_content.get(), {dialog_id, old_message->message_id},
"update_message_content");
}
old_content = std::move(new_content);
update_message_content_file_id_remote(old_content.get(), old_file_id);

View File

@ -570,7 +570,7 @@ PollId PollManager::create_poll(string &&question, vector<string> &&options, boo
return poll_id;
}
void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id) {
void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id, const char *source) {
CHECK(have_poll(poll_id));
if (full_message_id.get_message_id().is_scheduled()) {
return;
@ -578,15 +578,15 @@ void PollManager::register_poll(PollId poll_id, FullMessageId full_message_id) {
if (!full_message_id.get_message_id().is_server()) {
return;
}
LOG(INFO) << "Register " << poll_id << " from " << full_message_id;
LOG(INFO) << "Register " << poll_id << " from " << full_message_id << " from " << source;
bool is_inserted = poll_messages_[poll_id].insert(full_message_id).second;
CHECK(is_inserted);
LOG_CHECK(is_inserted) << source << " " << poll_id << full_message_id;
if (!td_->auth_manager_->is_bot() && !is_local_poll_id(poll_id) && !get_poll_is_closed(poll_id)) {
update_poll_timeout_.add_timeout_in(poll_id.get(), 0);
}
}
void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id) {
void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id, const char *source) {
CHECK(have_poll(poll_id));
if (full_message_id.get_message_id().is_scheduled()) {
return;
@ -594,10 +594,10 @@ void PollManager::unregister_poll(PollId poll_id, FullMessageId full_message_id)
if (!full_message_id.get_message_id().is_server()) {
return;
}
LOG(INFO) << "Unregister " << poll_id << " from " << full_message_id;
LOG(INFO) << "Unregister " << poll_id << " from " << full_message_id << " from " << source;
auto &message_ids = poll_messages_[poll_id];
auto is_deleted = message_ids.erase(full_message_id);
CHECK(is_deleted);
LOG_CHECK(is_deleted) << source << " " << poll_id << full_message_id;
if (message_ids.empty()) {
poll_messages_.erase(poll_id);
update_poll_timeout_.cancel_timeout(poll_id.get());

View File

@ -47,9 +47,9 @@ class PollManager : public Actor {
PollId create_poll(string &&question, vector<string> &&options, bool is_anonymous, bool allow_multiple_answers,
bool is_quiz, int32 correct_option_id, bool is_closed);
void register_poll(PollId poll_id, FullMessageId full_message_id);
void register_poll(PollId poll_id, FullMessageId full_message_id, const char *source);
void unregister_poll(PollId poll_id, FullMessageId full_message_id);
void unregister_poll(PollId poll_id, FullMessageId full_message_id, const char *source);
bool get_poll_is_closed(PollId poll_id) const;

View File

@ -650,14 +650,14 @@ void WebPagesManager::on_get_web_page_by_url(const string &url, WebPageId web_pa
cached_web_page_id = web_page_id;
}
void WebPagesManager::register_web_page(WebPageId web_page_id, FullMessageId full_message_id) {
void WebPagesManager::register_web_page(WebPageId web_page_id, FullMessageId full_message_id, const char *source) {
if (!web_page_id.is_valid()) {
return;
}
LOG(INFO) << "Register " << web_page_id << " from " << full_message_id;
LOG(INFO) << "Register " << web_page_id << " from " << full_message_id << " from " << source;
bool is_inserted = web_page_messages_[web_page_id].insert(full_message_id).second;
CHECK(is_inserted);
LOG_CHECK(is_inserted) << source << " " << web_page_id << full_message_id;
if (!td_->auth_manager_->is_bot() && !have_web_page_force(web_page_id)) {
LOG(INFO) << "Waiting for " << web_page_id << " needed in " << full_message_id;
@ -665,15 +665,15 @@ void WebPagesManager::register_web_page(WebPageId web_page_id, FullMessageId ful
}
}
void WebPagesManager::unregister_web_page(WebPageId web_page_id, FullMessageId full_message_id) {
void WebPagesManager::unregister_web_page(WebPageId web_page_id, FullMessageId full_message_id, const char *source) {
if (!web_page_id.is_valid()) {
return;
}
LOG(INFO) << "Unregister " << web_page_id << " from " << full_message_id;
LOG(INFO) << "Unregister " << web_page_id << " from " << full_message_id << " from " << source;
auto &message_ids = web_page_messages_[web_page_id];
auto is_deleted = message_ids.erase(full_message_id);
CHECK(is_deleted);
LOG_CHECK(is_deleted) << source << " " << web_page_id << full_message_id;
if (message_ids.empty()) {
web_page_messages_.erase(web_page_id);

View File

@ -47,9 +47,9 @@ class WebPagesManager : public Actor {
void on_get_web_page_by_url(const string &url, WebPageId web_page_id, bool from_database);
void register_web_page(WebPageId web_page_id, FullMessageId full_message_id);
void register_web_page(WebPageId web_page_id, FullMessageId full_message_id, const char *source);
void unregister_web_page(WebPageId web_page_id, FullMessageId full_message_id);
void unregister_web_page(WebPageId web_page_id, FullMessageId full_message_id, const char *source);
bool have_web_page(WebPageId web_page_id) const;