From cb3f390a926b15e491cf3ccbb98fe329ff32d431 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 22 Sep 2020 02:15:09 +0300 Subject: [PATCH] Unify "log event" spelling. GitOrigin-RevId: a1a491981596c56dbf7541d80ead1ea9f5d5bd04 --- SplitSource.php | 2 +- td/telegram/BackgroundManager.cpp | 26 +- td/telegram/ContactsManager.cpp | 104 ++-- td/telegram/ContactsManager.h | 8 +- td/telegram/MessagesManager.cpp | 579 +++++++++--------- td/telegram/MessagesManager.h | 100 +-- td/telegram/NotificationManager.cpp | 82 +-- td/telegram/NotificationManager.h | 8 +- td/telegram/PollManager.cpp | 58 +- td/telegram/PollManager.h | 6 +- td/telegram/SecretChatActor.cpp | 226 +++---- td/telegram/SecretChatActor.h | 38 +- td/telegram/SecretChatsManager.cpp | 38 +- td/telegram/SecretChatsManager.h | 10 +- td/telegram/Td.cpp | 2 +- td/telegram/TdDb.cpp | 2 +- td/telegram/WebPagesManager.cpp | 30 +- td/telegram/files/FileDb.cpp | 4 +- td/telegram/files/FileManager.cpp | 2 +- td/telegram/files/FileStatsWorker.cpp | 2 +- td/telegram/logevent/LogEvent.h | 28 +- td/telegram/logevent/LogEventHelper.cpp | 40 +- td/telegram/logevent/LogEventHelper.h | 8 +- td/telegram/logevent/SecretChatEvent.h | 16 +- tddb/td/db/TQueue.cpp | 36 +- tddb/td/db/TQueue.h | 10 +- tddb/td/db/binlog/Binlog.h | 14 +- tddb/td/db/binlog/BinlogHelper.h | 8 +- tddb/td/db/binlog/BinlogInterface.h | 14 +- .../binlog/detail/BinlogEventsProcessor.cpp | 2 +- test/secret.cpp | 18 +- 31 files changed, 762 insertions(+), 759 deletions(-) diff --git a/SplitSource.php b/SplitSource.php index 8fa3f8f80..3316e64ba 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -273,7 +273,7 @@ function split_file($file, $chunks, $undo) { 'HashtagHints' => 'HashtagHints', 'inline_queries_manager[_(-][^.]|InlineQueriesManager' => 'InlineQueriesManager', 'language_pack_manager[_(-][^.]|LanguagePackManager' => 'LanguagePackManager', - 'LogeventIdWithGeneration|add_log_event|delete_log_event|get_erase_logevent_promise|parse_time|store_time' => 'logevent/LogEventHelper', + 'LogeventIdWithGeneration|add_log_event|delete_log_event|get_erase_log_event_promise|parse_time|store_time' => 'logevent/LogEventHelper', 'MessageCopyOptions' => 'MessageCopyOptions', 'messages_manager[_(-][^.]|MessagesManager' => 'MessagesManager', 'notification_manager[_(-][^.]|NotificationManager|notifications[)]' => 'NotificationManager', diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 9c01e487b..76b40939e 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -318,22 +318,22 @@ class BackgroundManager::BackgroundLogEvent { void BackgroundManager::start_up() { for (int i = 0; i < 2; i++) { bool for_dark_theme = i != 0; - auto logevent_string = G()->td_db()->get_binlog_pmc()->get(get_background_database_key(for_dark_theme)); - if (!logevent_string.empty()) { - BackgroundLogEvent logevent; - log_event_parse(logevent, logevent_string).ensure(); + auto log_event_string = G()->td_db()->get_binlog_pmc()->get(get_background_database_key(for_dark_theme)); + if (!log_event_string.empty()) { + BackgroundLogEvent log_event; + log_event_parse(log_event, log_event_string).ensure(); - CHECK(logevent.background_.id.is_valid()); - bool needs_file_id = logevent.background_.type.type != BackgroundType::Type::Fill; - if (logevent.background_.file_id.is_valid() != needs_file_id) { - LOG(ERROR) << "Failed to load " << logevent.background_.id << " of " << logevent.background_.type; + CHECK(log_event.background_.id.is_valid()); + bool needs_file_id = log_event.background_.type.type != BackgroundType::Type::Fill; + if (log_event.background_.file_id.is_valid() != needs_file_id) { + LOG(ERROR) << "Failed to load " << log_event.background_.id << " of " << log_event.background_.type; G()->td_db()->get_binlog_pmc()->erase(get_background_database_key(for_dark_theme)); continue; } - set_background_id_[for_dark_theme] = logevent.background_.id; - set_background_type_[for_dark_theme] = logevent.set_type_; + set_background_id_[for_dark_theme] = log_event.background_.id; + set_background_type_[for_dark_theme] = log_event.set_type_; - add_background(logevent.background_); + add_background(log_event.background_); } send_update_selected_background(for_dark_theme); @@ -662,8 +662,8 @@ void BackgroundManager::save_background_id(bool for_dark_theme) const { if (background_id.is_valid()) { const Background *background = get_background(background_id); CHECK(background != nullptr); - BackgroundLogEvent logevent{*background, set_background_type_[for_dark_theme]}; - G()->td_db()->get_binlog_pmc()->set(key, log_event_store(logevent).as_slice().str()); + BackgroundLogEvent log_event{*background, set_background_type_[for_dark_theme]}; + G()->td_db()->get_binlog_pmc()->set(key, log_event_store(log_event).as_slice().str()); } else { G()->td_db()->get_binlog_pmc()->erase(key); } diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1b2b8478c..e59640bf4 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7313,12 +7313,12 @@ void ContactsManager::save_user(User *u, UserId user_id, bool from_binlog) { CHECK(u != nullptr); if (!u->is_saved || !u->is_status_saved) { // TODO more effective handling of !u->is_status_saved if (!from_binlog) { - auto logevent = UserLogEvent(user_id, *u); - auto storer = get_log_event_storer(logevent); - if (u->logevent_id == 0) { - u->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Users, storer); + auto log_event = UserLogEvent(user_id, *u); + auto storer = get_log_event_storer(log_event); + if (u->log_event_id == 0) { + u->log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Users, storer); } else { - binlog_rewrite(G()->td_db()->get_binlog(), u->logevent_id, LogEvent::HandlerType::Users, storer); + binlog_rewrite(G()->td_db()->get_binlog(), u->log_event_id, LogEvent::HandlerType::Users, storer); } } @@ -7346,7 +7346,7 @@ void ContactsManager::on_binlog_user_event(BinlogEvent &&event) { User *u = add_user(user_id, "on_binlog_user_event"); *u = std::move(log_event.u); // users come from binlog before all other events, so just add them - u->logevent_id = event.id_; + u->log_event_id = event.id_; update_user(u, user_id, true, false); } @@ -7413,12 +7413,12 @@ void ContactsManager::on_save_user_to_database(UserId user_id, bool success) { LOG(INFO) << "Successfully saved " << user_id << " to database"; } if (u->is_saved && u->is_status_saved) { - if (u->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), u->logevent_id); - u->logevent_id = 0; + if (u->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), u->log_event_id); + u->log_event_id = 0; } } else { - save_user(u, user_id, u->logevent_id != 0); + save_user(u, user_id, u->log_event_id != 0); } } @@ -7496,9 +7496,9 @@ void ContactsManager::on_load_user_from_database(UserId user_id, string value) { auto new_value = get_user_database_value(u); if (value != new_value) { save_user_to_database_impl(u, user_id, std::move(new_value)); - } else if (u->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), u->logevent_id); - u->logevent_id = 0; + } else if (u->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), u->log_event_id); + u->log_event_id = 0; } } @@ -7589,12 +7589,12 @@ void ContactsManager::save_chat(Chat *c, ChatId chat_id, bool from_binlog) { CHECK(c != nullptr); if (!c->is_saved) { if (!from_binlog) { - auto logevent = ChatLogEvent(chat_id, *c); - auto storer = get_log_event_storer(logevent); - if (c->logevent_id == 0) { - c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Chats, storer); + auto log_event = ChatLogEvent(chat_id, *c); + auto storer = get_log_event_storer(log_event); + if (c->log_event_id == 0) { + c->log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Chats, storer); } else { - binlog_rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::Chats, storer); + binlog_rewrite(G()->td_db()->get_binlog(), c->log_event_id, LogEvent::HandlerType::Chats, storer); } } @@ -7623,7 +7623,7 @@ void ContactsManager::on_binlog_chat_event(BinlogEvent &&event) { Chat *c = add_chat(chat_id); *c = std::move(log_event.c); // chats come from binlog before all other events, so just add them - c->logevent_id = event.id_; + c->log_event_id = event.id_; update_chat(c, chat_id, true, false); } @@ -7682,12 +7682,12 @@ void ContactsManager::on_save_chat_to_database(ChatId chat_id, bool success) { LOG(INFO) << "Successfully saved " << chat_id << " to database"; } if (c->is_saved) { - if (c->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), c->logevent_id); - c->logevent_id = 0; + if (c->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), c->log_event_id); + c->log_event_id = 0; } } else { - save_chat(c, chat_id, c->logevent_id != 0); + save_chat(c, chat_id, c->log_event_id != 0); } } @@ -7751,9 +7751,9 @@ void ContactsManager::on_load_chat_from_database(ChatId chat_id, string value) { auto new_value = get_chat_database_value(c); if (value != new_value) { save_chat_to_database_impl(c, chat_id, std::move(new_value)); - } else if (c->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), c->logevent_id); - c->logevent_id = 0; + } else if (c->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), c->log_event_id); + c->log_event_id = 0; } } @@ -7825,12 +7825,12 @@ void ContactsManager::save_channel(Channel *c, ChannelId channel_id, bool from_b CHECK(c != nullptr); if (!c->is_saved) { if (!from_binlog) { - auto logevent = ChannelLogEvent(channel_id, *c); - auto storer = get_log_event_storer(logevent); - if (c->logevent_id == 0) { - c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Channels, storer); + auto log_event = ChannelLogEvent(channel_id, *c); + auto storer = get_log_event_storer(log_event); + if (c->log_event_id == 0) { + c->log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::Channels, storer); } else { - binlog_rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::Channels, storer); + binlog_rewrite(G()->td_db()->get_binlog(), c->log_event_id, LogEvent::HandlerType::Channels, storer); } } @@ -7859,7 +7859,7 @@ void ContactsManager::on_binlog_channel_event(BinlogEvent &&event) { Channel *c = add_channel(channel_id, "on_binlog_channel_event"); *c = std::move(log_event.c); // channels come from binlog before all other events, so just add them - c->logevent_id = event.id_; + c->log_event_id = event.id_; update_channel(c, channel_id, true, false); } @@ -7919,12 +7919,12 @@ void ContactsManager::on_save_channel_to_database(ChannelId channel_id, bool suc LOG(INFO) << "Successfully saved " << channel_id << " to database"; } if (c->is_saved) { - if (c->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), c->logevent_id); - c->logevent_id = 0; + if (c->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), c->log_event_id); + c->log_event_id = 0; } } else { - save_channel(c, channel_id, c->logevent_id != 0); + save_channel(c, channel_id, c->log_event_id != 0); } } @@ -8008,9 +8008,9 @@ void ContactsManager::on_load_channel_from_database(ChannelId channel_id, string auto new_value = get_channel_database_value(c); if (value != new_value) { save_channel_to_database_impl(c, channel_id, std::move(new_value)); - } else if (c->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), c->logevent_id); - c->logevent_id = 0; + } else if (c->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), c->log_event_id); + c->log_event_id = 0; } } @@ -8075,12 +8075,12 @@ void ContactsManager::save_secret_chat(SecretChat *c, SecretChatId secret_chat_i CHECK(c != nullptr); if (!c->is_saved) { if (!from_binlog) { - auto logevent = SecretChatLogEvent(secret_chat_id, *c); - auto storer = get_log_event_storer(logevent); - if (c->logevent_id == 0) { - c->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SecretChatInfos, storer); + auto log_event = SecretChatLogEvent(secret_chat_id, *c); + auto storer = get_log_event_storer(log_event); + if (c->log_event_id == 0) { + c->log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SecretChatInfos, storer); } else { - binlog_rewrite(G()->td_db()->get_binlog(), c->logevent_id, LogEvent::HandlerType::SecretChatInfos, storer); + binlog_rewrite(G()->td_db()->get_binlog(), c->log_event_id, LogEvent::HandlerType::SecretChatInfos, storer); } } @@ -8109,7 +8109,7 @@ void ContactsManager::on_binlog_secret_chat_event(BinlogEvent &&event) { SecretChat *c = add_secret_chat(secret_chat_id); *c = std::move(log_event.c); // secret chats come from binlog before all other events, so just add them - c->logevent_id = event.id_; + c->log_event_id = event.id_; update_secret_chat(c, secret_chat_id, true, false); } @@ -8170,12 +8170,12 @@ void ContactsManager::on_save_secret_chat_to_database(SecretChatId secret_chat_i LOG(INFO) << "Successfully saved " << secret_chat_id << " to database"; } if (c->is_saved) { - if (c->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), c->logevent_id); - c->logevent_id = 0; + if (c->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), c->log_event_id); + c->log_event_id = 0; } } else { - save_secret_chat(c, secret_chat_id, c->logevent_id != 0); + save_secret_chat(c, secret_chat_id, c->log_event_id != 0); } } @@ -8240,9 +8240,9 @@ void ContactsManager::on_load_secret_chat_from_database(SecretChatId secret_chat auto new_value = get_secret_chat_database_value(c); if (value != new_value) { save_secret_chat_to_database_impl(c, secret_chat_id, std::move(new_value)); - } else if (c->logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), c->logevent_id); - c->logevent_id = 0; + } else if (c->log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), c->log_event_id); + c->log_event_id = 0; } } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index d47082934..1f1930f90 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -630,7 +630,7 @@ class ContactsManager : public Actor { bool is_received_from_server = false; // true, if the user was received from the server and not the database - uint64 logevent_id = 0; + uint64 log_event_id = 0; template void store(StorerT &storer) const; @@ -722,7 +722,7 @@ class ContactsManager : public Actor { bool is_received_from_server = false; // true, if the chat was received from the server and not the database - uint64 logevent_id = 0; + uint64 log_event_id = 0; template void store(StorerT &storer) const; @@ -799,7 +799,7 @@ class ContactsManager : public Actor { bool is_received_from_server = false; // true, if the channel was received from the server and not the database - uint64 logevent_id = 0; + uint64 log_event_id = 0; template void store(StorerT &storer) const; @@ -882,7 +882,7 @@ class ContactsManager : public Actor { bool is_saved = false; // is current secret chat version being saved/is saved to the database bool is_being_saved = false; // is current secret chat being saved to the database - uint64 logevent_id = 0; + uint64 log_event_id = 0; template void store(StorerT &storer) const; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a3c7fc1fc..d82a2c29d 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5130,7 +5130,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) { int32 size; parse(size, parser); if (size < 0) { - // the logevent is broken + // the log event is broken // it should be impossible, but has happenned at least once parser.set_error("Wrong first_database_message_id_by_index table size"); return; @@ -5145,7 +5145,7 @@ void MessagesManager::Dialog::parse(ParserT &parser) { int32 size; parse(size, parser); if (size < 0) { - // the logevent is broken + // the log event is broken // it should be impossible, but has happenned at least once parser.set_error("Wrong message_count_by_index table size"); return; @@ -7738,20 +7738,20 @@ class MessagesManager::ChangeDialogReportSpamStateOnServerLogEvent { } }; -uint64 MessagesManager::save_change_dialog_report_spam_state_on_server_logevent(DialogId dialog_id, - bool is_spam_dialog) { - ChangeDialogReportSpamStateOnServerLogEvent logevent{dialog_id, is_spam_dialog}; +uint64 MessagesManager::save_change_dialog_report_spam_state_on_server_log_event(DialogId dialog_id, + bool is_spam_dialog) { + ChangeDialogReportSpamStateOnServerLogEvent log_event{dialog_id, is_spam_dialog}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ChangeDialogReportSpamStateOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::change_dialog_report_spam_state_on_server(DialogId dialog_id, bool is_spam_dialog, - uint64 logevent_id, Promise &&promise) { - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_change_dialog_report_spam_state_on_server_logevent(dialog_id, is_spam_dialog); + uint64 log_event_id, Promise &&promise) { + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_change_dialog_report_spam_state_on_server_log_event(dialog_id, is_spam_dialog); } - auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); + auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); promise = std::move(new_promise); // to prevent self-move switch (dialog_id.get_type()) { @@ -9717,26 +9717,26 @@ class MessagesManager::DeleteMessagesFromServerLogEvent { } }; -uint64 MessagesManager::save_delete_messages_from_server_logevent(DialogId dialog_id, - const vector &message_ids, bool revoke) { - DeleteMessagesFromServerLogEvent logevent{dialog_id, message_ids, revoke}; +uint64 MessagesManager::save_delete_messages_from_server_log_event(DialogId dialog_id, + const vector &message_ids, bool revoke) { + DeleteMessagesFromServerLogEvent log_event{dialog_id, message_ids, revoke}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessagesFromServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::delete_messages_from_server(DialogId dialog_id, vector message_ids, bool revoke, - uint64 logevent_id, Promise &&promise) { + uint64 log_event_id, Promise &&promise) { if (message_ids.empty()) { return promise.set_value(Unit()); } LOG(INFO) << (revoke ? "Revoke " : "Delete ") << format::as_array(message_ids) << " in " << dialog_id << " from server"; - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_delete_messages_from_server_logevent(dialog_id, message_ids, revoke); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_delete_messages_from_server_log_event(dialog_id, message_ids, revoke); } - auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); + auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); promise = std::move(new_promise); // to prevent self-move switch (dialog_id.get_type()) { @@ -9790,25 +9790,25 @@ class MessagesManager::DeleteScheduledMessagesFromServerLogEvent { } }; -uint64 MessagesManager::save_delete_scheduled_messages_from_server_logevent(DialogId dialog_id, - const vector &message_ids) { - DeleteScheduledMessagesFromServerLogEvent logevent{dialog_id, message_ids}; +uint64 MessagesManager::save_delete_scheduled_messages_from_server_log_event(DialogId dialog_id, + const vector &message_ids) { + DeleteScheduledMessagesFromServerLogEvent log_event{dialog_id, message_ids}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteScheduledMessagesFromServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::delete_scheduled_messages_from_server(DialogId dialog_id, vector message_ids, - uint64 logevent_id, Promise &&promise) { + uint64 log_event_id, Promise &&promise) { if (message_ids.empty()) { return promise.set_value(Unit()); } LOG(INFO) << "Delete " << format::as_array(message_ids) << " in " << dialog_id << " from server"; - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_delete_scheduled_messages_from_server_logevent(dialog_id, message_ids); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_delete_scheduled_messages_from_server_log_event(dialog_id, message_ids); } - auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); + auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); promise = std::move(new_promise); // to prevent self-move td_->create_handler(std::move(promise))->send(dialog_id, std::move(message_ids)); @@ -9920,24 +9920,24 @@ class MessagesManager::DeleteDialogHistoryFromServerLogEvent { } }; -uint64 MessagesManager::save_delete_dialog_history_from_server_logevent(DialogId dialog_id, MessageId max_message_id, - bool remove_from_dialog_list, bool revoke) { - DeleteDialogHistoryFromServerLogEvent logevent{dialog_id, max_message_id, remove_from_dialog_list, revoke}; +uint64 MessagesManager::save_delete_dialog_history_from_server_log_event(DialogId dialog_id, MessageId max_message_id, + bool remove_from_dialog_list, bool revoke) { + DeleteDialogHistoryFromServerLogEvent log_event{dialog_id, max_message_id, remove_from_dialog_list, revoke}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteDialogHistoryFromServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::delete_dialog_history_from_server(DialogId dialog_id, MessageId max_message_id, bool remove_from_dialog_list, bool revoke, bool allow_error, - uint64 logevent_id, Promise &&promise) { + uint64 log_event_id, Promise &&promise) { LOG(INFO) << "Delete history in " << dialog_id << " up to " << max_message_id << " from server"; - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = - save_delete_dialog_history_from_server_logevent(dialog_id, max_message_id, remove_from_dialog_list, revoke); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = + save_delete_dialog_history_from_server_log_event(dialog_id, max_message_id, remove_from_dialog_list, revoke); } - auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); + auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); promise = std::move(new_promise); // to prevent self-move switch (dialog_id.get_type()) { @@ -10150,20 +10150,20 @@ class MessagesManager::DeleteAllChannelMessagesFromUserOnServerLogEvent { } }; -uint64 MessagesManager::save_delete_all_channel_messages_from_user_on_server_logevent(ChannelId channel_id, - UserId user_id) { - DeleteAllChannelMessagesFromUserOnServerLogEvent logevent{channel_id, user_id}; +uint64 MessagesManager::save_delete_all_channel_messages_from_user_on_server_log_event(ChannelId channel_id, + UserId user_id) { + DeleteAllChannelMessagesFromUserOnServerLogEvent log_event{channel_id, user_id}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteAllChannelMessagesFromUserOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::delete_all_channel_messages_from_user_on_server(ChannelId channel_id, UserId user_id, - uint64 logevent_id, Promise &&promise) { - if (logevent_id == 0 && G()->parameters().use_chat_info_db) { - logevent_id = save_delete_all_channel_messages_from_user_on_server_logevent(channel_id, user_id); + uint64 log_event_id, Promise &&promise) { + if (log_event_id == 0 && G()->parameters().use_chat_info_db) { + log_event_id = save_delete_all_channel_messages_from_user_on_server_log_event(channel_id, user_id); } - td_->create_handler(get_erase_logevent_promise(logevent_id, std::move(promise))) + td_->create_handler(get_erase_log_event_promise(log_event_id, std::move(promise))) ->send(channel_id, user_id); } @@ -10382,20 +10382,20 @@ class MessagesManager::ReadAllDialogMentionsOnServerLogEvent { } }; -uint64 MessagesManager::save_read_all_dialog_mentions_on_server_logevent(DialogId dialog_id) { - ReadAllDialogMentionsOnServerLogEvent logevent{dialog_id}; +uint64 MessagesManager::save_read_all_dialog_mentions_on_server_log_event(DialogId dialog_id) { + ReadAllDialogMentionsOnServerLogEvent log_event{dialog_id}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadAllDialogMentionsOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } -void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uint64 logevent_id, +void MessagesManager::read_all_dialog_mentions_on_server(DialogId dialog_id, uint64 log_event_id, Promise &&promise) { - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_read_all_dialog_mentions_on_server_logevent(dialog_id); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_read_all_dialog_mentions_on_server_log_event(dialog_id); } LOG(INFO) << "Read all mentions on server in " << dialog_id; - td_->create_handler(get_erase_logevent_promise(logevent_id, std::move(promise))) + td_->create_handler(get_erase_log_event_promise(log_event_id, std::move(promise))) ->send(dialog_id); } @@ -11244,7 +11244,7 @@ void MessagesManager::ttl_read_history(Dialog *d, bool is_outgoing, MessageId fr CHECK(!from_message_id.is_scheduled()); CHECK(!till_message_id.is_scheduled()); - // TODO: protect with logevent + // TODO: protect with log event suffix_load_till_message_id(d, till_message_id, PromiseCreator::lambda([actor_id = actor_id(this), dialog_id = d->dialog_id, is_outgoing, from_message_id, till_message_id, view_date](Result) { @@ -12102,7 +12102,7 @@ void MessagesManager::read_secret_chat_outbox(SecretChatId secret_chat_id, int32 } } - // TODO: protect with logevent + // TODO: protect with log event suffix_load_till_date( d, up_to_date, PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, up_to_date, read_date](Result result) { @@ -12528,7 +12528,7 @@ std::pair> MessagesManager::creat is_outgoing = supposed_to_be_outgoing; if (dialog_type == DialogType::Channel && !running_get_difference_ && !running_get_channel_difference(dialog_id) && - get_channel_difference_to_logevent_id_.count(dialog_id) == 0) { + get_channel_difference_to_log_event_id_.count(dialog_id) == 0) { // it is safer to completely ignore the message and re-get it through getChannelsDifference Dialog *d = get_dialog(dialog_id); if (d != nullptr) { @@ -17291,9 +17291,9 @@ Status MessagesManager::set_dialog_draft_message(DialogId dialog_id, if (update_dialog_draft_message(d, std::move(new_draft_message), false, true)) { if (dialog_id.get_type() != DialogType::SecretChat) { if (G()->parameters().use_message_db) { - SaveDialogDraftMessageOnServerLogEvent logevent; - logevent.dialog_id_ = dialog_id; - add_log_event(d->save_draft_message_logevent_id, get_log_event_storer(logevent), + SaveDialogDraftMessageOnServerLogEvent log_event; + log_event.dialog_id_ = dialog_id; + add_log_event(d->save_draft_message_log_event_id, get_log_event_storer(log_event), LogEvent::HandlerType::SaveDialogDraftMessageOnServer, "draft"); } @@ -17312,10 +17312,10 @@ void MessagesManager::save_dialog_draft_message_on_server(DialogId dialog_id) { CHECK(d != nullptr); Promise<> promise; - if (d->save_draft_message_logevent_id.logevent_id != 0) { - d->save_draft_message_logevent_id.generation++; + if (d->save_draft_message_log_event_id.log_event_id != 0) { + d->save_draft_message_log_event_id.generation++; promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, - generation = d->save_draft_message_logevent_id.generation](Result result) { + generation = d->save_draft_message_log_event_id.generation](Result result) { if (!G()->close_flag()) { send_closure(actor_id, &MessagesManager::on_saved_dialog_draft_message, dialog_id, generation); } @@ -17329,7 +17329,7 @@ void MessagesManager::save_dialog_draft_message_on_server(DialogId dialog_id) { void MessagesManager::on_saved_dialog_draft_message(DialogId dialog_id, uint64 generation) { auto d = get_dialog(dialog_id); CHECK(d != nullptr); - delete_log_event(d->save_draft_message_logevent_id, generation, "draft"); + delete_log_event(d->save_draft_message_log_event_id, generation, "draft"); } void MessagesManager::clear_all_draft_messages(bool exclude_secret_chats, Promise &&promise) { @@ -17480,24 +17480,24 @@ class MessagesManager::ToggleDialogIsPinnedOnServerLogEvent { } }; -uint64 MessagesManager::save_toggle_dialog_is_pinned_on_server_logevent(DialogId dialog_id, bool is_pinned) { - ToggleDialogIsPinnedOnServerLogEvent logevent{dialog_id, is_pinned}; +uint64 MessagesManager::save_toggle_dialog_is_pinned_on_server_log_event(DialogId dialog_id, bool is_pinned) { + ToggleDialogIsPinnedOnServerLogEvent log_event{dialog_id, is_pinned}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsPinnedOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } -void MessagesManager::toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 logevent_id) { +void MessagesManager::toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 log_event_id) { CHECK(!td_->auth_manager_->is_bot()); - if (logevent_id == 0 && dialog_id.get_type() == DialogType::SecretChat) { + if (log_event_id == 0 && dialog_id.get_type() == DialogType::SecretChat) { // don't even create new binlog events return; } - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_toggle_dialog_is_pinned_on_server_logevent(dialog_id, is_pinned); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_toggle_dialog_is_pinned_on_server_log_event(dialog_id, is_pinned); } - td_->create_handler(get_erase_logevent_promise(logevent_id))->send(dialog_id, is_pinned); + td_->create_handler(get_erase_log_event_promise(log_event_id))->send(dialog_id, is_pinned); } Status MessagesManager::set_pinned_dialogs(DialogListId dialog_list_id, vector dialog_ids) { @@ -17639,20 +17639,21 @@ class MessagesManager::ReorderPinnedDialogsOnServerLogEvent { } }; -uint64 MessagesManager::save_reorder_pinned_dialogs_on_server_logevent(FolderId folder_id, - const vector &dialog_ids) { - ReorderPinnedDialogsOnServerLogEvent logevent{folder_id, dialog_ids}; +uint64 MessagesManager::save_reorder_pinned_dialogs_on_server_log_event(FolderId folder_id, + const vector &dialog_ids) { + ReorderPinnedDialogsOnServerLogEvent log_event{folder_id, dialog_ids}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReorderPinnedDialogsOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::reorder_pinned_dialogs_on_server(FolderId folder_id, const vector &dialog_ids, - uint64 logevent_id) { - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_reorder_pinned_dialogs_on_server_logevent(folder_id, dialog_ids); + uint64 log_event_id) { + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_reorder_pinned_dialogs_on_server_log_event(folder_id, dialog_ids); } - td_->create_handler(get_erase_logevent_promise(logevent_id))->send(folder_id, dialog_ids); + td_->create_handler(get_erase_log_event_promise(log_event_id)) + ->send(folder_id, dialog_ids); } Status MessagesManager::toggle_dialog_is_marked_as_unread(DialogId dialog_id, bool is_marked_as_unread) { @@ -17698,25 +17699,25 @@ class MessagesManager::ToggleDialogIsMarkedAsUnreadOnServerLogEvent { } }; -uint64 MessagesManager::save_toggle_dialog_is_marked_as_unread_on_server_logevent(DialogId dialog_id, - bool is_marked_as_unread) { - ToggleDialogIsMarkedAsUnreadOnServerLogEvent logevent{dialog_id, is_marked_as_unread}; +uint64 MessagesManager::save_toggle_dialog_is_marked_as_unread_on_server_log_event(DialogId dialog_id, + bool is_marked_as_unread) { + ToggleDialogIsMarkedAsUnreadOnServerLogEvent log_event{dialog_id, is_marked_as_unread}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsMarkedAsUnreadOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::toggle_dialog_is_marked_as_unread_on_server(DialogId dialog_id, bool is_marked_as_unread, - uint64 logevent_id) { - if (logevent_id == 0 && dialog_id.get_type() == DialogType::SecretChat) { + uint64 log_event_id) { + if (log_event_id == 0 && dialog_id.get_type() == DialogType::SecretChat) { // don't even create new binlog events return; } - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_toggle_dialog_is_marked_as_unread_on_server_logevent(dialog_id, is_marked_as_unread); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_toggle_dialog_is_marked_as_unread_on_server_log_event(dialog_id, is_marked_as_unread); } - td_->create_handler(get_erase_logevent_promise(logevent_id)) + td_->create_handler(get_erase_log_event_promise(log_event_id)) ->send(dialog_id, is_marked_as_unread); } @@ -17770,23 +17771,24 @@ class MessagesManager::ToggleDialogIsBlockedOnServerLogEvent { } }; -uint64 MessagesManager::save_toggle_dialog_is_blocked_on_server_logevent(DialogId dialog_id, bool is_blocked) { - ToggleDialogIsBlockedOnServerLogEvent logevent{dialog_id, is_blocked}; +uint64 MessagesManager::save_toggle_dialog_is_blocked_on_server_log_event(DialogId dialog_id, bool is_blocked) { + ToggleDialogIsBlockedOnServerLogEvent log_event{dialog_id, is_blocked}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ToggleDialogIsBlockedOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } -void MessagesManager::toggle_dialog_is_blocked_on_server(DialogId dialog_id, bool is_blocked, uint64 logevent_id) { - if (logevent_id == 0 && dialog_id.get_type() == DialogType::SecretChat) { +void MessagesManager::toggle_dialog_is_blocked_on_server(DialogId dialog_id, bool is_blocked, uint64 log_event_id) { + if (log_event_id == 0 && dialog_id.get_type() == DialogType::SecretChat) { // don't even create new binlog events return; } - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_toggle_dialog_is_blocked_on_server_logevent(dialog_id, is_blocked); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_toggle_dialog_is_blocked_on_server_log_event(dialog_id, is_blocked); } - td_->create_handler(get_erase_logevent_promise(logevent_id))->send(dialog_id, is_blocked); + td_->create_handler(get_erase_log_event_promise(log_event_id)) + ->send(dialog_id, is_blocked); } Status MessagesManager::toggle_dialog_silent_send_message(DialogId dialog_id, bool silent_send_message) { @@ -17837,18 +17839,18 @@ void MessagesManager::update_dialog_notification_settings_on_server(DialogId dia CHECK(d != nullptr); if (!from_binlog && G()->parameters().use_message_db) { - UpdateDialogNotificationSettingsOnServerLogEvent logevent; - logevent.dialog_id_ = dialog_id; - add_log_event(d->save_notification_settings_logevent_id, get_log_event_storer(logevent), + UpdateDialogNotificationSettingsOnServerLogEvent log_event; + log_event.dialog_id_ = dialog_id; + add_log_event(d->save_notification_settings_log_event_id, get_log_event_storer(log_event), LogEvent::HandlerType::UpdateDialogNotificationSettingsOnServer, "notification settings"); } Promise<> promise; - if (d->save_notification_settings_logevent_id.logevent_id != 0) { - d->save_notification_settings_logevent_id.generation++; + if (d->save_notification_settings_log_event_id.log_event_id != 0) { + d->save_notification_settings_log_event_id.generation++; promise = PromiseCreator::lambda( [actor_id = actor_id(this), dialog_id, - generation = d->save_notification_settings_logevent_id.generation](Result result) { + generation = d->save_notification_settings_log_event_id.generation](Result result) { if (!G()->close_flag()) { send_closure(actor_id, &MessagesManager::on_updated_dialog_notification_settings, dialog_id, generation); } @@ -17870,7 +17872,7 @@ void MessagesManager::on_updated_dialog_notification_settings(DialogId dialog_id CHECK(!td_->auth_manager_->is_bot()); auto d = get_dialog(dialog_id); CHECK(d != nullptr); - delete_log_event(d->save_notification_settings_logevent_id, generation, "notification settings"); + delete_log_event(d->save_notification_settings_log_event_id, generation, "notification settings"); } Status MessagesManager::set_dialog_client_data(DialogId dialog_id, string &&client_data) { @@ -18301,24 +18303,25 @@ class MessagesManager::ReadMessageContentsOnServerLogEvent { } }; -uint64 MessagesManager::save_read_message_contents_on_server_logevent(DialogId dialog_id, - const vector &message_ids) { - ReadMessageContentsOnServerLogEvent logevent{dialog_id, message_ids}; +uint64 MessagesManager::save_read_message_contents_on_server_log_event(DialogId dialog_id, + const vector &message_ids) { + ReadMessageContentsOnServerLogEvent log_event{dialog_id, message_ids}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ReadMessageContentsOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::read_message_contents_on_server(DialogId dialog_id, vector message_ids, - uint64 logevent_id, Promise &&promise, bool skip_logevent) { + uint64 log_event_id, Promise &&promise, + bool skip_log_event) { CHECK(!message_ids.empty()); LOG(INFO) << "Read contents of " << format::as_array(message_ids) << " in " << dialog_id << " on server"; - if (logevent_id == 0 && G()->parameters().use_message_db && !skip_logevent) { - logevent_id = save_read_message_contents_on_server_logevent(dialog_id, message_ids); + if (log_event_id == 0 && G()->parameters().use_message_db && !skip_log_event) { + log_event_id = save_read_message_contents_on_server_log_event(dialog_id, message_ids); } - auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); + auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); promise = std::move(new_promise); // to prevent self-move switch (dialog_id.get_type()) { @@ -18930,21 +18933,21 @@ class MessagesManager::UpdateScopeNotificationSettingsOnServerLogEvent { } }; -uint64 MessagesManager::save_update_scope_notification_settings_on_server_logevent(NotificationSettingsScope scope) { - UpdateScopeNotificationSettingsOnServerLogEvent logevent{scope}; +uint64 MessagesManager::save_update_scope_notification_settings_on_server_log_event(NotificationSettingsScope scope) { + UpdateScopeNotificationSettingsOnServerLogEvent log_event{scope}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::UpdateScopeNotificationSettingsOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::update_scope_notification_settings_on_server(NotificationSettingsScope scope, - uint64 logevent_id) { + uint64 log_event_id) { CHECK(!td_->auth_manager_->is_bot()); - if (logevent_id == 0) { - logevent_id = save_update_scope_notification_settings_on_server_logevent(scope); + if (log_event_id == 0) { + log_event_id = save_update_scope_notification_settings_on_server_log_event(scope); } - LOG(INFO) << "Update " << scope << " notification settings on server with logevent " << logevent_id; - td_->create_handler(get_erase_logevent_promise(logevent_id)) + LOG(INFO) << "Update " << scope << " notification settings on server with log_event " << log_event_id; + td_->create_handler(get_erase_log_event_promise(log_event_id)) ->send(scope, *get_scope_notification_settings(scope)); } @@ -18980,20 +18983,20 @@ class MessagesManager::ResetAllNotificationSettingsOnServerLogEvent { } }; -uint64 MessagesManager::save_reset_all_notification_settings_on_server_logevent() { - ResetAllNotificationSettingsOnServerLogEvent logevent; +uint64 MessagesManager::save_reset_all_notification_settings_on_server_log_event() { + ResetAllNotificationSettingsOnServerLogEvent log_event; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ResetAllNotificationSettingsOnServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } -void MessagesManager::reset_all_notification_settings_on_server(uint64 logevent_id) { +void MessagesManager::reset_all_notification_settings_on_server(uint64 log_event_id) { CHECK(!td_->auth_manager_->is_bot()); - if (logevent_id == 0) { - logevent_id = save_reset_all_notification_settings_on_server_logevent(); + if (log_event_id == 0) { + log_event_id = save_reset_all_notification_settings_on_server_log_event(); } LOG(INFO) << "Reset all notification settings"; - td_->create_handler(get_erase_logevent_promise(logevent_id))->send(); + td_->create_handler(get_erase_log_event_promise(log_event_id))->send(); } tl_object_ptr MessagesManager::get_dialog_history(DialogId dialog_id, MessageId from_message_id, @@ -19230,18 +19233,18 @@ void MessagesManager::read_history_on_server(Dialog *d, MessageId max_message_id return; } - ReadHistoryInSecretChatLogEvent logevent; - logevent.dialog_id_ = dialog_id; - logevent.max_date_ = m->date; - add_log_event(d->read_history_logevent_ids[0], get_log_event_storer(logevent), + ReadHistoryInSecretChatLogEvent log_event; + log_event.dialog_id_ = dialog_id; + log_event.max_date_ = m->date; + add_log_event(d->read_history_log_event_ids[0], get_log_event_storer(log_event), LogEvent::HandlerType::ReadHistoryInSecretChat, "read history"); d->last_read_inbox_message_date = m->date; } else if (G()->parameters().use_message_db) { - ReadHistoryOnServerLogEvent logevent; - logevent.dialog_id_ = dialog_id; - logevent.max_message_id_ = max_message_id; - add_log_event(d->read_history_logevent_ids[0], get_log_event_storer(logevent), + ReadHistoryOnServerLogEvent log_event; + log_event.dialog_id_ = dialog_id; + log_event.max_message_id_ = max_message_id; + add_log_event(d->read_history_log_event_ids[0], get_log_event_storer(log_event), LogEvent::HandlerType::ReadHistoryOnServer, "read history"); } @@ -19267,11 +19270,11 @@ void MessagesManager::read_message_thread_history_on_server(Dialog *d, MessageId << max_message_id; if (G()->parameters().use_message_db) { - ReadMessageThreadHistoryOnServerLogEvent logevent; - logevent.dialog_id_ = dialog_id; - logevent.top_thread_message_id_ = top_thread_message_id; - logevent.max_message_id_ = max_message_id; - add_log_event(d->read_history_logevent_ids[top_thread_message_id.get()], get_log_event_storer(logevent), + ReadMessageThreadHistoryOnServerLogEvent log_event; + log_event.dialog_id_ = dialog_id; + log_event.top_thread_message_id_ = top_thread_message_id; + log_event.max_message_id_ = max_message_id; + add_log_event(d->read_history_log_event_ids[top_thread_message_id.get()], get_log_event_storer(log_event), LogEvent::HandlerType::ReadMessageThreadHistoryOnServer, "read history"); } @@ -19315,10 +19318,10 @@ void MessagesManager::read_history_on_server_impl(Dialog *d, MessageId max_messa } Promise<> promise; - if (d->read_history_logevent_ids[0].logevent_id != 0) { - d->read_history_logevent_ids[0].generation++; + if (d->read_history_log_event_ids[0].log_event_id != 0) { + d->read_history_log_event_ids[0].generation++; promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, - generation = d->read_history_logevent_ids[0].generation](Result result) { + generation = d->read_history_log_event_ids[0].generation](Result result) { if (!G()->close_flag()) { send_closure(actor_id, &MessagesManager::on_read_history_finished, dialog_id, MessageId(), generation); } @@ -19379,11 +19382,11 @@ void MessagesManager::read_message_thread_history_on_server_impl(Dialog *d, Mess } Promise<> promise; - if (d->read_history_logevent_ids[top_thread_message_id.get()].logevent_id != 0) { - d->read_history_logevent_ids[top_thread_message_id.get()].generation++; + if (d->read_history_log_event_ids[top_thread_message_id.get()].log_event_id != 0) { + d->read_history_log_event_ids[top_thread_message_id.get()].generation++; promise = PromiseCreator::lambda( [actor_id = actor_id(this), dialog_id, top_thread_message_id, - generation = d->read_history_logevent_ids[top_thread_message_id.get()].generation](Result result) { + generation = d->read_history_log_event_ids[top_thread_message_id.get()].generation](Result result) { if (!G()->close_flag()) { send_closure(actor_id, &MessagesManager::on_read_history_finished, dialog_id, top_thread_message_id, generation); @@ -19403,13 +19406,13 @@ void MessagesManager::read_message_thread_history_on_server_impl(Dialog *d, Mess void MessagesManager::on_read_history_finished(DialogId dialog_id, MessageId top_thread_message_id, uint64 generation) { auto d = get_dialog(dialog_id); CHECK(d != nullptr); - auto it = d->read_history_logevent_ids.find(top_thread_message_id.get()); - if (it == d->read_history_logevent_ids.end()) { + auto it = d->read_history_log_event_ids.find(top_thread_message_id.get()); + if (it == d->read_history_log_event_ids.end()) { return; } delete_log_event(it->second, generation, "read history"); - if (it->second.logevent_id == 0) { - d->read_history_logevent_ids.erase(it); + if (it->second.log_event_id == 0) { + d->read_history_log_event_ids.erase(it); } } @@ -21775,10 +21778,10 @@ void MessagesManager::cancel_send_message_query(DialogId dialog_id, Message *m) m->send_query_ref = NetQueryRef(); } - if (m->send_message_logevent_id != 0) { + if (m->send_message_log_event_id != 0) { LOG(INFO) << "Delete send message log event for " << m->message_id; - binlog_erase(G()->td_db()->get_binlog(), m->send_message_logevent_id); - m->send_message_logevent_id = 0; + binlog_erase(G()->td_db()->get_binlog(), m->send_message_log_event_id); + m->send_message_log_event_id = 0; } if (m->reply_to_message_id.is_valid() && !m->reply_to_message_id.is_yet_unsent()) { @@ -21946,7 +21949,7 @@ Result MessagesManager::send_message(DialogId dialog_id, MessageId re update_dialog_draft_message(d, nullptr, false, !need_update_dialog_pos); } - save_send_message_logevent(dialog_id, m); + save_send_message_log_event(dialog_id, m); do_send_message(dialog_id, m); send_update_new_message(d, m); @@ -22143,7 +22146,7 @@ Result> MessagesManager::send_message_group( } m->media_album_id = media_album_id; - save_send_message_logevent(dialog_id, m); + save_send_message_log_event(dialog_id, m); do_send_message(dialog_id, m); send_update_new_message(d, m); @@ -22156,17 +22159,17 @@ Result> MessagesManager::send_message_group( return result; } -void MessagesManager::save_send_message_logevent(DialogId dialog_id, const Message *m) { +void MessagesManager::save_send_message_log_event(DialogId dialog_id, const Message *m) { if (!G()->parameters().use_message_db) { return; } CHECK(m != nullptr); LOG(INFO) << "Save " << FullMessageId(dialog_id, m->message_id) << " to binlog"; - auto logevent = SendMessageLogEvent(dialog_id, m); - CHECK(m->send_message_logevent_id == 0); - m->send_message_logevent_id = - binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendMessage, get_log_event_storer(logevent)); + auto log_event = SendMessageLogEvent(dialog_id, m); + CHECK(m->send_message_log_event_id == 0); + m->send_message_log_event_id = + binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendMessage, get_log_event_storer(log_event)); } void MessagesManager::do_send_message(DialogId dialog_id, const Message *m, vector bad_parts) { @@ -22793,10 +22796,10 @@ Result MessagesManager::send_bot_start_message(UserId bot_user_id, Di } if (parameter.empty() && is_chat_with_bot) { - save_send_message_logevent(dialog_id, m); + save_send_message_log_event(dialog_id, m); do_send_message(dialog_id, m); } else { - save_send_bot_start_message_logevent(bot_user_id, dialog_id, parameter, m); + save_send_bot_start_message_log_event(bot_user_id, dialog_id, parameter, m); do_send_bot_start_message(bot_user_id, dialog_id, parameter, m); } return m->message_id; @@ -22827,22 +22830,22 @@ class MessagesManager::SendBotStartMessageLogEvent { } }; -void MessagesManager::save_send_bot_start_message_logevent(UserId bot_user_id, DialogId dialog_id, - const string ¶meter, const Message *m) { +void MessagesManager::save_send_bot_start_message_log_event(UserId bot_user_id, DialogId dialog_id, + const string ¶meter, const Message *m) { if (!G()->parameters().use_message_db) { return; } CHECK(m != nullptr); LOG(INFO) << "Save " << FullMessageId(dialog_id, m->message_id) << " to binlog"; - SendBotStartMessageLogEvent logevent; - logevent.bot_user_id = bot_user_id; - logevent.dialog_id = dialog_id; - logevent.parameter = parameter; - logevent.m_in = m; - CHECK(m->send_message_logevent_id == 0); - m->send_message_logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendBotStartMessage, - get_log_event_storer(logevent)); + SendBotStartMessageLogEvent log_event; + log_event.bot_user_id = bot_user_id; + log_event.dialog_id = dialog_id; + log_event.parameter = parameter; + log_event.m_in = m; + CHECK(m->send_message_log_event_id == 0); + m->send_message_log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendBotStartMessage, + get_log_event_storer(log_event)); } void MessagesManager::do_send_bot_start_message(UserId bot_user_id, DialogId dialog_id, const string ¶meter, @@ -22931,12 +22934,12 @@ Result MessagesManager::send_inline_query_result_message(DialogId dia } if (to_secret) { - save_send_message_logevent(dialog_id, m); + save_send_message_log_event(dialog_id, m); do_send_message(dialog_id, m); return m->message_id; } - save_send_inline_query_result_message_logevent(dialog_id, m, query_id, result_id); + save_send_inline_query_result_message_log_event(dialog_id, m, query_id, result_id); do_send_inline_query_result_message(dialog_id, m, query_id, result_id); return m->message_id; } @@ -22966,22 +22969,22 @@ class MessagesManager::SendInlineQueryResultMessageLogEvent { } }; -void MessagesManager::save_send_inline_query_result_message_logevent(DialogId dialog_id, const Message *m, - int64 query_id, const string &result_id) { +void MessagesManager::save_send_inline_query_result_message_log_event(DialogId dialog_id, const Message *m, + int64 query_id, const string &result_id) { if (!G()->parameters().use_message_db) { return; } CHECK(m != nullptr); LOG(INFO) << "Save " << FullMessageId(dialog_id, m->message_id) << " to binlog"; - SendInlineQueryResultMessageLogEvent logevent; - logevent.dialog_id = dialog_id; - logevent.query_id = query_id; - logevent.result_id = result_id; - logevent.m_in = m; - CHECK(m->send_message_logevent_id == 0); - m->send_message_logevent_id = binlog_add( - G()->td_db()->get_binlog(), LogEvent::HandlerType::SendInlineQueryResultMessage, get_log_event_storer(logevent)); + SendInlineQueryResultMessageLogEvent log_event; + log_event.dialog_id = dialog_id; + log_event.query_id = query_id; + log_event.result_id = result_id; + log_event.m_in = m; + CHECK(m->send_message_log_event_id == 0); + m->send_message_log_event_id = binlog_add( + G()->td_db()->get_binlog(), LogEvent::HandlerType::SendInlineQueryResultMessage, get_log_event_storer(log_event)); } void MessagesManager::do_send_inline_query_result_message(DialogId dialog_id, const Message *m, int64 query_id, @@ -24307,23 +24310,24 @@ class MessagesManager::ForwardMessagesLogEvent { } }; -uint64 MessagesManager::save_forward_messages_logevent(DialogId to_dialog_id, DialogId from_dialog_id, - const vector &messages, - const vector &message_ids) { - ForwardMessagesLogEvent logevent{to_dialog_id, from_dialog_id, message_ids, messages, Auto()}; - return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ForwardMessages, get_log_event_storer(logevent)); +uint64 MessagesManager::save_forward_messages_log_event(DialogId to_dialog_id, DialogId from_dialog_id, + const vector &messages, + const vector &message_ids) { + ForwardMessagesLogEvent log_event{to_dialog_id, from_dialog_id, message_ids, messages, Auto()}; + return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::ForwardMessages, + get_log_event_storer(log_event)); } void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_dialog_id, const vector &messages, const vector &message_ids, - uint64 logevent_id) { + uint64 log_event_id) { CHECK(messages.size() == message_ids.size()); if (messages.empty()) { return; } - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_forward_messages_logevent(to_dialog_id, from_dialog_id, messages, message_ids); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_forward_messages_log_event(to_dialog_id, from_dialog_id, messages, message_ids); } auto schedule_date = get_message_schedule_date(messages[0]); @@ -24344,7 +24348,7 @@ void MessagesManager::do_forward_messages(DialogId to_dialog_id, DialogId from_d vector random_ids = transform(messages, [this, to_dialog_id](const Message *m) { return begin_send_message(to_dialog_id, m); }); - send_closure(td_->create_net_actor(get_erase_logevent_promise(logevent_id)), + send_closure(td_->create_net_actor(get_erase_log_event_promise(log_event_id)), &ForwardMessagesActor::send, flags, to_dialog_id, from_dialog_id, message_ids, std::move(random_ids), schedule_date, get_sequence_dispatcher_id(to_dialog_id, MessageContentType::None)); } @@ -24617,7 +24621,7 @@ Result> MessagesManager::forward_messages(DialogId to_dialog_i } m->reply_markup = std::move(copied_message.reply_markup); - save_send_message_logevent(to_dialog_id, m); + save_send_message_log_event(to_dialog_id, m); do_send_message(to_dialog_id, m); result[copied_message.index] = m->message_id; @@ -24731,7 +24735,7 @@ Result> MessagesManager::resend_messages(DialogId dialog_id, v m->is_content_secret = message->is_content_secret; m->media_album_id = new_media_album_ids[message->media_album_id].first; - save_send_message_logevent(dialog_id, m); + save_send_message_log_event(dialog_id, m); do_send_message(dialog_id, m); send_update_new_message(d, m); @@ -24835,31 +24839,32 @@ class MessagesManager::SendScreenshotTakenNotificationMessageLogEvent { } }; -uint64 MessagesManager::save_send_screenshot_taken_notification_message_logevent(DialogId dialog_id, const Message *m) { +uint64 MessagesManager::save_send_screenshot_taken_notification_message_log_event(DialogId dialog_id, + const Message *m) { if (!G()->parameters().use_message_db) { return 0; } CHECK(m != nullptr); LOG(INFO) << "Save " << FullMessageId(dialog_id, m->message_id) << " to binlog"; - SendScreenshotTakenNotificationMessageLogEvent logevent; - logevent.dialog_id = dialog_id; - logevent.m_in = m; + SendScreenshotTakenNotificationMessageLogEvent log_event; + log_event.dialog_id = dialog_id; + log_event.m_in = m; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SendScreenshotTakenNotificationMessage, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dialog_id, const Message *m, - uint64 logevent_id) { + uint64 log_event_id) { LOG(INFO) << "Do send screenshot taken notification " << FullMessageId(dialog_id, m->message_id); CHECK(dialog_id.get_type() == DialogType::User); - if (logevent_id == 0) { - logevent_id = save_send_screenshot_taken_notification_message_logevent(dialog_id, m); + if (log_event_id == 0) { + log_event_id = save_send_screenshot_taken_notification_message_log_event(dialog_id, m); } int64 random_id = begin_send_message(dialog_id, m); - td_->create_handler(get_erase_logevent_promise(logevent_id)) + td_->create_handler(get_erase_log_event_promise(log_event_id)) ->send(dialog_id, random_id); } @@ -25098,7 +25103,7 @@ NotificationGroupId MessagesManager::get_dialog_notification_group_id(DialogId d notification_group_id_to_dialog_id_.emplace(next_notification_group_id, dialog_id); - if (running_get_channel_difference(dialog_id) || get_channel_difference_to_logevent_id_.count(dialog_id) != 0) { + if (running_get_channel_difference(dialog_id) || get_channel_difference_to_log_event_id_.count(dialog_id) != 0) { send_closure_later(G()->notification_manager(), &NotificationManager::before_get_chat_difference, next_notification_group_id); } @@ -26551,7 +26556,7 @@ void MessagesManager::send_update_chat_read_inbox(const Dialog *d, bool force, c << source; on_dialog_updated(d->dialog_id, source); if (!force && (running_get_difference_ || running_get_channel_difference(d->dialog_id) || - get_channel_difference_to_logevent_id_.count(d->dialog_id) != 0)) { + get_channel_difference_to_log_event_id_.count(d->dialog_id) != 0)) { LOG(INFO) << "Postpone updateChatReadInbox in " << d->dialog_id << "(" << get_dialog_title(d->dialog_id) << ") to " << d->server_unread_count << " + " << d->local_unread_count << " from " << source; postponed_chat_read_inbox_updates_.insert(d->dialog_id); @@ -26872,10 +26877,10 @@ void MessagesManager::on_send_message_file_part_missing(int64 random_id, int bad delete_random_id_to_message_id_correspondence(d, random_id, m->message_id); add_random_id_to_message_id_correspondence(d, m->random_id, m->message_id); - auto logevent = SendMessageLogEvent(dialog_id, m); - CHECK(m->send_message_logevent_id != 0); - binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage, - get_log_event_storer(logevent)); + auto log_event = SendMessageLogEvent(dialog_id, m); + CHECK(m->send_message_log_event_id != 0); + binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_log_event_id, LogEvent::HandlerType::SendMessage, + get_log_event_storer(log_event)); } do_send_message(dialog_id, m, {bad_part}); @@ -26924,10 +26929,10 @@ void MessagesManager::on_send_message_file_reference_error(int64 random_id) { delete_random_id_to_message_id_correspondence(d, random_id, m->message_id); add_random_id_to_message_id_correspondence(d, m->random_id, m->message_id); - auto logevent = SendMessageLogEvent(dialog_id, m); - CHECK(m->send_message_logevent_id != 0); - binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_logevent_id, LogEvent::HandlerType::SendMessage, - get_log_event_storer(logevent)); + auto log_event = SendMessageLogEvent(dialog_id, m); + CHECK(m->send_message_log_event_id != 0); + binlog_rewrite(G()->td_db()->get_binlog(), m->send_message_log_event_id, LogEvent::HandlerType::SendMessage, + get_log_event_storer(log_event)); } do_send_message(dialog_id, m, {-1}); @@ -27407,7 +27412,7 @@ void MessagesManager::on_update_pinned_dialogs(FolderId folder_id) { return; } - // TODO logevent + delete_logevent_promise + // TODO log event + delete_log_event_promise auto *list = get_dialog_list(DialogListId(folder_id)); if (list == nullptr || !list->are_pinned_dialogs_inited_) { @@ -27595,7 +27600,7 @@ void MessagesManager::repair_dialog_scheduled_messages(Dialog *d) { } d->last_repair_scheduled_messages_generation = scheduled_messages_sync_generation_; - // TODO create logevent + // TODO create log event auto dialog_id = d->dialog_id; LOG(INFO) << "Repair scheduled messages in " << dialog_id << " with generation " << d->last_repair_scheduled_messages_generation; @@ -28075,22 +28080,22 @@ class MessagesManager::GetDialogFromServerLogEvent { } }; -uint64 MessagesManager::save_get_dialog_from_server_logevent(DialogId dialog_id) { - GetDialogFromServerLogEvent logevent{dialog_id}; +uint64 MessagesManager::save_get_dialog_from_server_log_event(DialogId dialog_id) { + GetDialogFromServerLogEvent log_event{dialog_id}; return binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetDialogFromServer, - get_log_event_storer(logevent)); + get_log_event_storer(log_event)); } -void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise &&promise, uint64 logevent_id) { +void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise &&promise, uint64 log_event_id) { if (td_->auth_manager_->is_bot() || dialog_id.get_type() == DialogType::SecretChat) { - if (logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + if (log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), log_event_id); } return promise.set_error(Status::Error(500, "Wrong getDialog query")); } if (!have_input_peer(dialog_id, AccessRights::Read)) { - if (logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + if (log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), log_event_id); } return promise.set_error(Status::Error(400, "Can't access the chat")); } @@ -28098,19 +28103,19 @@ void MessagesManager::send_get_dialog_query(DialogId dialog_id, Promise && auto &promises = get_dialog_queries_[dialog_id]; promises.push_back(std::move(promise)); if (promises.size() != 1) { - if (logevent_id != 0) { + if (log_event_id != 0) { LOG(INFO) << "Duplicate getDialog query for " << dialog_id; - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + binlog_erase(G()->td_db()->get_binlog(), log_event_id); } // query has already been sent, just wait for the result return; } - if (logevent_id == 0 && G()->parameters().use_message_db) { - logevent_id = save_get_dialog_from_server_logevent(dialog_id); + if (log_event_id == 0 && G()->parameters().use_message_db) { + log_event_id = save_get_dialog_from_server_log_event(dialog_id); } - if (logevent_id != 0) { - auto result = get_dialog_query_logevent_id_.emplace(dialog_id, logevent_id); + if (log_event_id != 0) { + auto result = get_dialog_query_log_event_id_.emplace(dialog_id, log_event_id); CHECK(result.second); } if (G()->close_flag()) { @@ -28130,12 +28135,12 @@ void MessagesManager::on_get_dialog_query_finished(DialogId dialog_id, Status && auto promises = std::move(it->second); get_dialog_queries_.erase(it); - auto logevent_it = get_dialog_query_logevent_id_.find(dialog_id); - if (logevent_it != get_dialog_query_logevent_id_.end()) { + auto log_event_it = get_dialog_query_log_event_id_.find(dialog_id); + if (log_event_it != get_dialog_query_log_event_id_.end()) { if (!G()->close_flag()) { - binlog_erase(G()->td_db()->get_binlog(), logevent_it->second); + binlog_erase(G()->td_db()->get_binlog(), log_event_it->second); } - get_dialog_query_logevent_id_.erase(logevent_it); + get_dialog_query_log_event_id_.erase(log_event_it); } for (auto &promise : promises) { @@ -28706,18 +28711,18 @@ void MessagesManager::set_dialog_folder_id_on_server(DialogId dialog_id, bool fr CHECK(d != nullptr); if (!from_binlog && G()->parameters().use_message_db) { - SetDialogFolderIdOnServerLogEvent logevent; - logevent.dialog_id_ = dialog_id; - logevent.folder_id_ = d->folder_id; - add_log_event(d->set_folder_id_logevent_id, get_log_event_storer(logevent), + SetDialogFolderIdOnServerLogEvent log_event; + log_event.dialog_id_ = dialog_id; + log_event.folder_id_ = d->folder_id; + add_log_event(d->set_folder_id_log_event_id, get_log_event_storer(log_event), LogEvent::HandlerType::SetDialogFolderIdOnServer, "set chat folder"); } Promise<> promise; - if (d->set_folder_id_logevent_id.logevent_id != 0) { - d->set_folder_id_logevent_id.generation++; + if (d->set_folder_id_log_event_id.log_event_id != 0) { + d->set_folder_id_log_event_id.generation++; promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, - generation = d->set_folder_id_logevent_id.generation](Result result) { + generation = d->set_folder_id_log_event_id.generation](Result result) { if (!G()->close_flag()) { send_closure(actor_id, &MessagesManager::on_updated_dialog_folder_id, dialog_id, generation); } @@ -28731,7 +28736,7 @@ void MessagesManager::set_dialog_folder_id_on_server(DialogId dialog_id, bool fr void MessagesManager::on_updated_dialog_folder_id(DialogId dialog_id, uint64 generation) { auto d = get_dialog(dialog_id); CHECK(d != nullptr); - delete_log_event(d->set_folder_id_logevent_id, generation, "set chat folder"); + delete_log_event(d->set_folder_id_log_event_id, generation, "set chat folder"); } void MessagesManager::set_dialog_photo(DialogId dialog_id, const tl_object_ptr &input_photo, @@ -31041,41 +31046,41 @@ void MessagesManager::delete_message_from_database(Dialog *d, MessageId message_ return; } - DeleteMessageLogEvent logevent; + DeleteMessageLogEvent log_event; - logevent.full_message_id_ = {d->dialog_id, message_id}; + log_event.full_message_id_ = {d->dialog_id, message_id}; if (need_delete_files) { - logevent.file_ids_ = get_message_file_ids(m); + log_event.file_ids_ = get_message_file_ids(m); } - do_delete_message_logevent(logevent); + do_delete_message_log_event(log_event); } -void MessagesManager::do_delete_message_logevent(const DeleteMessageLogEvent &logevent) const { +void MessagesManager::do_delete_message_log_event(const DeleteMessageLogEvent &log_event) const { CHECK(G()->parameters().use_message_db); Promise db_promise; - if (!logevent.file_ids_.empty()) { - auto logevent_id = logevent.id_; - if (logevent_id == 0) { - logevent_id = - binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessage, get_log_event_storer(logevent)); + if (!log_event.file_ids_.empty()) { + auto log_event_id = log_event.id_; + if (log_event_id == 0) { + log_event_id = + binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::DeleteMessage, get_log_event_storer(log_event)); } MultiPromiseActorSafe mpas{"DeleteMessageMultiPromiseActor"}; - mpas.add_promise(PromiseCreator::lambda([logevent_id](Result result) { + mpas.add_promise(PromiseCreator::lambda([log_event_id](Result result) { if (result.is_error() || G()->close_flag()) { return; } - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + binlog_erase(G()->td_db()->get_binlog(), log_event_id); })); auto lock = mpas.get_promise(); - for (auto file_id : logevent.file_ids_) { - if (need_delete_file(logevent.full_message_id_, file_id)) { + for (auto file_id : log_event.file_ids_) { + if (need_delete_file(log_event.full_message_id_, file_id)) { send_closure(G()->file_manager(), &FileManager::delete_file, file_id, mpas.get_promise(), - "do_delete_message_logevent"); + "do_delete_message_log_event"); } } db_promise = mpas.get_promise(); @@ -31083,8 +31088,8 @@ void MessagesManager::do_delete_message_logevent(const DeleteMessageLogEvent &lo } // message may not exist in the dialog - LOG(INFO) << "Delete " << logevent.full_message_id_ << " from database"; - G()->td_db()->get_messages_db_async()->delete_message(logevent.full_message_id_, std::move(db_promise)); + LOG(INFO) << "Delete " << log_event.full_message_id_ << " from database"; + G()->td_db()->get_messages_db_async()->delete_message(log_event.full_message_id_, std::move(db_promise)); } void MessagesManager::attach_message_to_previous(Dialog *d, MessageId message_id, const char *source) { @@ -33311,15 +33316,15 @@ void MessagesManager::get_channel_difference(DialogId dialog_id, int32 pts, bool return; } - if (force && get_channel_difference_to_logevent_id_.count(dialog_id) == 0 && !G()->ignore_backgrond_updates()) { + if (force && get_channel_difference_to_log_event_id_.count(dialog_id) == 0 && !G()->ignore_backgrond_updates()) { auto channel_id = dialog_id.get_channel_id(); CHECK(input_channel->get_id() == telegram_api::inputChannel::ID); auto access_hash = static_cast(*input_channel).access_hash_; - auto logevent = GetChannelDifferenceLogEvent(channel_id, access_hash); - auto logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetChannelDifference, - get_log_event_storer(logevent)); + auto log_event = GetChannelDifferenceLogEvent(channel_id, access_hash); + auto log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::GetChannelDifference, + get_log_event_storer(log_event)); - get_channel_difference_to_logevent_id_.emplace(dialog_id, logevent_id); + get_channel_difference_to_log_event_id_.emplace(dialog_id, log_event_id); } return do_get_channel_difference(dialog_id, pts, force, std::move(input_channel), source); @@ -33703,12 +33708,12 @@ void MessagesManager::after_get_channel_difference(DialogId dialog_id, bool succ LOG(INFO) << "After " << (success ? "" : "un") << "successful get channel difference in " << dialog_id; LOG_CHECK(!running_get_channel_difference(dialog_id)) << '"' << active_get_channel_differencies_[dialog_id] << '"'; - auto logevent_it = get_channel_difference_to_logevent_id_.find(dialog_id); - if (logevent_it != get_channel_difference_to_logevent_id_.end()) { + auto log_event_it = get_channel_difference_to_log_event_id_.find(dialog_id); + if (log_event_it != get_channel_difference_to_log_event_id_.end()) { if (!G()->close_flag()) { - binlog_erase(G()->td_db()->get_binlog(), logevent_it->second); + binlog_erase(G()->td_db()->get_binlog(), log_event_it->second); } - get_channel_difference_to_logevent_id_.erase(logevent_it); + get_channel_difference_to_log_event_id_.erase(log_event_it); } auto d = get_dialog(dialog_id); @@ -33965,19 +33970,19 @@ void MessagesManager::try_hide_distance(DialogId dialog_id, const Message *m) { } MessagesManager::Message *MessagesManager::continue_send_message(DialogId dialog_id, unique_ptr &&m, - uint64 logevent_id) { - CHECK(logevent_id != 0); + uint64 log_event_id) { + CHECK(log_event_id != 0); CHECK(m != nullptr); CHECK(m->content != nullptr); Dialog *d = get_dialog_force(dialog_id); if (d == nullptr) { LOG(ERROR) << "Can't find " << dialog_id << " to continue send a message"; - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + binlog_erase(G()->td_db()->get_binlog(), log_event_id); return nullptr; } if (!have_input_peer(dialog_id, AccessRights::Read)) { - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + binlog_erase(G()->td_db()->get_binlog(), log_event_id); return nullptr; } @@ -34039,7 +34044,7 @@ void MessagesManager::on_binlog_events(vector &&events) { auto dialog_id = log_event.dialog_id; auto m = std::move(log_event.m_out); - m->send_message_logevent_id = event.id_; + m->send_message_log_event_id = event.id_; if (m->content->get_type() == MessageContentType::Unsupported) { LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_)); @@ -34073,7 +34078,7 @@ void MessagesManager::on_binlog_events(vector &&events) { auto dialog_id = log_event.dialog_id; auto m = std::move(log_event.m_out); - m->send_message_logevent_id = event.id_; + m->send_message_log_event_id = event.id_; CHECK(m->content->get_type() == MessageContentType::Text); @@ -34106,7 +34111,7 @@ void MessagesManager::on_binlog_events(vector &&events) { auto dialog_id = log_event.dialog_id; auto m = std::move(log_event.m_out); - m->send_message_logevent_id = event.id_; + m->send_message_log_event_id = event.id_; if (m->content->get_type() == MessageContentType::Unsupported) { LOG(ERROR) << "Message content is invalid: " << format::as_hex_dump<4>(Slice(event.data_)); @@ -34139,7 +34144,7 @@ void MessagesManager::on_binlog_events(vector &&events) { auto dialog_id = log_event.dialog_id; auto m = std::move(log_event.m_out); - m->send_message_logevent_id = 0; // to not allow event deletion by message deletion + m->send_message_log_event_id = 0; // to not allow event deletion by message deletion CHECK(m->content->get_type() == MessageContentType::ScreenshotTaken); @@ -34250,7 +34255,7 @@ void MessagesManager::on_binlog_events(vector &&events) { } } - do_delete_message_logevent(log_event); + do_delete_message_log_event(log_event); break; } case LogEvent::HandlerType::DeleteMessagesFromServer: { @@ -34359,11 +34364,11 @@ void MessagesManager::on_binlog_events(vector &&events) { binlog_erase(G()->td_db()->get_binlog(), event.id_); break; } - if (d->read_history_logevent_ids[0].logevent_id != 0) { + if (d->read_history_log_event_ids[0].log_event_id != 0) { // we need only latest read history event - binlog_erase(G()->td_db()->get_binlog(), d->read_history_logevent_ids[0].logevent_id); + binlog_erase(G()->td_db()->get_binlog(), d->read_history_log_event_ids[0].log_event_id); } - d->read_history_logevent_ids[0].logevent_id = event.id_; + d->read_history_log_event_ids[0].log_event_id = event.id_; read_history_on_server_impl(d, log_event.max_message_id_); break; @@ -34385,11 +34390,11 @@ void MessagesManager::on_binlog_events(vector &&events) { binlog_erase(G()->td_db()->get_binlog(), event.id_); break; } - if (d->read_history_logevent_ids[0].logevent_id != 0) { + if (d->read_history_log_event_ids[0].log_event_id != 0) { // we need only latest read history event - binlog_erase(G()->td_db()->get_binlog(), d->read_history_logevent_ids[0].logevent_id); + binlog_erase(G()->td_db()->get_binlog(), d->read_history_log_event_ids[0].log_event_id); } - d->read_history_logevent_ids[0].logevent_id = event.id_; + d->read_history_log_event_ids[0].log_event_id = event.id_; d->last_read_inbox_message_date = log_event.max_date_; read_history_on_server_impl(d, MessageId()); @@ -34411,12 +34416,12 @@ void MessagesManager::on_binlog_events(vector &&events) { break; } auto top_thread_message_id = log_event.top_thread_message_id_; - if (d->read_history_logevent_ids[top_thread_message_id.get()].logevent_id != 0) { + if (d->read_history_log_event_ids[top_thread_message_id.get()].log_event_id != 0) { // we need only latest read history event binlog_erase(G()->td_db()->get_binlog(), - d->read_history_logevent_ids[top_thread_message_id.get()].logevent_id); + d->read_history_log_event_ids[top_thread_message_id.get()].log_event_id); } - d->read_history_logevent_ids[top_thread_message_id.get()].logevent_id = event.id_; + d->read_history_log_event_ids[top_thread_message_id.get()].log_event_id = event.id_; read_message_thread_history_on_server_impl(d, top_thread_message_id, log_event.max_message_id_); break; @@ -34555,7 +34560,7 @@ void MessagesManager::on_binlog_events(vector &&events) { binlog_erase(G()->td_db()->get_binlog(), event.id_); break; } - d->save_draft_message_logevent_id.logevent_id = event.id_; + d->save_draft_message_log_event_id.log_event_id = event.id_; save_dialog_draft_message_on_server(dialog_id); break; @@ -34575,7 +34580,7 @@ void MessagesManager::on_binlog_events(vector &&events) { binlog_erase(G()->td_db()->get_binlog(), event.id_); break; } - d->save_notification_settings_logevent_id.logevent_id = event.id_; + d->save_notification_settings_log_event_id.log_event_id = event.id_; update_dialog_notification_settings_on_server(dialog_id, true); break; @@ -34628,7 +34633,7 @@ void MessagesManager::on_binlog_events(vector &&events) { binlog_erase(G()->td_db()->get_binlog(), event.id_); break; } - d->set_folder_id_logevent_id.logevent_id = event.id_; + d->set_folder_id_log_event_id.log_event_id = event.id_; set_dialog_folder_id(d, log_event.folder_id_); @@ -34670,7 +34675,7 @@ void MessagesManager::on_binlog_events(vector &&events) { DialogId dialog_id(log_event.channel_id); LOG(INFO) << "Continue to run getChannelDifference in " << dialog_id; - get_channel_difference_to_logevent_id_.emplace(dialog_id, event.id_); + get_channel_difference_to_log_event_id_.emplace(dialog_id, event.id_); do_get_channel_difference( dialog_id, load_channel_pts(dialog_id), true, telegram_api::make_object(log_event.channel_id.get(), log_event.access_hash), @@ -34678,7 +34683,7 @@ void MessagesManager::on_binlog_events(vector &&events) { break; } default: - LOG(FATAL) << "Unsupported logevent type " << event.type_; + LOG(FATAL) << "Unsupported log event type " << event.type_; } } } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 46e53c7b9..c47af4536 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1093,7 +1093,7 @@ class MessagesManager : public Actor { mutable int32 last_access_date = 0; - mutable uint64 send_message_logevent_id = 0; + mutable uint64 send_message_log_event_id = 0; mutable NetQueryRef send_query_ref; @@ -1146,11 +1146,11 @@ class MessagesManager : public Actor { MessageId reply_markup_message_id; DialogNotificationSettings notification_settings; unique_ptr draft_message; - LogeventIdWithGeneration save_draft_message_logevent_id; - LogeventIdWithGeneration save_notification_settings_logevent_id; - std::unordered_map read_history_logevent_ids; + LogeventIdWithGeneration save_draft_message_log_event_id; + LogeventIdWithGeneration save_notification_settings_log_event_id; + std::unordered_map read_history_log_event_ids; std::unordered_set updated_read_history_message_ids; - LogeventIdWithGeneration set_folder_id_logevent_id; + LogeventIdWithGeneration set_folder_id_log_event_id; FolderId folder_id; vector dialog_list_ids; // TODO replace with mask @@ -1777,7 +1777,7 @@ class MessagesManager : public Actor { bool skip_update_for_not_found_messages); void do_forward_messages(DialogId to_dialog_id, DialogId from_dialog_id, const vector &messages, - const vector &message_ids, uint64 logevent_id); + const vector &message_ids, uint64 log_event_id); Result forward_message(DialogId to_dialog_id, DialogId from_dialog_id, MessageId message_id, tl_object_ptr &&options, bool in_game_share, @@ -1810,22 +1810,22 @@ class MessagesManager : public Actor { void on_yet_unsent_media_queue_updated(DialogId dialog_id); - void save_send_bot_start_message_logevent(UserId bot_user_id, DialogId dialog_id, const string ¶meter, - const Message *m); + void save_send_bot_start_message_log_event(UserId bot_user_id, DialogId dialog_id, const string ¶meter, + const Message *m); void do_send_bot_start_message(UserId bot_user_id, DialogId dialog_id, const string ¶meter, const Message *m); - void save_send_inline_query_result_message_logevent(DialogId dialog_id, const Message *m, int64 query_id, - const string &result_id); + void save_send_inline_query_result_message_log_event(DialogId dialog_id, const Message *m, int64 query_id, + const string &result_id); void do_send_inline_query_result_message(DialogId dialog_id, const Message *m, int64 query_id, const string &result_id); - uint64 save_send_screenshot_taken_notification_message_logevent(DialogId dialog_id, const Message *m); + uint64 save_send_screenshot_taken_notification_message_log_event(DialogId dialog_id, const Message *m); - void do_send_screenshot_taken_notification_message(DialogId dialog_id, const Message *m, uint64 logevent_id); + void do_send_screenshot_taken_notification_message(DialogId dialog_id, const Message *m, uint64 log_event_id); - Message *continue_send_message(DialogId dialog_id, unique_ptr &&m, uint64 logevent_id); + Message *continue_send_message(DialogId dialog_id, unique_ptr &&m, uint64 log_event_id); bool is_message_unload_enabled() const; @@ -1867,19 +1867,19 @@ class MessagesManager : public Actor { void delete_message_from_server(DialogId dialog_id, MessageId message_ids, bool revoke); - void delete_messages_from_server(DialogId dialog_id, vector message_ids, bool revoke, uint64 logevent_id, + void delete_messages_from_server(DialogId dialog_id, vector message_ids, bool revoke, uint64 log_event_id, Promise &&promise); - void delete_scheduled_messages_from_server(DialogId dialog_id, vector message_ids, uint64 logevent_id, + void delete_scheduled_messages_from_server(DialogId dialog_id, vector message_ids, uint64 log_event_id, Promise &&promise); void delete_dialog_history_from_server(DialogId dialog_id, MessageId max_message_id, bool remove_from_dialog_list, - bool revoke, bool allow_error, uint64 logevent_id, Promise &&promise); + bool revoke, bool allow_error, uint64 log_event_id, Promise &&promise); - void delete_all_channel_messages_from_user_on_server(ChannelId channel_id, UserId user_id, uint64 logevent_id, + void delete_all_channel_messages_from_user_on_server(ChannelId channel_id, UserId user_id, uint64 log_event_id, Promise &&promise); - void read_all_dialog_mentions_on_server(DialogId dialog_id, uint64 logevent_id, Promise &&promise); + void read_all_dialog_mentions_on_server(DialogId dialog_id, uint64 log_event_id, Promise &&promise); static MessageId find_message_by_date(const Message *m, int32 date); @@ -1918,8 +1918,8 @@ class MessagesManager : public Actor { bool read_message_content(Dialog *d, Message *m, bool is_local_read, const char *source); - void read_message_contents_on_server(DialogId dialog_id, vector message_ids, uint64 logevent_id, - Promise &&promise, bool skip_logevent = false); + void read_message_contents_on_server(DialogId dialog_id, vector message_ids, uint64 log_event_id, + Promise &&promise, bool skip_log_event = false); bool has_incoming_notification(DialogId dialog_id, const Message *m) const; @@ -2065,7 +2065,7 @@ class MessagesManager : public Actor { NotificationId prev_last_notification_id, Result> result); - void do_delete_message_logevent(const DeleteMessageLogEvent &logevent) const; + void do_delete_message_log_event(const DeleteMessageLogEvent &log_event) const; void attach_message_to_previous(Dialog *d, MessageId message_id, const char *source); @@ -2265,13 +2265,13 @@ class MessagesManager : public Actor { void do_set_dialog_folder_id(Dialog *d, FolderId folder_id); - void toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 logevent_id); + void toggle_dialog_is_pinned_on_server(DialogId dialog_id, bool is_pinned, uint64 log_event_id); - void toggle_dialog_is_marked_as_unread_on_server(DialogId dialog_id, bool is_marked_as_unread, uint64 logevent_id); + void toggle_dialog_is_marked_as_unread_on_server(DialogId dialog_id, bool is_marked_as_unread, uint64 log_event_id); - void toggle_dialog_is_blocked_on_server(DialogId dialog_id, bool is_blocked, uint64 logevent_id); + void toggle_dialog_is_blocked_on_server(DialogId dialog_id, bool is_blocked, uint64 log_event_id); - void reorder_pinned_dialogs_on_server(FolderId folder_id, const vector &dialog_ids, uint64 logevent_id); + void reorder_pinned_dialogs_on_server(FolderId folder_id, const vector &dialog_ids, uint64 log_event_id); void set_dialog_reply_markup(Dialog *d, MessageId message_id); @@ -2359,7 +2359,7 @@ class MessagesManager : public Actor { void on_get_dialogs_from_database(FolderId folder_id, int32 limit, DialogDbGetDialogsResult &&dialogs, Promise &&promise); - void send_get_dialog_query(DialogId dialog_id, Promise &&promise, uint64 logevent_id = 0); + void send_get_dialog_query(DialogId dialog_id, Promise &&promise, uint64 log_event_id = 0); void send_search_public_dialogs_query(const string &query, Promise &&promise); @@ -2645,11 +2645,11 @@ class MessagesManager : public Actor { void on_updated_dialog_notification_settings(DialogId dialog_id, uint64 generation); - void update_scope_notification_settings_on_server(NotificationSettingsScope scope, uint64 logevent_id); + void update_scope_notification_settings_on_server(NotificationSettingsScope scope, uint64 log_event_id); - void reset_all_notification_settings_on_server(uint64 logevent_id); + void reset_all_notification_settings_on_server(uint64 log_event_id); - void change_dialog_report_spam_state_on_server(DialogId dialog_id, bool is_spam_dialog, uint64 logevent_id, + void change_dialog_report_spam_state_on_server(DialogId dialog_id, bool is_spam_dialog, uint64 log_event_id, Promise &&promise); void set_dialog_folder_id_on_server(DialogId dialog_id, bool from_binlog); @@ -2821,40 +2821,40 @@ class MessagesManager : public Actor { static void add_message_dependencies(Dependencies &dependencies, DialogId dialog_id, const Message *m); - void save_send_message_logevent(DialogId dialog_id, const Message *m); + void save_send_message_log_event(DialogId dialog_id, const Message *m); - uint64 save_change_dialog_report_spam_state_on_server_logevent(DialogId dialog_id, bool is_spam_dialog); + uint64 save_change_dialog_report_spam_state_on_server_log_event(DialogId dialog_id, bool is_spam_dialog); - uint64 save_delete_messages_from_server_logevent(DialogId dialog_id, const vector &message_ids, - bool revoke); + uint64 save_delete_messages_from_server_log_event(DialogId dialog_id, const vector &message_ids, + bool revoke); - uint64 save_delete_scheduled_messages_from_server_logevent(DialogId dialog_id, const vector &message_ids); + uint64 save_delete_scheduled_messages_from_server_log_event(DialogId dialog_id, const vector &message_ids); - uint64 save_delete_dialog_history_from_server_logevent(DialogId dialog_id, MessageId max_message_id, - bool remove_from_dialog_list, bool revoke); + uint64 save_delete_dialog_history_from_server_log_event(DialogId dialog_id, MessageId max_message_id, + bool remove_from_dialog_list, bool revoke); - uint64 save_delete_all_channel_messages_from_user_on_server_logevent(ChannelId channel_id, UserId user_id); + uint64 save_delete_all_channel_messages_from_user_on_server_log_event(ChannelId channel_id, UserId user_id); - uint64 save_read_all_dialog_mentions_on_server_logevent(DialogId dialog_id); + uint64 save_read_all_dialog_mentions_on_server_log_event(DialogId dialog_id); - uint64 save_toggle_dialog_is_pinned_on_server_logevent(DialogId dialog_id, bool is_pinned); + uint64 save_toggle_dialog_is_pinned_on_server_log_event(DialogId dialog_id, bool is_pinned); - uint64 save_reorder_pinned_dialogs_on_server_logevent(FolderId folder_id, const vector &dialog_ids); + uint64 save_reorder_pinned_dialogs_on_server_log_event(FolderId folder_id, const vector &dialog_ids); - uint64 save_toggle_dialog_is_marked_as_unread_on_server_logevent(DialogId dialog_id, bool is_marked_as_unread); + uint64 save_toggle_dialog_is_marked_as_unread_on_server_log_event(DialogId dialog_id, bool is_marked_as_unread); - uint64 save_toggle_dialog_is_blocked_on_server_logevent(DialogId dialog_id, bool is_blocked); + uint64 save_toggle_dialog_is_blocked_on_server_log_event(DialogId dialog_id, bool is_blocked); - uint64 save_read_message_contents_on_server_logevent(DialogId dialog_id, const vector &message_ids); + uint64 save_read_message_contents_on_server_log_event(DialogId dialog_id, const vector &message_ids); - uint64 save_update_scope_notification_settings_on_server_logevent(NotificationSettingsScope scope); + uint64 save_update_scope_notification_settings_on_server_log_event(NotificationSettingsScope scope); - uint64 save_reset_all_notification_settings_on_server_logevent(); + uint64 save_reset_all_notification_settings_on_server_log_event(); - uint64 save_get_dialog_from_server_logevent(DialogId dialog_id); + uint64 save_get_dialog_from_server_log_event(DialogId dialog_id); - uint64 save_forward_messages_logevent(DialogId to_dialog_id, DialogId from_dialog_id, - const vector &messages, const vector &message_ids); + uint64 save_forward_messages_log_event(DialogId to_dialog_id, DialogId from_dialog_id, + const vector &messages, const vector &message_ids); void suffix_load_loop(Dialog *d); void suffix_load_update_first_message_id(Dialog *d); @@ -3047,7 +3047,7 @@ class MessagesManager : public Actor { std::unordered_map>, DialogIdHash> get_dialog_notification_settings_queries_; std::unordered_map>, DialogIdHash> get_dialog_queries_; - std::unordered_map get_dialog_query_logevent_id_; + std::unordered_map get_dialog_query_log_event_id_; std::unordered_map replied_by_yet_unsent_messages_; @@ -3093,7 +3093,7 @@ class MessagesManager : public Actor { vector> dialog_filter_reload_queries_; std::unordered_map active_get_channel_differencies_; - std::unordered_map get_channel_difference_to_logevent_id_; + std::unordered_map get_channel_difference_to_log_event_id_; MultiTimeout channel_get_difference_timeout_{"ChannelGetDifferenceTimeout"}; MultiTimeout channel_get_difference_retry_timeout_{"ChannelGetDifferenceRetryTimeout"}; diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 155c24133..6ae3c7b46 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -1654,25 +1654,25 @@ void NotificationManager::on_notification_processed(NotificationId notification_ void NotificationManager::on_notification_removed(NotificationId notification_id) { VLOG(notifications) << "In on_notification_removed with " << notification_id; - auto add_it = temporary_notification_logevent_ids_.find(notification_id); - if (add_it == temporary_notification_logevent_ids_.end()) { + auto add_it = temporary_notification_log_event_ids_.find(notification_id); + if (add_it == temporary_notification_log_event_ids_.end()) { return; } - auto edit_it = temporary_edit_notification_logevent_ids_.find(notification_id); - if (edit_it != temporary_edit_notification_logevent_ids_.end()) { - VLOG(notifications) << "Remove from binlog edit of " << notification_id << " with logevent " << edit_it->second; + auto edit_it = temporary_edit_notification_log_event_ids_.find(notification_id); + if (edit_it != temporary_edit_notification_log_event_ids_.end()) { + VLOG(notifications) << "Remove from binlog edit of " << notification_id << " with log event " << edit_it->second; if (!is_being_destroyed_) { binlog_erase(G()->td_db()->get_binlog(), edit_it->second); } - temporary_edit_notification_logevent_ids_.erase(edit_it); + temporary_edit_notification_log_event_ids_.erase(edit_it); } - VLOG(notifications) << "Remove from binlog " << notification_id << " with logevent " << add_it->second; + VLOG(notifications) << "Remove from binlog " << notification_id << " with log event " << add_it->second; if (!is_being_destroyed_) { binlog_erase(G()->td_db()->get_binlog(), add_it->second); } - temporary_notification_logevent_ids_.erase(add_it); + temporary_notification_log_event_ids_.erase(add_it); auto erased_notification_count = temporary_notifications_.erase(temporary_notification_message_ids_[notification_id]); auto erased_message_id_count = temporary_notification_message_ids_.erase(notification_id); @@ -3547,18 +3547,18 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess string sender_name, int32 date, bool is_from_scheduled, bool contains_mention, bool initial_is_silent, bool is_silent, string loc_key, string arg, Photo photo, Document document, - NotificationId notification_id, uint64 logevent_id, + NotificationId notification_id, uint64 log_event_id, Promise promise) { auto is_pinned = begins_with(loc_key, "PINNED_"); auto r_info = td_->messages_manager_->get_message_push_notification_info( dialog_id, message_id, random_id, sender_user_id, sender_dialog_id, date, is_from_scheduled, contains_mention, - is_pinned, logevent_id != 0); + is_pinned, log_event_id != 0); if (r_info.is_error()) { VLOG(notifications) << "Don't need message push notification for " << message_id << "/" << random_id << " from " << dialog_id << " sent by " << sender_user_id << "/" << sender_dialog_id << " at " << date << ": " << r_info.error(); - if (logevent_id != 0) { - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + if (log_event_id != 0) { + binlog_erase(G()->td_db()->get_binlog(), log_event_id); } if (r_info.error().code() == 406) { promise.set_error(r_info.move_as_error()); @@ -3576,24 +3576,24 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess // TODO support secret chat notifications // main problem: there is no message_id yet // also don't forget to delete newSecretChat notification - CHECK(logevent_id == 0); + CHECK(log_event_id == 0); return promise.set_error(Status::Error(406, "Secret chat push notifications are unsupported")); } CHECK(random_id == 0); if (is_disabled() || max_notification_group_count_ == 0) { - CHECK(logevent_id == 0); + CHECK(log_event_id == 0); return promise.set_error(Status::Error(200, "Immediate success")); } if (!notification_id.is_valid()) { - CHECK(logevent_id == 0); + CHECK(log_event_id == 0); notification_id = get_next_notification_id(); if (!notification_id.is_valid()) { return promise.set_value(Unit()); } } else { - CHECK(logevent_id != 0); + CHECK(log_event_id != 0); } if (sender_user_id.is_valid() && !td_->contacts_manager_->have_user_force(sender_user_id)) { @@ -3607,13 +3607,13 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess td_->contacts_manager_->on_get_user(std::move(user), "add_message_push_notification"); } - if (logevent_id == 0 && G()->parameters().use_message_db) { - AddMessagePushNotificationLogEvent logevent{ + if (log_event_id == 0 && G()->parameters().use_message_db) { + AddMessagePushNotificationLogEvent log_event{ dialog_id, message_id, random_id, sender_user_id, sender_dialog_id, sender_name, date, is_from_scheduled, contains_mention, initial_is_silent, loc_key, arg, photo, document, notification_id}; - logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification, - get_log_event_storer(logevent)); + log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::AddMessagePushNotification, + get_log_event_storer(log_event)); } auto group_id = info.group_id; @@ -3621,9 +3621,9 @@ void NotificationManager::add_message_push_notification(DialogId dialog_id, Mess bool is_outgoing = sender_user_id.is_valid() ? td_->contacts_manager_->get_my_id() == sender_user_id : is_from_scheduled; - if (logevent_id != 0) { - VLOG(notifications) << "Register temporary " << notification_id << " with logevent " << logevent_id; - temporary_notification_logevent_ids_[notification_id] = logevent_id; + if (log_event_id != 0) { + VLOG(notifications) << "Register temporary " << notification_id << " with log event " << log_event_id; + temporary_notification_log_event_ids_[notification_id] = log_event_id; temporary_notifications_[FullMessageId(dialog_id, message_id)] = {group_id, notification_id, sender_user_id, sender_dialog_id, sender_name, is_outgoing}; temporary_notification_message_ids_[notification_id] = FullMessageId(dialog_id, message_id); @@ -3716,9 +3716,9 @@ class NotificationManager::EditMessagePushNotificationLogEvent { void NotificationManager::edit_message_push_notification(DialogId dialog_id, MessageId message_id, int32 edit_date, string loc_key, string arg, Photo photo, Document document, - uint64 logevent_id, Promise promise) { + uint64 log_event_id, Promise promise) { if (is_disabled() || max_notification_group_count_ == 0) { - CHECK(logevent_id == 0); + CHECK(log_event_id == 0); return promise.set_error(Status::Error(200, "Immediate success")); } @@ -3738,23 +3738,23 @@ void NotificationManager::edit_message_push_notification(DialogId dialog_id, Mes CHECK(group_id.is_valid()); CHECK(notification_id.is_valid()); - if (logevent_id == 0 && G()->parameters().use_message_db) { - EditMessagePushNotificationLogEvent logevent{dialog_id, message_id, edit_date, loc_key, arg, photo, document}; - auto storer = get_log_event_storer(logevent); - auto &cur_logevent_id = temporary_edit_notification_logevent_ids_[notification_id]; - if (cur_logevent_id == 0) { - logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::EditMessagePushNotification, storer); - cur_logevent_id = logevent_id; - VLOG(notifications) << "Add edit message push notification logevent " << logevent_id; + if (log_event_id == 0 && G()->parameters().use_message_db) { + EditMessagePushNotificationLogEvent log_event{dialog_id, message_id, edit_date, loc_key, arg, photo, document}; + auto storer = get_log_event_storer(log_event); + auto &cur_log_event_id = temporary_edit_notification_log_event_ids_[notification_id]; + if (cur_log_event_id == 0) { + log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::EditMessagePushNotification, storer); + cur_log_event_id = log_event_id; + VLOG(notifications) << "Add edit message push notification log event " << log_event_id; } else { - auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog(), cur_logevent_id, - LogEvent::HandlerType::EditMessagePushNotification, storer); - VLOG(notifications) << "Rewrite edit message push notification logevent " << cur_logevent_id << " with " - << new_logevent_id; + auto new_log_event_id = binlog_rewrite(G()->td_db()->get_binlog(), cur_log_event_id, + LogEvent::HandlerType::EditMessagePushNotification, storer); + VLOG(notifications) << "Rewrite edit message push notification log event " << cur_log_event_id << " with " + << new_log_event_id; } - } else if (logevent_id != 0) { - VLOG(notifications) << "Register edit of temporary " << notification_id << " with logevent " << logevent_id; - temporary_edit_notification_logevent_ids_[notification_id] = logevent_id; + } else if (log_event_id != 0) { + VLOG(notifications) << "Register edit of temporary " << notification_id << " with log event " << log_event_id; + temporary_edit_notification_log_event_ids_[notification_id] = log_event_id; } push_notification_promises_[notification_id].push_back(std::move(promise)); @@ -4113,7 +4113,7 @@ void NotificationManager::on_binlog_events(vector &&events) { break; } default: - LOG(FATAL) << "Unsupported logevent type " << event.type_; + LOG(FATAL) << "Unsupported log event type " << event.type_; } } if (is_inited_) { diff --git a/td/telegram/NotificationManager.h b/td/telegram/NotificationManager.h index 5748b7fd3..aeacc05e3 100644 --- a/td/telegram/NotificationManager.h +++ b/td/telegram/NotificationManager.h @@ -310,10 +310,10 @@ class NotificationManager : public Actor { DialogId sender_dialog_id, string sender_name, int32 date, bool is_from_scheduled, bool contains_mention, bool initial_is_silent, bool is_silent, string loc_key, string arg, Photo photo, Document document, NotificationId notification_id, - uint64 logevent_id, Promise promise); + uint64 log_event_id, Promise promise); void edit_message_push_notification(DialogId dialog_id, MessageId message_id, int32 edit_date, string loc_key, - string arg, Photo photo, Document document, uint64 logevent_id, + string arg, Photo photo, Document document, uint64 log_event_id, Promise promise); void after_get_difference_impl(); @@ -382,8 +382,8 @@ class NotificationManager : public Actor { std::unordered_set available_call_notification_group_ids_; std::unordered_map dialog_id_to_call_notification_group_id_; - std::unordered_map temporary_notification_logevent_ids_; - std::unordered_map temporary_edit_notification_logevent_ids_; + std::unordered_map temporary_notification_log_event_ids_; + std::unordered_map temporary_edit_notification_log_event_ids_; struct TemporaryNotification { NotificationGroupId group_id; NotificationId notification_id; diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index c6ec62a9d..42ca81e54 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -749,7 +749,7 @@ class PollManager::SetPollAnswerLogEvent { }; void PollManager::do_set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector &&options, - uint64 logevent_id, Promise &&promise) { + uint64 log_event_id, Promise &&promise) { LOG(INFO) << "Set answer in " << poll_id << " from " << full_message_id; auto &pending_answer = pending_answers_[poll_id]; if (!pending_answer.promises_.empty() && pending_answer.options_ == options) { @@ -757,27 +757,27 @@ void PollManager::do_set_poll_answer(PollId poll_id, FullMessageId full_message_ return; } - if (pending_answer.logevent_id_ != 0 && logevent_id != 0) { - LOG(ERROR) << "Duplicate SetPollAnswer log event: " << pending_answer.logevent_id_ << " and " << logevent_id; - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + if (pending_answer.log_event_id_ != 0 && log_event_id != 0) { + LOG(ERROR) << "Duplicate SetPollAnswer log event: " << pending_answer.log_event_id_ << " and " << log_event_id; + binlog_erase(G()->td_db()->get_binlog(), log_event_id); return; } - if (logevent_id == 0 && G()->parameters().use_message_db) { - SetPollAnswerLogEvent logevent; - logevent.poll_id_ = poll_id; - logevent.full_message_id_ = full_message_id; - logevent.options_ = options; - auto storer = get_log_event_storer(logevent); + if (log_event_id == 0 && G()->parameters().use_message_db) { + SetPollAnswerLogEvent log_event; + log_event.poll_id_ = poll_id; + log_event.full_message_id_ = full_message_id; + log_event.options_ = options; + auto storer = get_log_event_storer(log_event); if (pending_answer.generation_ == 0) { - CHECK(pending_answer.logevent_id_ == 0); - logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SetPollAnswer, storer); - LOG(INFO) << "Add set poll answer logevent " << logevent_id; + CHECK(pending_answer.log_event_id_ == 0); + log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::SetPollAnswer, storer); + LOG(INFO) << "Add set poll answer log event " << log_event_id; } else { - CHECK(pending_answer.logevent_id_ != 0); - logevent_id = pending_answer.logevent_id_; - auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog(), pending_answer.logevent_id_, - LogEvent::HandlerType::SetPollAnswer, storer); - LOG(INFO) << "Rewrite set poll answer logevent " << logevent_id << " with " << new_logevent_id; + CHECK(pending_answer.log_event_id_ != 0); + log_event_id = pending_answer.log_event_id_; + auto new_log_event_id = binlog_rewrite(G()->td_db()->get_binlog(), pending_answer.log_event_id_, + LogEvent::HandlerType::SetPollAnswer, storer); + LOG(INFO) << "Rewrite set poll answer log event " << log_event_id << " with " << new_log_event_id; } } @@ -803,7 +803,7 @@ void PollManager::do_set_poll_answer(PollId poll_id, FullMessageId full_message_ pending_answer.options_ = std::move(options); pending_answer.promises_.push_back(std::move(promise)); pending_answer.generation_ = generation; - pending_answer.logevent_id_ = logevent_id; + pending_answer.log_event_id_ = log_event_id; notify_on_poll_update(poll_id); @@ -833,9 +833,9 @@ void PollManager::on_set_poll_answer(PollId poll_id, uint64 generation, return; } - if (pending_answer.logevent_id_ != 0) { - LOG(INFO) << "Delete set poll answer logevent " << pending_answer.logevent_id_; - binlog_erase(G()->td_db()->get_binlog(), pending_answer.logevent_id_); + if (pending_answer.log_event_id_ != 0) { + LOG(INFO) << "Delete set poll answer log event " << pending_answer.log_event_id_; + binlog_erase(G()->td_db()->get_binlog(), pending_answer.log_event_id_); } auto promises = std::move(pending_answer.promises_); @@ -1104,17 +1104,17 @@ class PollManager::StopPollLogEvent { }; void PollManager::do_stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr &&reply_markup, - uint64 logevent_id, Promise &&promise) { + uint64 log_event_id, Promise &&promise) { LOG(INFO) << "Stop " << poll_id << " from " << full_message_id; - if (logevent_id == 0 && G()->parameters().use_message_db && reply_markup == nullptr) { - StopPollLogEvent logevent{poll_id, full_message_id}; - logevent_id = - binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::StopPoll, get_log_event_storer(logevent)); + if (log_event_id == 0 && G()->parameters().use_message_db && reply_markup == nullptr) { + StopPollLogEvent log_event{poll_id, full_message_id}; + log_event_id = + binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::StopPoll, get_log_event_storer(log_event)); } bool is_inserted = being_closed_polls_.insert(poll_id).second; CHECK(is_inserted); - auto new_promise = get_erase_logevent_promise(logevent_id, std::move(promise)); + auto new_promise = get_erase_log_event_promise(log_event_id, std::move(promise)); send_closure(td_->create_net_actor(std::move(new_promise)), &StopPollActor::send, full_message_id, std::move(reply_markup)); @@ -1678,7 +1678,7 @@ void PollManager::on_binlog_events(vector &&events) { break; } default: - LOG(FATAL) << "Unsupported logevent type " << event.type_; + LOG(FATAL) << "Unsupported log event type " << event.type_; } } } diff --git a/td/telegram/PollManager.h b/td/telegram/PollManager.h index 205e701c4..6d8c63ff7 100644 --- a/td/telegram/PollManager.h +++ b/td/telegram/PollManager.h @@ -181,7 +181,7 @@ class PollManager : public Actor { void on_get_poll_results(PollId poll_id, uint64 generation, Result> result); - void do_set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector &&options, uint64 logevent_id, + void do_set_poll_answer(PollId poll_id, FullMessageId full_message_id, vector &&options, uint64 log_event_id, Promise &&promise); void on_set_poll_answer(PollId poll_id, uint64 generation, Result> &&result); @@ -196,7 +196,7 @@ class PollManager : public Actor { Result> &&result); void do_stop_poll(PollId poll_id, FullMessageId full_message_id, unique_ptr &&reply_markup, - uint64 logevent_id, Promise &&promise); + uint64 log_event_id, Promise &&promise); MultiTimeout update_poll_timeout_{"UpdatePollTimeout"}; MultiTimeout close_poll_timeout_{"ClosePollTimeout"}; @@ -211,7 +211,7 @@ class PollManager : public Actor { vector options_; vector> promises_; uint64 generation_ = 0; - uint64 logevent_id_ = 0; + uint64 log_event_id_ = 0; NetQueryRef query_ref_; }; std::unordered_map pending_answers_; diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 4310a2b2f..07d6247cc 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -96,11 +96,11 @@ void SecretChatActor::create_chat(int32 user_id, int64 user_access_hash, int32 r return; } - auto event = make_unique(); + auto event = make_unique(); event->user_id = user_id; event->user_access_hash = user_access_hash; event->random_id = random_id; - event->set_logevent_id(binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event))); + event->set_log_event_id(binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event))); do_create_chat_impl(std::move(event)); promise.set_value(SecretChatId(random_id)); loop(); @@ -139,18 +139,18 @@ void SecretChatActor::on_result_resendable(NetQueryPtr net_query, Promise event) { +void SecretChatActor::replay_close_chat(unique_ptr event) { do_close_chat_impl(std::move(event)); } -void SecretChatActor::replay_create_chat(unique_ptr event) { +void SecretChatActor::replay_create_chat(unique_ptr event) { if (close_flag_) { return; } do_create_chat_impl(std::move(event)); } -void SecretChatActor::add_inbound_message(unique_ptr message) { +void SecretChatActor::add_inbound_message(unique_ptr message) { SCOPE_EXIT { if (message) { message->promise.set_value(Unit()); @@ -167,7 +167,7 @@ void SecretChatActor::add_inbound_message(unique_ptr message) { +void SecretChatActor::replay_inbound_message(unique_ptr message) { if (close_flag_) { return; } @@ -190,7 +190,7 @@ void SecretChatActor::replay_inbound_message(unique_ptr message) { +void SecretChatActor::replay_outbound_message(unique_ptr message) { if (close_flag_) { return; } @@ -331,10 +331,10 @@ void SecretChatActor::send_message_impl(tl_object_ptrsecond, std::move(promise)); } - auto binlog_event = make_unique(); + auto binlog_event = make_unique(); binlog_event->chat_id = auth_state_.id; binlog_event->random_id = random_id; - binlog_event->file = logevent::EncryptedInputFile::from_input_encrypted_file(file); + binlog_event->file = log_event::EncryptedInputFile::from_input_encrypted_file(file); binlog_event->message_id = seq_no_state_.message_id + 1; binlog_event->my_in_seq_no = seq_no_state_.my_in_seq_no; binlog_event->my_out_seq_no = seq_no_state_.my_out_seq_no + 1; @@ -719,23 +719,23 @@ void SecretChatActor::cancel_chat(Promise<> promise) { } close_flag_ = true; - std::vector to_delete; + std::vector to_delete; outbound_message_states_.for_each( - [&](auto state_id, auto &state) { to_delete.push_back(state.message->logevent_id()); }); - inbound_message_states_.for_each([&](auto state_id, auto &state) { to_delete.push_back(state.logevent_id); }); + [&](auto state_id, auto &state) { to_delete.push_back(state.message->log_event_id()); }); + inbound_message_states_.for_each([&](auto state_id, auto &state) { to_delete.push_back(state.log_event_id); }); // TODO: It must be a transaction for (auto id : to_delete) { binlog_erase(context_->binlog(), id); } - if (create_logevent_id_ != 0) { - binlog_erase(context_->binlog(), create_logevent_id_); - create_logevent_id_ = 0; + if (create_log_event_id_ != 0) { + binlog_erase(context_->binlog(), create_log_event_id_); + create_log_event_id_ = 0; } - auto event = make_unique(); + auto event = make_unique(); event->chat_id = auth_state_.id; - event->set_logevent_id(binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event))); + event->set_log_event_id(binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*event))); auto on_sync = PromiseCreator::lambda( [actor_id = actor_id(this), event = std::move(event), promise = std::move(promise)](Result result) mutable { @@ -752,9 +752,9 @@ void SecretChatActor::cancel_chat(Promise<> promise) { yield(); } -void SecretChatActor::do_close_chat_impl(unique_ptr event) { +void SecretChatActor::do_close_chat_impl(unique_ptr event) { close_flag_ = true; - close_logevent_id_ = event->logevent_id(); + close_log_event_id_ = event->log_event_id(); LOG(INFO) << "Send messages.discardEncryption"; auth_state_.state = State::Closed; context_->secret_chat_db()->set_value(auth_state_); @@ -768,10 +768,10 @@ void SecretChatActor::do_close_chat_impl(unique_ptr e context_->send_net_query(std::move(query), actor_shared(this), true); } -void SecretChatActor::do_create_chat_impl(unique_ptr event) { +void SecretChatActor::do_create_chat_impl(unique_ptr event) { LOG(INFO) << *event; CHECK(event->random_id == auth_state_.id); - create_logevent_id_ = event->logevent_id(); + create_log_event_id_ = event->log_event_id(); if (auth_state_.state == State::Empty) { auth_state_.user_id = event->user_id; @@ -784,19 +784,19 @@ void SecretChatActor::do_create_chat_impl(unique_ptr } else if (auth_state_.state == State::SendRequest) { } else if (auth_state_.state == State::WaitRequestResponse) { } else { - binlog_erase(context_->binlog(), create_logevent_id_); - create_logevent_id_ = 0; + binlog_erase(context_->binlog(), create_log_event_id_); + create_log_event_id_ = 0; } } void SecretChatActor::on_discard_encryption_result(NetQueryPtr result) { CHECK(close_flag_); - CHECK(close_logevent_id_ != 0); + CHECK(close_log_event_id_ != 0); if (context_->close_flag()) { return; } LOG(INFO) << "Got result for messages.discardEncryption"; context_->secret_chat_db()->erase_value(auth_state_); - binlog_erase(context_->binlog(), close_logevent_id_); + binlog_erase(context_->binlog(), close_log_event_id_); // skip flush stop(); } @@ -877,7 +877,7 @@ Result> SecretChatActor::decrypt(BufferSl } } -Status SecretChatActor::do_inbound_message_encrypted(unique_ptr message) { +Status SecretChatActor::do_inbound_message_encrypted(unique_ptr message) { SCOPE_EXIT { if (message) { message->promise.set_value(Unit()); @@ -970,7 +970,7 @@ Status SecretChatActor::check_seq_no(int in_seq_no, int out_seq_no, int32 his_la return Status::OK(); } -Status SecretChatActor::do_inbound_message_decrypted_unchecked(unique_ptr message) { +Status SecretChatActor::do_inbound_message_decrypted_unchecked(unique_ptr message) { SCOPE_EXIT { CHECK(message == nullptr || !message->promise); }; @@ -979,9 +979,9 @@ Status SecretChatActor::do_inbound_message_decrypted_unchecked(unique_ptrhis_layer()); if (status.is_error() && status.code() != 2 /* not gap found */) { message->promise.set_value(Unit()); - if (message->logevent_id()) { - LOG(INFO) << "Erase binlog event: " << tag("logevent_id", message->logevent_id()); - binlog_erase(context_->binlog(), message->logevent_id()); + if (message->log_event_id()) { + LOG(INFO) << "Erase binlog event: " << tag("log_event_id", message->log_event_id()); + binlog_erase(context_->binlog(), message->log_event_id()); } auto warning_message = PSTRING() << status << tag("seq_no_state_.my_in_seq_no", seq_no_state_.my_in_seq_no) << tag("seq_no_state_.my_out_seq_no", seq_no_state_.my_out_seq_no) @@ -1049,7 +1049,7 @@ Status SecretChatActor::do_inbound_message_decrypted_unchecked(unique_ptr binlog_event, +void SecretChatActor::do_outbound_message_impl(unique_ptr binlog_event, Promise<> promise) { binlog_event->crc = crc64(binlog_event->encrypted_message.as_slice()); LOG(INFO) << "Do outbound message: " << *binlog_event << tag("crc", binlog_event->crc); @@ -1064,13 +1064,13 @@ void SecretChatActor::do_outbound_message_impl(unique_ptr Save logevent. [save_logevent] - // 2. [save_logevent] => Save SeqNoState [save_changes] - // 3. [save_logevent] => Send NetQuery [send_message] + // 1. [] => Save log_event. [save_log_event] + // 2. [save_log_event] => Save SeqNoState [save_changes] + // 3. [save_log_event] => Send NetQuery [send_message] // Note: we have to force binlog to flush // 4.0 [send_message]:Fail => rewrite - // 4. [save_changes; send_message] => Mark logevent as sent [rewrite_logevent] - // 5. [save_changes; send_message; ack] => [remove_logevent] + // 4. [save_changes; send_message] => Mark log event as sent [rewrite_log_event] + // 5. [save_changes; send_message; ack] => [remove_log_event] auto message = state->message.get(); @@ -1112,20 +1112,20 @@ void SecretChatActor::do_outbound_message_impl(unique_ptr [send_message; save_changes] - auto save_logevent_finish = PromiseCreator::join(std::move(send_message_start), std::move(save_changes_start)); + // save_log_event => [send_message; save_changes] + auto save_log_event_finish = PromiseCreator::join(std::move(send_message_start), std::move(save_changes_start)); - auto logevent_id = state->message->logevent_id(); - if (logevent_id == 0) { - logevent_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*state->message)); - LOG(INFO) << "Outbound secret message [save_logevent] start " << tag("logevent_id", logevent_id); - context_->binlog()->force_sync(std::move(save_logevent_finish)); - state->message->set_logevent_id(logevent_id); + auto log_event_id = state->message->log_event_id(); + if (log_event_id == 0) { + log_event_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*state->message)); + LOG(INFO) << "Outbound secret message [save_log_event] start " << tag("log_event_id", log_event_id); + context_->binlog()->force_sync(std::move(save_log_event_finish)); + state->message->set_log_event_id(log_event_id); } else { - LOG(INFO) << "Outbound secret message [save_logevent] skip " << tag("logevent_id", logevent_id); - save_logevent_finish.set_value(Unit()); + LOG(INFO) << "Outbound secret message [save_log_event] skip " << tag("log_event_id", log_event_id); + save_log_event_finish.set_value(Unit()); } - promise.set_value(Unit()); // logevent was sent to binlog; + promise.set_value(Unit()); // log event was sent to binlog } void SecretChatActor::on_his_in_seq_no_updated() { @@ -1197,66 +1197,66 @@ void SecretChatActor::update_seq_no_state(const T &new_seq_no_state) { return on_seq_no_state_changed(); } -void SecretChatActor::do_inbound_message_decrypted_pending(unique_ptr message) { - // Just save logevent if necessary - auto logevent_id = message->logevent_id(); +void SecretChatActor::do_inbound_message_decrypted_pending(unique_ptr message) { + // Just save log event if necessary + auto log_event_id = message->log_event_id(); // qts auto qts_promise = std::move(message->promise); - if (logevent_id == 0) { + if (log_event_id == 0) { message->is_pending = true; - message->set_logevent_id(binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message), - std::move(qts_promise))); - LOG(INFO) << "Inbound PENDING secret message [save_logevent] start (do not expect finish) " - << tag("logevent_id", message->logevent_id()); + message->set_log_event_id(binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, + create_storer(*message), std::move(qts_promise))); + LOG(INFO) << "Inbound PENDING secret message [save_log_event] start (do not expect finish) " + << tag("log_event_id", message->log_event_id()); } else { - LOG(INFO) << "Inbound PENDING secret message [save_logevent] skip " << tag("logevent_id", logevent_id); + LOG(INFO) << "Inbound PENDING secret message [save_log_event] skip " << tag("log_event_id", log_event_id); CHECK(!qts_promise); } - LOG(INFO) << "Inbound PENDING secret message start " << tag("logevent_id", logevent_id) << tag("message", *message); + LOG(INFO) << "Inbound PENDING secret message start " << tag("log_event_id", log_event_id) << tag("message", *message); auto seq_no = message->decrypted_message_layer->out_seq_no_ / 2; pending_inbound_messages_[seq_no] = std::move(message); } -Status SecretChatActor::do_inbound_message_decrypted(unique_ptr message) { +Status SecretChatActor::do_inbound_message_decrypted(unique_ptr message) { // InboundSecretMessage // - // 1. [] => Add logevent. [save_logevent] - // 2. [save_logevent] => Save SeqNoState [save_changes] - // 3. [save_logevent] => Add message to MessageManager [save_message] - // Note: if we are able to add message by random_id, we may not wait for (logevent). Otherwise we should force + // 1. [] => Add log event. [save_log_event] + // 2. [save_log_event] => Save SeqNoState [save_changes] + // 3. [save_log_event] => Add message to MessageManager [save_message] + // Note: if we are able to add message by random_id, we may not wait for (log event). Otherwise we should force // binlog flush. - // 4. [save_logevent] => Update qts [qts] - // 5. [save_changes; save_message; ?qts) => Remove logevent [remove_logevent] + // 4. [save_log_event] => Update qts [qts] + // 5. [save_changes; save_message; ?qts) => Remove log event [remove_log_event] // Note: It is easier not to wait for qts. In the worst case old update will be handled again after restart. auto state_id = inbound_message_states_.create(); InboundMessageState &state = *inbound_message_states_.get(state_id); - // save logevent - auto logevent_id = message->logevent_id(); + // save log event + auto log_event_id = message->log_event_id(); bool need_sync = false; - if (logevent_id == 0) { - logevent_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message)); - LOG(INFO) << "Inbound secret message [save_logevent] start " << tag("logevent_id", logevent_id); + if (log_event_id == 0) { + log_event_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message)); + LOG(INFO) << "Inbound secret message [save_log_event] start " << tag("log_event_id", log_event_id); need_sync = true; } else { if (message->is_pending) { message->is_pending = false; - auto old_logevent_id = logevent_id; - logevent_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message)); - binlog_erase(context_->binlog(), old_logevent_id); - LOG(INFO) << "Inbound secret message [save_logevent] rewrite (after pending state) " - << tag("logevent_id", logevent_id) << tag("old_logevent_id", old_logevent_id); + auto old_log_event_id = log_event_id; + log_event_id = binlog_add(context_->binlog(), LogEvent::HandlerType::SecretChats, create_storer(*message)); + binlog_erase(context_->binlog(), old_log_event_id); + LOG(INFO) << "Inbound secret message [save_log_event] rewrite (after pending state) " + << tag("log_event_id", log_event_id) << tag("old_log_event_id", old_log_event_id); need_sync = true; } else { - LOG(INFO) << "Inbound secret message [save_logevent] skip " << tag("logevent_id", logevent_id); + LOG(INFO) << "Inbound secret message [save_log_event] skip " << tag("log_event_id", log_event_id); } } - LOG(INFO) << "Inbound secret message start " << tag("logevent_id", logevent_id) << tag("message", *message); - state.logevent_id = logevent_id; + LOG(INFO) << "Inbound secret message start " << tag("log_event_id", log_event_id) << tag("message", *message); + state.log_event_id = log_event_id; // save_message auto save_message_finish = PromiseCreator::lambda([actor_id = actor_id(this), state_id](Result<> result) { @@ -1305,7 +1305,7 @@ Status SecretChatActor::do_inbound_message_decrypted(unique_ptrdecrypted_message_layer->message_->get_id() == secret_api::decryptedMessage::ID) { auto decrypted_message = @@ -1319,7 +1319,7 @@ Status SecretChatActor::do_inbound_message_decrypted(unique_ptraction_); switch (action->get_id()) { case secret_api::decryptedMessageActionDeleteMessages::ID: - // Corresponding logevent won't be deleted before promise returned by add_changes is set. + // Corresponding log event won't be deleted before promise returned by add_changes is set. context_->on_delete_messages( static_cast(*action).random_ids_, std::move(save_message_finish)); @@ -1385,13 +1385,13 @@ decryptedMessageActionNoop#a82fdd63 = DecryptedMessageAction; }); auto save_changes_start = add_changes(std::move(save_changes_finish)); - // save_logevent - auto save_logevent_finish = PromiseCreator::join(std::move(save_changes_start), std::move(qts_promise)); + // save_log_event + auto save_log_event_finish = PromiseCreator::join(std::move(save_changes_start), std::move(qts_promise)); if (need_sync) { // TODO: lazy sync is enough - context_->binlog()->force_sync(std::move(save_logevent_finish)); + context_->binlog()->force_sync(std::move(save_log_event_finish)); } else { - save_logevent_finish.set_value(Unit()); + save_log_event_finish.set_value(Unit()); } return Status::OK(); } @@ -1433,7 +1433,7 @@ void SecretChatActor::on_inbound_save_message_finish(uint64 state_id) { } auto *state = inbound_message_states_.get(state_id); CHECK(state); - LOG(INFO) << "Inbound message [save_message] finish " << tag("logevent_id", state->logevent_id); + LOG(INFO) << "Inbound message [save_message] finish " << tag("log_event_id", state->log_event_id); state->save_message_finish = true; inbound_loop(state, state_id); } @@ -1444,7 +1444,7 @@ void SecretChatActor::on_inbound_save_changes_finish(uint64 state_id) { } auto *state = inbound_message_states_.get(state_id); CHECK(state); - LOG(INFO) << "Inbound message [save_changes] finish " << tag("logevent_id", state->logevent_id); + LOG(INFO) << "Inbound message [save_changes] finish " << tag("log_event_id", state->log_event_id); state->save_changes_finish = true; inbound_loop(state, state_id); } @@ -1456,13 +1456,13 @@ void SecretChatActor::inbound_loop(InboundMessageState *state, uint64 state_id) if (!state->save_changes_finish || !state->save_message_finish) { return; } - LOG(INFO) << "Inbound message [remove_logevent] start " << tag("logevent_id", state->logevent_id); - binlog_erase(context_->binlog(), state->logevent_id); + LOG(INFO) << "Inbound message [remove_log_event] start " << tag("log_event_id", state->log_event_id); + binlog_erase(context_->binlog(), state->log_event_id); inbound_message_states_.erase(state_id); } -NetQueryPtr SecretChatActor::create_net_query(const logevent::OutboundSecretMessage &message) { +NetQueryPtr SecretChatActor::create_net_query(const log_event::OutboundSecretMessage &message) { NetQueryPtr query; if (message.need_notify_user) { CHECK(message.file.empty()); @@ -1510,14 +1510,14 @@ void SecretChatActor::on_outbound_send_message_start(uint64 state_id) { auto *message = state->message.get(); if (!message->is_sent) { - LOG(INFO) << "Outbound message [send_message] start " << tag("logevent_id", state->message->logevent_id()); + LOG(INFO) << "Outbound message [send_message] start " << tag("log_event_id", state->message->log_event_id()); auto query = create_net_query(*message); state->net_query_id = query->id(); state->net_query_ref = query.get_weak(); state->net_query_may_fail = state->message->is_rewritable; context_->send_net_query(std::move(query), actor_shared(this, state_id), true); } else { - LOG(INFO) << "Outbound message [send_message] start dummy " << tag("logevent_id", state->message->logevent_id()); + LOG(INFO) << "Outbound message [send_message] start dummy " << tag("log_event_id", state->message->log_event_id()); on_outbound_send_message_finish(state_id); } } @@ -1532,10 +1532,10 @@ void SecretChatActor::outbound_resend(uint64 state_id) { state->message->is_sent = false; state->net_query_id = 0; state->net_query_ref = NetQueryRef(); - LOG(INFO) << "Outbound message [resend] " << tag("logevent_id", state->message->logevent_id()) + LOG(INFO) << "Outbound message [resend] " << tag("log_event_id", state->message->log_event_id()) << tag("state_id", state_id); - binlog_rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats, + binlog_rewrite(context_->binlog(), state->message->log_event_id(), LogEvent::HandlerType::SecretChats, create_storer(*state->message)); auto send_message_start = PromiseCreator::lambda([actor_id = actor_id(this), state_id](Result<> result) { if (result.is_ok()) { @@ -1574,8 +1574,8 @@ Status SecretChatActor::outbound_rewrite_with_empty(uint64 state_id) { state->message->is_external = false; state->message->need_notify_user = false; state->message->is_silent = true; - state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(nullptr); - binlog_rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats, + state->message->file = log_event::EncryptedInputFile::from_input_encrypted_file(nullptr); + binlog_rewrite(context_->binlog(), state->message->log_event_id(), LogEvent::HandlerType::SecretChats, create_storer(*state->message)); return Status::OK(); } @@ -1593,7 +1593,7 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise } CHECK(state); if (state->net_query_id != query->id()) { - LOG(INFO) << "Ignore old net query result " << tag("logevent_id", state->message->logevent_id()) + LOG(INFO) << "Ignore old net query result " << tag("log_event_id", state->message->log_event_id()) << tag("query_id", query->id()) << tag("state_query_id", state->net_query_id) << query; query->clear(); return; @@ -1620,7 +1620,7 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise if (state->message->is_external) { LOG(INFO) << "Outbound secret message [send_message] failed, rewrite it with dummy " - << tag("logevent_id", state->message->logevent_id()) << tag("error", error); + << tag("log_event_id", state->message->log_event_id()) << tag("error", error); state->send_result_ = [this, random_id = state->message->random_id, error_code = error.code(), error_message = error.message()](Promise<> promise) { this->context_->on_send_message_error(random_id, Status::Error(error_code, error_message), std::move(promise)); @@ -1629,7 +1629,7 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise } else { // Just resend. LOG(INFO) << "Outbound secret message [send_message] failed, resend it " - << tag("logevent_id", state->message->logevent_id()) << tag("error", error); + << tag("log_event_id", state->message->log_event_id()) << tag("error", error); send_message_error_promise.set_value(Unit()); } return; @@ -1666,14 +1666,14 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise telegram_api::downcast_call( *sent->file_, overloaded( [&](telegram_api::encryptedFileEmpty &) { - state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file( + state->message->file = log_event::EncryptedInputFile::from_input_encrypted_file( telegram_api::inputEncryptedFileEmpty()); get_file = [] { return telegram_api::make_object(); }; }, [&](telegram_api::encryptedFile &file) { - state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file( + state->message->file = log_event::EncryptedInputFile::from_input_encrypted_file( telegram_api::inputEncryptedFile(file.id_, file.access_hash_)); get_file = [id = file.id_, access_hash = file.access_hash_, size = file.size_, dc_id = file.dc_id_, key_fingerprint = file.key_fingerprint_] { @@ -1758,7 +1758,7 @@ void SecretChatActor::on_outbound_send_message_finish(uint64 state_id) { if (!state) { return; } - LOG(INFO) << "Outbound secret message [send_message] finish " << tag("logevent_id", state->message->logevent_id()); + LOG(INFO) << "Outbound secret message [send_message] finish " << tag("log_event_id", state->message->log_event_id()); state->send_message_finish_flag = true; state->outer_send_message_finish.set_value(Unit()); @@ -1771,7 +1771,7 @@ void SecretChatActor::on_outbound_save_changes_finish(uint64 state_id) { } auto *state = outbound_message_states_.get(state_id); CHECK(state); - LOG(INFO) << "Outbound secret message [save_changes] finish " << tag("logevent_id", state->message->logevent_id()); + LOG(INFO) << "Outbound secret message [save_changes] finish " << tag("log_event_id", state->message->log_event_id()); state->save_changes_finish_flag = true; outbound_loop(state, state_id); } @@ -1782,7 +1782,7 @@ void SecretChatActor::on_outbound_ack(uint64 state_id) { } auto *state = outbound_message_states_.get(state_id); CHECK(state); - LOG(INFO) << "Outbound secret message [ack] finish " << tag("logevent_id", state->message->logevent_id()); + LOG(INFO) << "Outbound secret message [ack] finish " << tag("log_event_id", state->message->log_event_id()); state->ack_flag = true; outbound_loop(state, state_id); } @@ -1794,7 +1794,7 @@ void SecretChatActor::on_outbound_outer_send_message_promise(uint64 state_id, Pr } auto *state = outbound_message_states_.get(state_id); CHECK(state); - LOG(INFO) << "Outbound secret message [TODO] " << tag("logevent_id", state->message->logevent_id()); + LOG(INFO) << "Outbound secret message [TODO] " << tag("log_event_id", state->message->log_event_id()); promise.set_value(Unit()); // Seems like this message is at least stored to binlog already if (state->send_result_) { state->send_result_({}); @@ -1809,20 +1809,20 @@ void SecretChatActor::outbound_loop(OutboundMessageState *state, uint64 state_id return; } if (state->save_changes_finish_flag /*&& state->send_message_finish_flag*/ && state->ack_flag) { - LOG(INFO) << "Outbound message [remove_logevent] start " << tag("logevent_id", state->message->logevent_id()); - binlog_erase(context_->binlog(), state->message->logevent_id()); + LOG(INFO) << "Outbound message [remove_log_event] start " << tag("log_event_id", state->message->log_event_id()); + binlog_erase(context_->binlog(), state->message->log_event_id()); random_id_to_outbound_message_state_token_.erase(state->message->random_id); - LOG(INFO) << "Outbound message finish (lazy) " << tag("logevent_id", state->message->logevent_id()); + LOG(INFO) << "Outbound message finish (lazy) " << tag("log_event_id", state->message->log_event_id()); outbound_message_states_.erase(state_id); return; } if (state->save_changes_finish_flag && state->send_message_finish_flag && - !state->message->is_sent) { // [rewrite_logevent] - LOG(INFO) << "Outbound message [rewrite_logevent] start " << tag("logevent_id", state->message->logevent_id()); + !state->message->is_sent) { // [rewrite_log_event] + LOG(INFO) << "Outbound message [rewrite_log_event] start " << tag("log_event_id", state->message->log_event_id()); state->message->is_sent = true; - binlog_rewrite(context_->binlog(), state->message->logevent_id(), LogEvent::HandlerType::SecretChats, + binlog_rewrite(context_->binlog(), state->message->log_event_id(), LogEvent::HandlerType::SecretChats, create_storer(*state->message)); } } @@ -1884,9 +1884,9 @@ Status SecretChatActor::on_update_chat(telegram_api::encryptedChat &update) { return Status::Error("Key fingerprint mismatch"); } auth_state_.state = State::Ready; - if (create_logevent_id_ != 0) { - binlog_erase(context_->binlog(), create_logevent_id_); - create_logevent_id_ = 0; + if (create_log_event_id_ != 0) { + binlog_erase(context_->binlog(), create_log_event_id_); + create_log_event_id_ = 0; } // NB: order is important @@ -2044,7 +2044,7 @@ void SecretChatActor::on_outbound_action(secret_api::decryptedMessageActionReadM // TODO } void SecretChatActor::on_outbound_action(secret_api::decryptedMessageActionDeleteMessages &delete_messages) { - // Corresponding logevent won't be deleted before promise returned by add_changes is set. + // Corresponding log event won't be deleted before promise returned by add_changes is set. on_delete_messages(delete_messages.random_ids_).ensure(); } void SecretChatActor::on_outbound_action(secret_api::decryptedMessageActionScreenshotMessages &screenshot) { diff --git a/td/telegram/SecretChatActor.h b/td/telegram/SecretChatActor.h index f873db2cd..091dd4102 100644 --- a/td/telegram/SecretChatActor.h +++ b/td/telegram/SecretChatActor.h @@ -119,10 +119,10 @@ class SecretChatActor : public NetQueryCallback { // Inbound messages // Logevent is created by SecretChatsManager, because it must contain qts - void add_inbound_message(unique_ptr message); + void add_inbound_message(unique_ptr message); // Outbound messages - // Promise will be set just after corresponding logevent will be SENT to binlog. + // Promise will be set just after corresponding log event will be SENT to binlog. void send_message(tl_object_ptr message, tl_object_ptr file, Promise<> promise); void send_message_action(tl_object_ptr action); @@ -136,10 +136,10 @@ class SecretChatActor : public NetQueryCallback { void send_set_ttl_message(int32 ttl, int64 random_id, Promise<> promise); // Binlog replay interface - void replay_inbound_message(unique_ptr message); - void replay_outbound_message(unique_ptr message); - void replay_close_chat(unique_ptr event); - void replay_create_chat(unique_ptr event); + void replay_inbound_message(unique_ptr message); + void replay_outbound_message(unique_ptr message); + void replay_close_chat(unique_ptr event); + void replay_create_chat(unique_ptr event); void binlog_replay_finish(); private: @@ -461,9 +461,9 @@ class SecretChatActor : public NetQueryCallback { bool binlog_replay_finish_flag_ = false; bool close_flag_ = false; - LogEvent::Id close_logevent_id_ = 0; + LogEvent::Id close_log_event_id_ = 0; - LogEvent::Id create_logevent_id_ = 0; + LogEvent::Id create_log_event_id_ = 0; enum class QueryType : uint8 { DhConfig, EncryptedChat, Message, Ignore, DiscardEncryption, ReadHistory }; @@ -560,19 +560,19 @@ class SecretChatActor : public NetQueryCallback { struct InboundMessageState { bool save_changes_finish = false; bool save_message_finish = false; - LogEvent::Id logevent_id = 0; + LogEvent::Id log_event_id = 0; int32 message_id; }; Container inbound_message_states_; - std::map> pending_inbound_messages_; + std::map> pending_inbound_messages_; Result> decrypt(BufferSlice &encrypted_message); - Status do_inbound_message_encrypted(unique_ptr message); - Status do_inbound_message_decrypted_unchecked(unique_ptr message); - Status do_inbound_message_decrypted(unique_ptr message); - void do_inbound_message_decrypted_pending(unique_ptr message); + Status do_inbound_message_encrypted(unique_ptr message); + Status do_inbound_message_decrypted_unchecked(unique_ptr message); + Status do_inbound_message_decrypted(unique_ptr message); + void do_inbound_message_decrypted_pending(unique_ptr message); void on_inbound_save_message_finish(uint64 state_id); void on_inbound_save_changes_finish(uint64 state_id); @@ -580,7 +580,7 @@ class SecretChatActor : public NetQueryCallback { // OutboundMessage struct OutboundMessageState { - unique_ptr message; + unique_ptr message; Promise<> outer_send_message_finish; Promise<> send_message_finish; @@ -618,11 +618,11 @@ class SecretChatActor : public NetQueryCallback { void send_message_impl(tl_object_ptr message, tl_object_ptr file, int32 flags, Promise<> promise); - void do_outbound_message_impl(unique_ptr, Promise<> promise); + void do_outbound_message_impl(unique_ptr, Promise<> promise); Result create_encrypted_message(int32 layer, int32 my_in_seq_no, int32 my_out_seq_no, tl_object_ptr &message); - NetQueryPtr create_net_query(const logevent::OutboundSecretMessage &message); + NetQueryPtr create_net_query(const log_event::OutboundSecretMessage &message); void outbound_resend(uint64 state_id); Status outbound_rewrite_with_empty(uint64 state_id); @@ -637,7 +637,7 @@ class SecretChatActor : public NetQueryCallback { // DiscardEncryption void on_fatal_error(Status status); - void do_close_chat_impl(unique_ptr event); + void do_close_chat_impl(unique_ptr event); void on_discard_encryption_result(NetQueryPtr result); // Other @@ -693,7 +693,7 @@ class SecretChatActor : public NetQueryCallback { void on_dh_config(telegram_api::messages_dhConfigNotModified &dh_not_modified); void on_dh_config(telegram_api::messages_dhConfig &dh); - void do_create_chat_impl(unique_ptr event); + void do_create_chat_impl(unique_ptr event); SecretChatId get_secret_chat_id() { return SecretChatId(auth_state_.id); diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index 89ec4c399..6c63fb68f 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -188,7 +188,7 @@ void SecretChatsManager::on_new_message(tl_object_ptr(); + auto event = make_unique(); event->promise = std::move(promise); downcast_call(*message_ptr, [&](auto &x) { event->chat_id = x.chat_id_; @@ -217,26 +217,26 @@ void SecretChatsManager::replay_binlog_event(BinlogEvent &&binlog_event) { binlog_erase(G()->td_db()->get_binlog(), binlog_event.id_); return; } - auto r_message = logevent::SecretChatEvent::from_buffer_slice(binlog_event.data_as_buffer_slice()); + auto r_message = log_event::SecretChatEvent::from_buffer_slice(binlog_event.data_as_buffer_slice()); LOG_IF(FATAL, r_message.is_error()) << "Failed to deserialize event: " << r_message.error(); auto message = r_message.move_as_ok(); - message->set_logevent_id(binlog_event.id_); + message->set_log_event_id(binlog_event.id_); LOG(INFO) << "Process binlog event " << *message; switch (message->get_type()) { - case logevent::SecretChatEvent::Type::InboundSecretMessage: - return replay_inbound_message( - unique_ptr(static_cast(message.release()))); - case logevent::SecretChatEvent::Type::OutboundSecretMessage: - return replay_outbound_message(unique_ptr( - static_cast(message.release()))); - case logevent::SecretChatEvent::Type::CloseSecretChat: + case log_event::SecretChatEvent::Type::InboundSecretMessage: + return replay_inbound_message(unique_ptr( + static_cast(message.release()))); + case log_event::SecretChatEvent::Type::OutboundSecretMessage: + return replay_outbound_message(unique_ptr( + static_cast(message.release()))); + case log_event::SecretChatEvent::Type::CloseSecretChat: return replay_close_chat( - unique_ptr(static_cast(message.release()))); - case logevent::SecretChatEvent::Type::CreateSecretChat: + unique_ptr(static_cast(message.release()))); + case log_event::SecretChatEvent::Type::CreateSecretChat: return replay_create_chat( - unique_ptr(static_cast(message.release()))); + unique_ptr(static_cast(message.release()))); } - LOG(FATAL) << "Unknown logevent type " << tag("type", format::as_hex(static_cast(message->get_type()))); + LOG(FATAL) << "Unknown log event type " << tag("type", format::as_hex(static_cast(message->get_type()))); } void SecretChatsManager::binlog_replay_finish() { @@ -246,34 +246,34 @@ void SecretChatsManager::binlog_replay_finish() { } } -void SecretChatsManager::replay_inbound_message(unique_ptr message) { +void SecretChatsManager::replay_inbound_message(unique_ptr message) { LOG(INFO) << "Replay inbound secret message in chat " << message->chat_id; auto actor = get_chat_actor(message->chat_id); send_closure_later(actor, &SecretChatActor::replay_inbound_message, std::move(message)); } -void SecretChatsManager::add_inbound_message(unique_ptr message) { +void SecretChatsManager::add_inbound_message(unique_ptr message) { LOG(INFO) << "Process inbound secret message in chat " << message->chat_id; auto actor = get_chat_actor(message->chat_id); send_closure(actor, &SecretChatActor::add_inbound_message, std::move(message)); } -void SecretChatsManager::replay_close_chat(unique_ptr message) { +void SecretChatsManager::replay_close_chat(unique_ptr message) { LOG(INFO) << "Replay close secret chat " << message->chat_id; auto actor = get_chat_actor(message->chat_id); send_closure_later(actor, &SecretChatActor::replay_close_chat, std::move(message)); } -void SecretChatsManager::replay_create_chat(unique_ptr message) { +void SecretChatsManager::replay_create_chat(unique_ptr message) { LOG(INFO) << "Replay create secret chat " << message->random_id; auto actor = create_chat_actor(message->random_id); send_closure_later(actor, &SecretChatActor::replay_create_chat, std::move(message)); } -void SecretChatsManager::replay_outbound_message(unique_ptr message) { +void SecretChatsManager::replay_outbound_message(unique_ptr message) { LOG(INFO) << "Replay outbound secret message in chat " << message->chat_id; auto actor = get_chat_actor(message->chat_id); diff --git a/td/telegram/SecretChatsManager.h b/td/telegram/SecretChatsManager.h index 06bf1b47a..43cbb9177 100644 --- a/td/telegram/SecretChatsManager.h +++ b/td/telegram/SecretChatsManager.h @@ -64,11 +64,11 @@ class SecretChatsManager : public Actor { void flush_pending_chat_updates(); void do_update_chat(tl_object_ptr update); - void replay_inbound_message(unique_ptr message); - void add_inbound_message(unique_ptr message); - void replay_outbound_message(unique_ptr message); - void replay_close_chat(unique_ptr message); - void replay_create_chat(unique_ptr message); + void replay_inbound_message(unique_ptr message); + void add_inbound_message(unique_ptr message); + void replay_outbound_message(unique_ptr message); + void replay_close_chat(unique_ptr message); + void replay_create_chat(unique_ptr message); unique_ptr make_secret_chat_context(int32 id); ActorId get_chat_actor(int32 id); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index b95007460..90d537569 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4198,7 +4198,7 @@ Status Td::init(DbKey key) { // for each Actor. // // 2. An actor must not make some decisions before all binlog events are processed. - // For example, SecretChatActor must not send RequestKey, before it receives logevent with RequestKey and understands + // For example, SecretChatActor must not send RequestKey, before it receives log event with RequestKey and understands // that RequestKey was already sent. // // 3. During replay of binlog some queries may be sent to other actors. They shouldn't process such events before all diff --git a/td/telegram/TdDb.cpp b/td/telegram/TdDb.cpp index 981d26a9f..8f33b9e62 100644 --- a/td/telegram/TdDb.cpp +++ b/td/telegram/TdDb.cpp @@ -127,7 +127,7 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue &binlog_p config_pmc.external_init_handle(event); break; default: - LOG(FATAL) << "Unsupported logevent type " << event.type_; + LOG(FATAL) << "Unsupported log event type " << event.type_; } }; diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 2f3681525..1ec469a17 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -230,7 +230,7 @@ class WebPagesManager::WebPage { FileSourceId file_source_id; - mutable uint64 logevent_id = 0; + mutable uint64 log_event_id = 0; template void store(StorerT &storer) const { @@ -425,10 +425,10 @@ WebPageId WebPagesManager::on_get_web_page(tl_object_ptr LOG(INFO) << "Got empty " << web_page_id; const WebPage *web_page_to_delete = get_web_page(web_page_id); if (web_page_to_delete != nullptr) { - if (web_page_to_delete->logevent_id != 0) { + if (web_page_to_delete->log_event_id != 0) { LOG(INFO) << "Erase " << web_page_id << " from binlog"; - binlog_erase(G()->td_db()->get_binlog(), web_page_to_delete->logevent_id); - web_page_to_delete->logevent_id = 0; + binlog_erase(G()->td_db()->get_binlog(), web_page_to_delete->log_event_id); + web_page_to_delete->log_event_id = 0; } if (web_page_to_delete->file_source_id.is_valid()) { td_->file_manager_->change_files_source(web_page_to_delete->file_source_id, @@ -551,7 +551,7 @@ void WebPagesManager::update_web_page(unique_ptr web_page, WebPageId we } old_instant_view = std::move(page->instant_view); - web_page->logevent_id = page->logevent_id; + web_page->log_event_id = page->log_event_id; } else { auto it = url_to_file_source_id_.find(web_page->url); if (it != url_to_file_source_id_.end()) { @@ -1504,12 +1504,12 @@ void WebPagesManager::save_web_page(const WebPage *web_page, WebPageId web_page_ CHECK(web_page != nullptr); if (!from_binlog) { - WebPageLogEvent logevent(web_page_id, web_page); - auto storer = get_log_event_storer(logevent); - if (web_page->logevent_id == 0) { - web_page->logevent_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::WebPages, storer); + WebPageLogEvent log_event(web_page_id, web_page); + auto storer = get_log_event_storer(log_event); + if (web_page->log_event_id == 0) { + web_page->log_event_id = binlog_add(G()->td_db()->get_binlog(), LogEvent::HandlerType::WebPages, storer); } else { - binlog_rewrite(G()->td_db()->get_binlog(), web_page->logevent_id, LogEvent::HandlerType::WebPages, storer); + binlog_rewrite(G()->td_db()->get_binlog(), web_page->log_event_id, LogEvent::HandlerType::WebPages, storer); } } @@ -1540,7 +1540,7 @@ void WebPagesManager::on_binlog_web_page_event(BinlogEvent &&event) { auto web_page = std::move(log_event.web_page_out); CHECK(web_page != nullptr); - web_page->logevent_id = event.id_; + web_page->log_event_id = event.id_; update_web_page(std::move(web_page), web_page_id, true, false); } @@ -1561,13 +1561,13 @@ void WebPagesManager::on_save_web_page_to_database(WebPageId web_page_id, bool s if (!success) { LOG(ERROR) << "Failed to save " << web_page_id << " to database"; - save_web_page(web_page, web_page_id, web_page->logevent_id != 0); + save_web_page(web_page, web_page_id, web_page->log_event_id != 0); } else { LOG(INFO) << "Successfully saved " << web_page_id << " to database"; - if (web_page->logevent_id != 0) { + if (web_page->log_event_id != 0) { LOG(INFO) << "Erase " << web_page_id << " from binlog"; - binlog_erase(G()->td_db()->get_binlog(), web_page->logevent_id); - web_page->logevent_id = 0; + binlog_erase(G()->td_db()->get_binlog(), web_page->log_event_id); + web_page->log_event_id = 0; } } } diff --git a/td/telegram/files/FileDb.cpp b/td/telegram/files/FileDb.cpp index e334095d0..6954f8679 100644 --- a/td/telegram/files/FileDb.cpp +++ b/td/telegram/files/FileDb.cpp @@ -278,7 +278,7 @@ class FileDb : public FileDbInterface { //LOG(DEBUG) << "By id " << id.get() << " found data " << format::as_hex_dump<4>(Slice(data_str)); //LOG(INFO) << attempt_count; - logevent::WithVersion parser(data_str); + log_event::WithVersion parser(data_str); parser.set_version(static_cast(Version::Initial)); FileData data; data.parse(parser, true); @@ -316,7 +316,7 @@ Status fix_file_remote_location_key_bug(SqliteDb &db) { CHECK(TlParser(key).fetch_int() == OLD_KEY_MAGIC); auto remote_str = PSTRING() << key.substr(4, 4) << Slice("\0\0\0\0") << key.substr(8); FullRemoteFileLocation remote; - logevent::WithVersion parser(remote_str); + log_event::WithVersion parser(remote_str); parser.set_version(static_cast(Version::Initial)); parse(remote, parser); parser.fetch_end(); diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 7b4573aab..5aa606d1d 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2873,7 +2873,7 @@ Result FileManager::from_persistent_id_v23(Slice binary, FileType file_t } auto decoded_binary = zero_decode(binary); FullRemoteFileLocation remote_location; - logevent::WithVersion parser(decoded_binary); + log_event::WithVersion parser(decoded_binary); parser.set_version(version); parse(remote_location, parser); parser.fetch_end(); diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index 5b84b31b1..8d16d5c37 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -58,7 +58,7 @@ void scan_db(CancellationToken &token, CallbackT &&callback) { if (value.substr(0, 2) == "@@") { return true; } - logevent::WithVersion parser(value); + log_event::WithVersion parser(value); FileData data; data.parse(parser, false); if (parser.get_status().is_error()) { diff --git a/td/telegram/logevent/LogEvent.h b/td/telegram/logevent/LogEvent.h index b2f076031..1d3cf8cba 100644 --- a/td/telegram/logevent/LogEvent.h +++ b/td/telegram/logevent/LogEvent.h @@ -25,7 +25,7 @@ #include namespace td { -namespace logevent { +namespace log_event { template class WithVersion : public ParentT { @@ -107,19 +107,19 @@ class LogEvent { using Id = uint64; - Id logevent_id() const { - return logevent_id_; + Id log_event_id() const { + return log_event_id_; } - void set_logevent_id(Id logevent_id) { - logevent_id_ = logevent_id; + void set_log_event_id(Id log_event_id) { + log_event_id_ = log_event_id; } virtual StringBuilder &print(StringBuilder &sb) const { - return sb << "[Logevent " << tag("id", logevent_id()) << "]"; + return sb << "[Logevent " << tag("id", log_event_id()) << "]"; } private: - Id logevent_id_{}; + Id log_event_id_{}; }; inline StringBuilder &operator<<(StringBuilder &sb, const LogEvent &log_event) { return log_event.print(sb); @@ -257,12 +257,12 @@ class LogEventStorerImpl : public Storer { const T &event_; }; -} // namespace logevent +} // namespace log_event -using LogEvent = logevent::LogEvent; -using LogEventParser = logevent::LogEventParser; -using LogEventStorerCalcLength = logevent::LogEventStorerCalcLength; -using LogEventStorerUnsafe = logevent::LogEventStorerUnsafe; +using LogEvent = log_event::LogEvent; +using LogEventParser = log_event::LogEventParser; +using LogEventStorerCalcLength = log_event::LogEventStorerCalcLength; +using LogEventStorerUnsafe = log_event::LogEventStorerUnsafe; template Status log_event_parse(T &data, Slice slice) TD_WARN_UNUSED_RESULT; @@ -295,8 +295,8 @@ BufferSlice log_event_store(const T &data) { } template -logevent::LogEventStorerImpl get_log_event_storer(const T &event) { - return logevent::LogEventStorerImpl(event); +log_event::LogEventStorerImpl get_log_event_storer(const T &event) { + return log_event::LogEventStorerImpl(event); } } // namespace td diff --git a/td/telegram/logevent/LogEventHelper.cpp b/td/telegram/logevent/LogEventHelper.cpp index 4b1a619a7..45e89c283 100644 --- a/td/telegram/logevent/LogEventHelper.cpp +++ b/td/telegram/logevent/LogEventHelper.cpp @@ -15,43 +15,41 @@ namespace td { -void add_log_event(LogeventIdWithGeneration &logevent_id, const Storer &storer, uint32 type, Slice name) { +void add_log_event(LogeventIdWithGeneration &log_event_id, const Storer &storer, uint32 type, Slice name) { LOG(INFO) << "Save " << name << " to binlog"; - if (logevent_id.logevent_id == 0) { - logevent_id.logevent_id = - binlog_add(G()->td_db()->get_binlog(), type, storer); - LOG(INFO) << "Add " << name << " logevent " << logevent_id.logevent_id; + if (log_event_id.log_event_id == 0) { + log_event_id.log_event_id = binlog_add(G()->td_db()->get_binlog(), type, storer); + LOG(INFO) << "Add " << name << " log event " << log_event_id.log_event_id; } else { - auto new_logevent_id = binlog_rewrite(G()->td_db()->get_binlog(), logevent_id.logevent_id, - type, storer); - LOG(INFO) << "Rewrite " << name << " logevent " << logevent_id.logevent_id << " with " << new_logevent_id; + auto new_log_event_id = binlog_rewrite(G()->td_db()->get_binlog(), log_event_id.log_event_id, type, storer); + LOG(INFO) << "Rewrite " << name << " log event " << log_event_id.log_event_id << " with " << new_log_event_id; } - logevent_id.generation++; + log_event_id.generation++; } -void delete_log_event(LogeventIdWithGeneration &logevent_id, uint64 generation, Slice name) { - LOG(INFO) << "Finish to process " << name << " logevent " << logevent_id.logevent_id << " with generation " << generation; - if (logevent_id.generation == generation) { - CHECK(logevent_id.logevent_id != 0); - LOG(INFO) << "Delete " << name << " logevent " << logevent_id.logevent_id; - binlog_erase(G()->td_db()->get_binlog(), logevent_id.logevent_id); - logevent_id.logevent_id = 0; +void delete_log_event(LogeventIdWithGeneration &log_event_id, uint64 generation, Slice name) { + LOG(INFO) << "Finish to process " << name << " log event " << log_event_id.log_event_id << " with generation " + << generation; + if (log_event_id.generation == generation) { + CHECK(log_event_id.log_event_id != 0); + LOG(INFO) << "Delete " << name << " log event " << log_event_id.log_event_id; + binlog_erase(G()->td_db()->get_binlog(), log_event_id.log_event_id); + log_event_id.log_event_id = 0; } } -Promise get_erase_logevent_promise(uint64 logevent_id, Promise promise) { - if (logevent_id == 0) { +Promise get_erase_log_event_promise(uint64 log_event_id, Promise promise) { + if (log_event_id == 0) { return promise; } - return PromiseCreator::lambda([logevent_id, promise = std::move(promise)](Result result) mutable { + return PromiseCreator::lambda([log_event_id, promise = std::move(promise)](Result result) mutable { if (!G()->close_flag()) { - binlog_erase(G()->td_db()->get_binlog(), logevent_id); + binlog_erase(G()->td_db()->get_binlog(), log_event_id); } promise.set_result(std::move(result)); }); } - } // namespace td diff --git a/td/telegram/logevent/LogEventHelper.h b/td/telegram/logevent/LogEventHelper.h index a3204e816..0704e7318 100644 --- a/td/telegram/logevent/LogEventHelper.h +++ b/td/telegram/logevent/LogEventHelper.h @@ -16,15 +16,15 @@ namespace td { struct LogeventIdWithGeneration { - uint64 logevent_id = 0; + uint64 log_event_id = 0; uint64 generation = 0; }; -void add_log_event(LogeventIdWithGeneration &logevent_id, const Storer &storer, uint32 type, Slice name); +void add_log_event(LogeventIdWithGeneration &log_event_id, const Storer &storer, uint32 type, Slice name); -void delete_log_event(LogeventIdWithGeneration &logevent_id, uint64 generation, Slice name); +void delete_log_event(LogeventIdWithGeneration &log_event_id, uint64 generation, Slice name); -Promise get_erase_logevent_promise(uint64 logevent_id, Promise promise = Promise()); +Promise get_erase_log_event_promise(uint64 log_event_id, Promise promise = Promise()); template void store_time(double time_at, StorerT &storer) { diff --git a/td/telegram/logevent/SecretChatEvent.h b/td/telegram/logevent/SecretChatEvent.h index 361574cf8..8a992c465 100644 --- a/td/telegram/logevent/SecretChatEvent.h +++ b/td/telegram/logevent/SecretChatEvent.h @@ -20,7 +20,7 @@ #include "td/telegram/telegram_api.h" namespace td { -namespace logevent { +namespace log_event { class SecretChatEvent : public LogEventBase { public: @@ -296,7 +296,7 @@ class InboundSecretMessage : public SecretChatLogEventBase } StringBuilder &print(StringBuilder &sb) const override { - return sb << "[Logevent InboundSecretMessage " << tag("id", logevent_id()) << tag("chat_id", chat_id) + return sb << "[Logevent InboundSecretMessage " << tag("id", log_event_id()) << tag("chat_id", chat_id) << tag("date", date) << tag("auth_key_id", format::as_hex(auth_key_id)) << tag("message_id", message_id) << tag("my_in_seq_no", my_in_seq_no) << tag("my_out_seq_no", my_out_seq_no) << tag("his_in_seq_no", his_in_seq_no) << tag("message", to_string(decrypted_message_layer)) @@ -402,7 +402,7 @@ class OutboundSecretMessage : public SecretChatLogEventBase { } StringBuilder &print(StringBuilder &sb) const override { - return sb << "[Logevent CloseSecretChat " << tag("id", logevent_id()) << tag("chat_id", chat_id) << "]"; + return sb << "[Logevent CloseSecretChat " << tag("id", log_event_id()) << tag("chat_id", chat_id) << "]"; } }; @@ -456,7 +456,7 @@ class CreateSecretChat : public SecretChatLogEventBase { } StringBuilder &print(StringBuilder &sb) const override { - return sb << "[Logevent CreateSecretChat " << tag("id", logevent_id()) << tag("chat_id", random_id) + return sb << "[Logevent CreateSecretChat " << tag("id", log_event_id()) << tag("chat_id", random_id) << tag("user_id", user_id) << "]"; } }; @@ -480,10 +480,10 @@ void SecretChatEvent::downcast_call(Type type, F &&f) { break; } } -} // namespace logevent +} // namespace log_event -inline auto create_storer(logevent::SecretChatEvent &event) { - return logevent::detail::StorerImpl(event); +inline auto create_storer(log_event::SecretChatEvent &event) { + return log_event::detail::StorerImpl(event); } } // namespace td diff --git a/tddb/td/db/TQueue.cpp b/tddb/td/db/TQueue.cpp index 9d5d70775..bb09571f3 100644 --- a/tddb/td/db/TQueue.cpp +++ b/tddb/td/db/TQueue.cpp @@ -113,8 +113,8 @@ class TQueueImpl : public TQueue { auto it = q.events.end(); --it; if (it->second.data.empty()) { - if (callback_ != nullptr && it->second.logevent_id != 0) { - callback_->pop(it->second.logevent_id); + if (callback_ != nullptr && it->second.log_event_id != 0) { + callback_->pop(it->second.log_event_id); } q.events.erase(it); } @@ -123,8 +123,8 @@ class TQueueImpl : public TQueue { schedule_queue_gc(queue_id, q, raw_event.expires_at); } - if (raw_event.logevent_id == 0 && callback_ != nullptr) { - raw_event.logevent_id = callback_->push(queue_id, raw_event); + if (raw_event.log_event_id == 0 && callback_ != nullptr) { + raw_event.log_event_id = callback_->push(queue_id, raw_event); } q.tail_id = event_id.next().move_as_ok(); q.total_event_length += raw_event.data.size(); @@ -307,7 +307,7 @@ class TQueueImpl : public TQueue { void pop(Queue &q, QueueId queue_id, std::map::iterator &it, EventId tail_id) { auto &event = it->second; - if (callback_ == nullptr || event.logevent_id == 0) { + if (callback_ == nullptr || event.log_event_id == 0) { remove_event(q, it); return; } @@ -319,7 +319,7 @@ class TQueueImpl : public TQueue { } ++it; } else { - callback_->pop(event.logevent_id); + callback_->pop(event.log_event_id); remove_event(q, it); } } @@ -438,16 +438,16 @@ uint64 TQueueBinlog::push(QueueId queue_id, const RawEvent &event) { log_event.data = event.data; log_event.extra = event.extra; auto magic = BINLOG_EVENT_TYPE + (log_event.extra != 0); - if (event.logevent_id == 0) { + if (event.log_event_id == 0) { return binlog_->add(magic, log_event); } - binlog_->rewrite(event.logevent_id, magic, log_event); - return event.logevent_id; + binlog_->rewrite(event.log_event_id, magic, log_event); + return event.log_event_id; } template -void TQueueBinlog::pop(uint64 logevent_id) { - binlog_->erase(logevent_id); +void TQueueBinlog::pop(uint64 log_event_id) { + binlog_->erase(log_event_id); } template @@ -463,7 +463,7 @@ Status TQueueBinlog::replay(const BinlogEvent &binlog_event, TQueue &q) TRY_STATUS(parser.get_status()); TRY_RESULT(event_id, EventId::from_int32(event.event_id)); RawEvent raw_event; - raw_event.logevent_id = binlog_event.id_; + raw_event.log_event_id = binlog_event.id_; raw_event.event_id = event_id; raw_event.expires_at = event.expires_at; raw_event.data = event.data.str(); @@ -483,19 +483,19 @@ template class TQueueBinlog; template class TQueueBinlog; uint64 TQueueMemoryStorage::push(QueueId queue_id, const RawEvent &event) { - auto logevent_id = event.logevent_id == 0 ? next_logevent_id_++ : event.logevent_id; - events_[logevent_id] = std::make_pair(queue_id, event); - return logevent_id; + auto log_event_id = event.log_event_id == 0 ? next_log_event_id_++ : event.log_event_id; + events_[log_event_id] = std::make_pair(queue_id, event); + return log_event_id; } -void TQueueMemoryStorage::pop(uint64 logevent_id) { - events_.erase(logevent_id); +void TQueueMemoryStorage::pop(uint64 log_event_id) { + events_.erase(log_event_id); } void TQueueMemoryStorage::replay(TQueue &q) const { for (auto &e : events_) { auto x = e.second; - x.second.logevent_id = e.first; + x.second.log_event_id = e.first; bool is_added = q.do_push(x.first, std::move(x.second)); CHECK(is_added); } diff --git a/tddb/td/db/TQueue.h b/tddb/td/db/TQueue.h index 58efc283a..762c66556 100644 --- a/tddb/td/db/TQueue.h +++ b/tddb/td/db/TQueue.h @@ -60,7 +60,7 @@ class TQueue { }; struct RawEvent { - uint64 logevent_id{0}; + uint64 log_event_id{0}; EventId event_id; string data; int64 extra{0}; @@ -82,7 +82,7 @@ class TQueue { virtual ~StorageCallback() = default; virtual uint64 push(QueueId queue_id, const RawEvent &event) = 0; - virtual void pop(uint64 logevent_id) = 0; + virtual void pop(uint64 log_event_id) = 0; virtual void close(Promise<> promise) = 0; }; @@ -125,7 +125,7 @@ template class TQueueBinlog : public TQueue::StorageCallback { public: uint64 push(QueueId queue_id, const RawEvent &event) override; - void pop(uint64 logevent_id) override; + void pop(uint64 log_event_id) override; Status replay(const BinlogEvent &binlog_event, TQueue &q) const TD_WARN_UNUSED_RESULT; void set_binlog(std::shared_ptr binlog) { @@ -141,12 +141,12 @@ class TQueueBinlog : public TQueue::StorageCallback { class TQueueMemoryStorage : public TQueue::StorageCallback { public: uint64 push(QueueId queue_id, const RawEvent &event) override; - void pop(uint64 logevent_id) override; + void pop(uint64 log_event_id) override; void replay(TQueue &q) const; virtual void close(Promise<> promise) override; private: - uint64 next_logevent_id_{1}; + uint64 next_log_event_id_{1}; std::map> events_; }; diff --git a/tddb/td/db/binlog/Binlog.h b/tddb/td/db/binlog/Binlog.h index fa8c64bb3..7af532b0c 100644 --- a/tddb/td/db/binlog/Binlog.h +++ b/tddb/td/db/binlog/Binlog.h @@ -72,20 +72,20 @@ class Binlog { } uint64 add(int32 type, const Storer &storer) { - auto logevent_id = next_id(); - add_raw_event(BinlogEvent::create_raw(logevent_id, type, 0, storer), {}); - return logevent_id; + auto log_event_id = next_id(); + add_raw_event(BinlogEvent::create_raw(log_event_id, type, 0, storer), {}); + return log_event_id; } - uint64 rewrite(uint64 logevent_id, int32 type, const Storer &storer) { + uint64 rewrite(uint64 log_event_id, int32 type, const Storer &storer) { auto seq_no = next_id(); - add_raw_event(BinlogEvent::create_raw(logevent_id, type, BinlogEvent::Flags::Rewrite, storer), {}); + add_raw_event(BinlogEvent::create_raw(log_event_id, type, BinlogEvent::Flags::Rewrite, storer), {}); return seq_no; } - uint64 erase(uint64 logevent_id) { + uint64 erase(uint64 log_event_id) { auto seq_no = next_id(); - add_raw_event(BinlogEvent::create_raw(logevent_id, BinlogEvent::ServiceTypes::Empty, BinlogEvent::Flags::Rewrite, + add_raw_event(BinlogEvent::create_raw(log_event_id, BinlogEvent::ServiceTypes::Empty, BinlogEvent::Flags::Rewrite, EmptyStorer()), {}); return seq_no; diff --git a/tddb/td/db/binlog/BinlogHelper.h b/tddb/td/db/binlog/BinlogHelper.h index 6d387941b..3e73422ce 100644 --- a/tddb/td/db/binlog/BinlogHelper.h +++ b/tddb/td/db/binlog/BinlogHelper.h @@ -21,13 +21,13 @@ inline uint64 binlog_add(BinlogInterface *binlog_ptr, int32 type, const Storer & return binlog_ptr->add(type, storer, std::move(promise)); } -inline uint64 binlog_rewrite(BinlogInterface *binlog_ptr, uint64 logevent_id, int32 type, const Storer &storer, +inline uint64 binlog_rewrite(BinlogInterface *binlog_ptr, uint64 log_event_id, int32 type, const Storer &storer, Promise<> promise = Promise<>()) { - return binlog_ptr->rewrite(logevent_id, type, storer, std::move(promise)); + return binlog_ptr->rewrite(log_event_id, type, storer, std::move(promise)); } -inline uint64 binlog_erase(BinlogInterface *binlog_ptr, uint64 logevent_id, Promise<> promise = Promise<>()) { - return binlog_ptr->erase(logevent_id, std::move(promise)); +inline uint64 binlog_erase(BinlogInterface *binlog_ptr, uint64 log_event_id, Promise<> promise = Promise<>()) { + return binlog_ptr->erase(log_event_id, std::move(promise)); } } // namespace td diff --git a/tddb/td/db/binlog/BinlogInterface.h b/tddb/td/db/binlog/BinlogInterface.h index c70052264..5f3d4627c 100644 --- a/tddb/td/db/binlog/BinlogInterface.h +++ b/tddb/td/db/binlog/BinlogInterface.h @@ -43,22 +43,22 @@ class BinlogInterface { } uint64 add(int32 type, const Storer &storer, Promise<> promise = Promise<>()) { - auto logevent_id = next_id(); - add_raw_event_impl(logevent_id, BinlogEvent::create_raw(logevent_id, type, 0, storer), std::move(promise), {}); - return logevent_id; + auto log_event_id = next_id(); + add_raw_event_impl(log_event_id, BinlogEvent::create_raw(log_event_id, type, 0, storer), std::move(promise), {}); + return log_event_id; } - uint64 rewrite(uint64 logevent_id, int32 type, const Storer &storer, Promise<> promise = Promise<>()) { + uint64 rewrite(uint64 log_event_id, int32 type, const Storer &storer, Promise<> promise = Promise<>()) { auto seq_no = next_id(); - add_raw_event_impl(seq_no, BinlogEvent::create_raw(logevent_id, type, BinlogEvent::Flags::Rewrite, storer), + add_raw_event_impl(seq_no, BinlogEvent::create_raw(log_event_id, type, BinlogEvent::Flags::Rewrite, storer), std::move(promise), {}); return seq_no; } - uint64 erase(uint64 logevent_id, Promise<> promise = Promise<>()) { + uint64 erase(uint64 log_event_id, Promise<> promise = Promise<>()) { auto seq_no = next_id(); add_raw_event_impl(seq_no, - BinlogEvent::create_raw(logevent_id, BinlogEvent::ServiceTypes::Empty, + BinlogEvent::create_raw(log_event_id, BinlogEvent::ServiceTypes::Empty, BinlogEvent::Flags::Rewrite, EmptyStorer()), std::move(promise), {}); return seq_no; diff --git a/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp b/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp index f8eb41f97..9d9ed36ef 100644 --- a/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp +++ b/tddb/td/db/binlog/detail/BinlogEventsProcessor.cpp @@ -20,7 +20,7 @@ Status BinlogEventsProcessor::do_event(BinlogEvent &&event) { if ((event.flags_ & BinlogEvent::Flags::Rewrite) && !ids_.empty() && ids_.back() >= fixed_id) { auto it = std::lower_bound(ids_.begin(), ids_.end(), fixed_id); if (it == ids_.end() || *it != fixed_id) { - return Status::Error(PSLICE() << "Ignore rewrite logevent " << event.public_to_string()); + return Status::Error(PSLICE() << "Ignore rewrite log event " << event.public_to_string()); } auto pos = it - ids_.begin(); total_raw_events_size_ -= static_cast(events_[pos].raw_event_.size()); diff --git a/test/secret.cpp b/test/secret.cpp index 170f4317a..a5e9ab285 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -589,7 +589,7 @@ class Master : public Actor { void add_inbound_message(int32 chat_id, BufferSlice data, uint64 crc) { CHECK(crc64(data.as_slice()) == crc); - auto event = make_unique(); + auto event = make_unique(); event->chat_id = chat_id; event->date = 0; event->encrypted_message = std::move(data); @@ -668,21 +668,21 @@ class Master : public Actor { for (auto &event : events) { CHECK(event.type_ == LogEvent::HandlerType::SecretChats); - auto r_message = logevent::SecretChatEvent::from_buffer_slice(event.data_as_buffer_slice()); + auto r_message = log_event::SecretChatEvent::from_buffer_slice(event.data_as_buffer_slice()); LOG_IF(FATAL, r_message.is_error()) << "Failed to deserialize event: " << r_message.error(); auto message = r_message.move_as_ok(); - message->set_logevent_id(event.id_); + message->set_log_event_id(event.id_); LOG(INFO) << "Process binlog event " << *message; switch (message->get_type()) { - case logevent::SecretChatEvent::Type::InboundSecretMessage: + case log_event::SecretChatEvent::Type::InboundSecretMessage: send_closure_later(actor_, &SecretChatActor::replay_inbound_message, - unique_ptr( - static_cast(message.release()))); + unique_ptr( + static_cast(message.release()))); break; - case logevent::SecretChatEvent::Type::OutboundSecretMessage: + case log_event::SecretChatEvent::Type::OutboundSecretMessage: send_closure_later(actor_, &SecretChatActor::replay_outbound_message, - unique_ptr( - static_cast(message.release()))); + unique_ptr( + static_cast(message.release()))); break; default: UNREACHABLE();