From 813e32a2650fcf290d42a1112542fa90c4608146 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 1 Oct 2021 11:36:32 +0300 Subject: [PATCH] Simplify on_get_message_from_database usage. --- td/telegram/MessagesManager.cpp | 40 ++++++++++++++++----------------- td/telegram/MessagesManager.h | 4 +++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a681f8c83..1e6044e20 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -12656,9 +12656,7 @@ void MessagesManager::ttl_db_on_result(Resultserver_time()); } @@ -21761,7 +21759,7 @@ void MessagesManager::on_search_dialog_messages_db_result(int64 random_id, Dialo res.reserve(messages.size()); for (auto &message : messages) { - auto m = on_get_message_from_database(dialog_id, d, message, false, "on_search_dialog_messages_db_result"); + auto m = on_get_message_from_database(d, dialog_id, message, false, "on_search_dialog_messages_db_result"); if (m != nullptr && first_db_message_id <= m->message_id) { if (filter == MessageSearchFilter::UnreadMention && !m->contains_unread_mention) { // skip already read by d->last_read_all_mentions_message_id mentions @@ -21897,9 +21895,7 @@ void MessagesManager::on_messages_db_fts_result(Result resu res.reserve(fts_result.messages.size()); for (auto &message : fts_result.messages) { - auto m = on_get_message_from_database(message.dialog_id, - get_dialog_force(message.dialog_id, "on_messages_db_fts_result"), - message.data, false, "on_messages_db_fts_result"); + auto m = on_get_message_from_database(message, false, "on_messages_db_fts_result"); if (m != nullptr) { res.push_back(FullMessageId(message.dialog_id, m->message_id)); } @@ -21932,9 +21928,7 @@ void MessagesManager::on_messages_db_calls_result(Result res.reserve(calls_result.messages.size()); for (auto &message : calls_result.messages) { - auto m = on_get_message_from_database(message.dialog_id, - get_dialog_force(message.dialog_id, "on_messages_db_calls_result"), - message.data, false, "on_messages_db_calls_result"); + auto m = on_get_message_from_database(message, false, "on_messages_db_calls_result"); if (m != nullptr && first_db_message_id <= m->message_id) { res.push_back(FullMessageId(message.dialog_id, m->message_id)); @@ -22085,7 +22079,7 @@ void MessagesManager::on_get_dialog_message_by_date_from_database(DialogId dialo CHECK(d != nullptr); if (result.is_ok()) { Message *m = - on_get_message_from_database(dialog_id, d, result.ok(), false, "on_get_dialog_message_by_date_from_database"); + on_get_message_from_database(d, dialog_id, result.ok(), false, "on_get_dialog_message_by_date_from_database"); if (m != nullptr) { auto message_id = find_message_by_date(d->messages.get(), date); if (!message_id.is_valid()) { @@ -27511,7 +27505,7 @@ vector MessagesManager::get_message_notifications_from_database_fo << " messages with notifications from database in " << group_info.group_id << '/' << d->dialog_id; for (auto &message : messages) { - auto m = on_get_message_from_database(d->dialog_id, d, std::move(message), false, + auto m = on_get_message_from_database(d, d->dialog_id, message, false, "get_message_notifications_from_database_force"); if (m == nullptr) { VLOG(notifications) << "Receive from database a broken message"; @@ -27767,8 +27761,7 @@ void MessagesManager::on_get_message_notifications_from_database(DialogId dialog VLOG(notifications) << "Loaded " << messages.size() << " messages with notifications in " << group_info.group_id << '/' << dialog_id << " from database"; for (auto &message : messages) { - auto m = on_get_message_from_database(dialog_id, d, std::move(message), false, - "on_get_message_notifications_from_database"); + auto m = on_get_message_from_database(d, dialog_id, message, false, "on_get_message_notifications_from_database"); if (m == nullptr) { VLOG(notifications) << "Receive from database a broken message"; continue; @@ -27942,7 +27935,7 @@ void MessagesManager::do_remove_message_notification(DialogId dialog_id, bool fr Dialog *d = get_dialog(dialog_id); CHECK(d != nullptr); - auto m = on_get_message_from_database(dialog_id, d, std::move(result[0]), false, "do_remove_message_notification"); + auto m = on_get_message_from_database(d, dialog_id, result[0], false, "do_remove_message_notification"); if (m != nullptr && m->notification_id == notification_id && is_from_mention_notification_group(d, m) == from_mentions && is_message_notification_active(d, m)) { remove_message_notification_id(d, m, false, false); @@ -32127,10 +32120,16 @@ MessagesManager::Message *MessagesManager::get_message_force(Dialog *d, MessageI if (r_value.is_error()) { return nullptr; } - return on_get_message_from_database(d->dialog_id, d, r_value.ok(), message_id.is_scheduled(), source); + return on_get_message_from_database(d, d->dialog_id, r_value.ok(), message_id.is_scheduled(), source); } -MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId dialog_id, Dialog *d, +MessagesManager::Message *MessagesManager::on_get_message_from_database(const MessagesDbMessage &message, + bool is_scheduled, const char *source) { + return on_get_message_from_database(get_dialog_force(message.dialog_id, source), message.dialog_id, message.data, + is_scheduled, source); +} + +MessagesManager::Message *MessagesManager::on_get_message_from_database(Dialog *d, DialogId dialog_id, const BufferSlice &value, bool is_scheduled, const char *source) { if (value.empty()) { @@ -34063,10 +34062,9 @@ MessagesManager::Dialog *MessagesManager::get_dialog_by_message_id(MessageId mes auto r_value = G()->td_db()->get_messages_db_sync()->get_message_by_unique_message_id(message_id.get_server_message_id()); if (r_value.is_ok()) { - auto dialog_id = r_value.ok().dialog_id; - Message *m = on_get_message_from_database(dialog_id, get_dialog_force(dialog_id, "get_dialog_by_message_id"), - r_value.ok().data, false, "get_dialog_by_message_id"); + Message *m = on_get_message_from_database(r_value.ok(), false, "get_dialog_by_message_id"); if (m != nullptr) { + auto dialog_id = r_value.ok().dialog_id; CHECK(m->message_id == message_id); LOG_CHECK(message_id_to_dialog_id_[message_id] == dialog_id) << message_id << ' ' << dialog_id << ' ' << message_id_to_dialog_id_[message_id] << ' ' @@ -34097,7 +34095,7 @@ MessageId MessagesManager::get_message_id_by_random_id(Dialog *d, int64 random_i auto r_value = G()->td_db()->get_messages_db_sync()->get_message_by_random_id(d->dialog_id, random_id); if (r_value.is_ok()) { debug_add_message_to_dialog_fail_reason_ = "not called"; - Message *m = on_get_message_from_database(d->dialog_id, d, r_value.ok(), false, "get_message_id_by_random_id"); + Message *m = on_get_message_from_database(d, d->dialog_id, r_value.ok(), false, "get_message_id_by_random_id"); if (m != nullptr) { LOG_CHECK(m->random_id == random_id) << random_id << " " << m->random_id << " " << d->random_id_to_message_id[random_id] << " " diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 395ed3fb9..10d896c6f 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2659,7 +2659,9 @@ class MessagesManager final : public Actor { void get_message_force_from_server(Dialog *d, MessageId message_id, Promise &&promise, tl_object_ptr input_message = nullptr); - Message *on_get_message_from_database(DialogId dialog_id, Dialog *d, const BufferSlice &value, bool is_scheduled, + Message *on_get_message_from_database(const MessagesDbMessage &message, bool is_scheduled, const char *source); + + Message *on_get_message_from_database(Dialog *d, DialogId dialog_id, const BufferSlice &value, bool is_scheduled, const char *source); void get_dialog_message_by_date_from_server(const Dialog *d, int32 date, int64 random_id, bool after_database_search,