From 314035a1298d5defac1fdb258871c12cb650d0b8 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 1 Oct 2021 11:22:56 +0300 Subject: [PATCH] Use MessagesDbMessage instead of std::pair. --- td/telegram/MessagesDb.cpp | 23 ++++++++++------------- td/telegram/MessagesDb.h | 15 +++++++-------- td/telegram/MessagesManager.cpp | 17 +++++++++-------- td/telegram/MessagesManager.h | 2 +- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 1c67f58ce..1c2c4d444 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -462,7 +462,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface { return BufferSlice(stmt.view_blob(0)); } - Result> get_message_by_unique_message_id(ServerMessageId unique_message_id) final { + Result get_message_by_unique_message_id(ServerMessageId unique_message_id) final { if (!unique_message_id.is_valid()) { return Status::Error("Invalid unique_message_id"); } @@ -475,7 +475,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface { return Status::Error("Not found"); } DialogId dialog_id(get_message_by_unique_message_id_stmt_.view_int64(0)); - return std::make_pair(dialog_id, BufferSlice(get_message_by_unique_message_id_stmt_.view_blob(1))); + return MessagesDbMessage{dialog_id, BufferSlice(get_message_by_unique_message_id_stmt_.view_blob(1))}; } Result get_message_by_random_id(DialogId dialog_id, int64 random_id) final { @@ -554,15 +554,14 @@ class MessagesDbImpl final : public MessagesDbSyncInterface { return Status::Error("Not found"); } - Result>, int32>> get_expiring_messages(int32 expires_from, - int32 expires_till, - int32 limit) final { + Result, int32>> get_expiring_messages(int32 expires_from, int32 expires_till, + int32 limit) final { SCOPE_EXIT { get_expiring_messages_stmt_.reset(); get_expiring_messages_helper_stmt_.reset(); }; - std::vector> messages; + std::vector messages; // load messages if (expires_from <= expires_till) { get_expiring_messages_stmt_.bind_int32(1, expires_from).ensure(); @@ -572,7 +571,7 @@ class MessagesDbImpl final : public MessagesDbSyncInterface { while (get_expiring_messages_stmt_.has_row()) { DialogId dialog_id(get_expiring_messages_stmt_.view_int64(0)); BufferSlice data(get_expiring_messages_stmt_.view_blob(1)); - messages.emplace_back(dialog_id, std::move(data)); + messages.push_back(MessagesDbMessage{dialog_id, std::move(data)}); get_expiring_messages_stmt_.step().ensure(); } } @@ -973,8 +972,7 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface { void get_message(FullMessageId full_message_id, Promise promise) final { send_closure_later(impl_, &Impl::get_message, full_message_id, std::move(promise)); } - void get_message_by_unique_message_id(ServerMessageId unique_message_id, - Promise> promise) final { + void get_message_by_unique_message_id(ServerMessageId unique_message_id, Promise promise) final { send_closure_later(impl_, &Impl::get_message_by_unique_message_id, unique_message_id, std::move(promise)); } void get_message_by_random_id(DialogId dialog_id, int64 random_id, Promise promise) final { @@ -1004,7 +1002,7 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface { send_closure_later(impl_, &Impl::get_messages_fts, std::move(query), std::move(promise)); } void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit, - Promise>, int32>> promise) final { + Promise, int32>> promise) final { send_closure_later(impl_, &Impl::get_expiring_messages, expires_from, expires_till, limit, std::move(promise)); } @@ -1063,8 +1061,7 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface { add_read_query(); promise.set_result(sync_db_->get_message(full_message_id)); } - void get_message_by_unique_message_id(ServerMessageId unique_message_id, - Promise> promise) { + void get_message_by_unique_message_id(ServerMessageId unique_message_id, Promise promise) { add_read_query(); promise.set_result(sync_db_->get_message_by_unique_message_id(unique_message_id)); } @@ -1100,7 +1097,7 @@ class MessagesDbAsync final : public MessagesDbAsyncInterface { promise.set_result(sync_db_->get_messages_fts(std::move(query))); } void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit, - Promise>, int32>> promise) { + Promise, int32>> promise) { add_read_query(); promise.set_result(sync_db_->get_expiring_messages(expires_from, expires_till, limit)); } diff --git a/td/telegram/MessagesDb.h b/td/telegram/MessagesDb.h index f63ed42f8..47fa54b24 100644 --- a/td/telegram/MessagesDb.h +++ b/td/telegram/MessagesDb.h @@ -77,8 +77,7 @@ class MessagesDbSyncInterface { virtual Status delete_dialog_messages_from_user(DialogId dialog_id, UserId sender_user_id) = 0; virtual Result get_message(FullMessageId full_message_id) = 0; - virtual Result> get_message_by_unique_message_id( - ServerMessageId unique_message_id) = 0; + virtual Result get_message_by_unique_message_id(ServerMessageId unique_message_id) = 0; virtual Result get_message_by_random_id(DialogId dialog_id, int64 random_id) = 0; virtual Result get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id, int32 date) = 0; @@ -89,8 +88,9 @@ class MessagesDbSyncInterface { NotificationId from_notification_id, int32 limit) = 0; - virtual Result>, int32>> get_expiring_messages( - int32 expires_from, int32 expires_till, int32 limit) = 0; + virtual Result, int32>> get_expiring_messages(int32 expires_from, + int32 expires_till, + int32 limit) = 0; virtual Result get_calls(MessagesDbCallsQuery query) = 0; virtual Result get_messages_fts(MessagesDbFtsQuery query) = 0; @@ -127,7 +127,7 @@ class MessagesDbAsyncInterface { virtual void get_message(FullMessageId full_message_id, Promise promise) = 0; virtual void get_message_by_unique_message_id(ServerMessageId unique_message_id, - Promise> promise) = 0; + Promise promise) = 0; virtual void get_message_by_random_id(DialogId dialog_id, int64 random_id, Promise promise) = 0; virtual void get_dialog_message_by_date(DialogId dialog_id, MessageId first_message_id, MessageId last_message_id, int32 date, Promise promise) = 0; @@ -140,9 +140,8 @@ class MessagesDbAsyncInterface { virtual void get_calls(MessagesDbCallsQuery, Promise promise) = 0; virtual void get_messages_fts(MessagesDbFtsQuery query, Promise promise) = 0; - virtual void get_expiring_messages( - int32 expires_from, int32 expires_till, int32 limit, - Promise>, int32>> promise) = 0; + virtual void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit, + Promise, int32>> promise) = 0; virtual void close(Promise<> promise) = 0; virtual void force_flush() = 0; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 7c1cbeed8..a681f8c83 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -12638,13 +12638,12 @@ void MessagesManager::ttl_db_loop(double server_now) { G()->td_db()->get_messages_db_async()->get_expiring_messages( ttl_db_expires_from_, ttl_db_expires_till_, limit, PromiseCreator::lambda( - [actor_id = actor_id(this)](Result>, int32>> result) { + [actor_id = actor_id(this)](Result, int32>> result) { send_closure(actor_id, &MessagesManager::ttl_db_on_result, std::move(result), false); })); } -void MessagesManager::ttl_db_on_result(Result>, int32>> r_result, - bool dummy) { +void MessagesManager::ttl_db_on_result(Result, int32>> r_result, bool dummy) { if (G()->close_flag()) { return; } @@ -12657,8 +12656,9 @@ void MessagesManager::ttl_db_on_result(Resultserver_time()); } @@ -16260,7 +16260,8 @@ vector MessagesManager::search_public_dialogs(const string &query, Pro auto d = get_dialog(dialog_id); if (d == nullptr || d->order != DEFAULT_ORDER || - (dialog_id.get_type() == DialogType::User && td_->contacts_manager_->is_user_contact(dialog_id.get_user_id()))) { + (dialog_id.get_type() == DialogType::User && + td_->contacts_manager_->is_user_contact(dialog_id.get_user_id()))) { continue; } @@ -34062,9 +34063,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()) { - DialogId dialog_id(r_value.ok().first); + 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().second, false, "get_dialog_by_message_id"); + r_value.ok().data, false, "get_dialog_by_message_id"); if (m != nullptr) { CHECK(m->message_id == message_id); LOG_CHECK(message_id_to_dialog_id_[message_id] == dialog_id) diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index c828ef389..395ed3fb9 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2735,7 +2735,7 @@ class MessagesManager final : public Actor { void ttl_db_loop_start(double server_now); void ttl_db_loop(double server_now); - void ttl_db_on_result(Result>, int32>> r_result, bool dummy); + void ttl_db_on_result(Result, int32>> r_result, bool dummy); void on_get_message_link_dialog(MessageLinkInfo &&info, Promise &&promise);