diff --git a/benchmark/bench_actor.cpp b/benchmark/bench_actor.cpp index 82c88cfdd..a84949580 100644 --- a/benchmark/bench_actor.cpp +++ b/benchmark/bench_actor.cpp @@ -35,12 +35,14 @@ struct TestActor final : public td::Actor { td::int32 TestActor::actor_count_; +namespace td { template <> -class td::ActorTraits { +class ActorTraits { public: static constexpr bool need_context = false; static constexpr bool need_start_up = true; }; +} // namespace td class CreateActorBench final : public td::Benchmark { td::ConcurrentScheduler scheduler_; diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 0e43f1b0f..50083fbbf 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3737,7 +3737,7 @@ updateChatVideoChat chat_id:int53 video_chat:videoChat = Update; //@description The value of the default disable_notification parameter, used when a message is sent to the chat, was changed @chat_id Chat identifier @default_disable_notification The new default_disable_notification value updateChatDefaultDisableNotification chat_id:int53 default_disable_notification:Bool = Update; -//@description Incoming messages were read or number of unread messages has been changed @chat_id Chat identifier @last_read_inbox_message_id Identifier of the last read incoming message @unread_count The number of unread messages left in the chat +//@description Incoming messages were read or the number of unread messages has been changed @chat_id Chat identifier @last_read_inbox_message_id Identifier of the last read incoming message @unread_count The number of unread messages left in the chat updateChatReadInbox chat_id:int53 last_read_inbox_message_id:int53 unread_count:int32 = Update; //@description Outgoing messages were read @chat_id Chat identifier @last_read_outbox_message_id Identifier of last read outgoing message @@ -4189,7 +4189,7 @@ getFile file_id:int32 = File; //@remote_file_id Remote identifier of the file to get @file_type File type; pass null if unknown getRemoteFile remote_file_id:string file_type:FileType = File; -//@description Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats has been loaded +//@description Loads more chats from a chat list. The loaded chats and their positions in the chat list will be sent through updates. Chats are sorted by the pair (chat.position.order, chat.id) in descending order. Returns a 404 error if all chats have been loaded //@chat_list The chat list in which to load chats; pass null to load chats from the main chat list //@limit The maximum number of chats to be loaded. For optimal performance, the number of loaded chats is chosen by TDLib and can be smaller than the specified limit, even if the end of the list is not reached loadChats chat_list:ChatList limit:int32 = Ok; @@ -5137,7 +5137,7 @@ setGroupCallParticipantVolumeLevel group_call_id:int32 participant_id:MessageSen //@is_hand_raised Pass true if the user's hand needs to be raised. Only self hand can be raised. Requires groupCall.can_be_managed group call flag to lower other's hand toggleGroupCallParticipantIsHandRaised group_call_id:int32 participant_id:MessageSender is_hand_raised:Bool = Ok; -//@description Loads more participants of a group call. The loaded participants will be received through updates. Use the field groupCall.loaded_all_participants to check whether all participants has already been loaded +//@description Loads more participants of a group call. The loaded participants will be received through updates. Use the field groupCall.loaded_all_participants to check whether all participants have already been loaded //@group_call_id Group call identifier. The group call must be previously received through getGroupCall and must be joined or being joined //@limit The maximum number of participants to load; up to 100 loadGroupCallParticipants group_call_id:int32 limit:int32 = Ok; diff --git a/td/mtproto/PacketInfo.h b/td/mtproto/PacketInfo.h index a6907eee3..4407101f1 100644 --- a/td/mtproto/PacketInfo.h +++ b/td/mtproto/PacketInfo.h @@ -16,7 +16,7 @@ struct PacketInfo { enum { Common, EndToEnd } type = Common; uint64 auth_key_id{0}; uint32 message_ack{0}; - UInt128 message_key{}; + UInt128 message_key; uint64 salt{0}; uint64 session_id{0}; diff --git a/td/mtproto/TcpTransport.h b/td/mtproto/TcpTransport.h index d2fbc3e01..9e392ae7f 100644 --- a/td/mtproto/TcpTransport.h +++ b/td/mtproto/TcpTransport.h @@ -193,7 +193,7 @@ class ObfuscatedTransport final : public IStreamTransport { // TODO: use ByteFlow? // One problem is that BufferedFd owns output_buffer_ // The other problem is that first 56 bytes must be sent unencrypted. - UInt256 output_key_{}; + UInt256 output_key_; AesCtrState output_state_; ChainBufferWriter *output_ = nullptr; diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 82ffd25b3..57e4b422b 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -189,7 +189,7 @@ FileId AnimationsManager::on_get_animation(unique_ptr new_animation, a->file_name = std::move(new_animation->file_name); } if (a->dimensions != new_animation->dimensions) { - LOG(DEBUG) << "Animation " << file_id << " dimensions has changed"; + LOG(DEBUG) << "Animation " << file_id << " dimensions have changed"; a->dimensions = new_animation->dimensions; } if (a->duration != new_animation->duration) { @@ -523,7 +523,7 @@ void AnimationsManager::reload_saved_animations(bool force) { void AnimationsManager::repair_saved_animations(Promise &&promise) { if (td_->auth_manager_->is_bot()) { - return promise.set_error(Status::Error(400, "Bots has no saved animations")); + return promise.set_error(Status::Error(400, "Bots have no saved animations")); } repair_saved_animations_queries_.push_back(std::move(promise)); diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 824c24ba5..981bc691b 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -62,6 +62,7 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par LOG(WARNING) << "Continue to log out"; update_state(State::LoggingOut); } else if (auth_str == "destroy") { + LOG(WARNING) << "Continue to destroy auth keys"; update_state(State::DestroyingKeys); } else { if (!load_state()) { @@ -74,7 +75,8 @@ void AuthManager::start_up() { if (state_ == State::LoggingOut) { send_log_out_query(); } else if (state_ == State::DestroyingKeys) { - destroy_auth_keys(); + G()->net_query_dispatcher().destroy_auth_keys( + PromiseCreator::lambda([](Unit) { send_closure_later(G()->td(), &Td::destroy); }, PromiseCreator::Ignore())); } } void AuthManager::tear_down() { diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index 7fc629a71..927105c6b 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -174,8 +174,8 @@ void FileReferenceManager::merge(NodeId to_node_id, NodeId from_node_id) { auto &from = from_it->second; VLOG(file_references) << "Merge " << to.file_source_ids.size() << " and " << from.file_source_ids.size() << " sources of files " << to_node_id << " and " << from_node_id; - CHECK(!to.query || to.query->proxy.empty()); - CHECK(!from.query || from.query->proxy.empty()); + CHECK(!to.query || to.query->proxy.is_empty()); + CHECK(!from.query || from.query->proxy.is_empty()); if (to.query || from.query) { if (!to.query) { to.query = make_unique(); @@ -184,7 +184,7 @@ void FileReferenceManager::merge(NodeId to_node_id, NodeId from_node_id) { if (from.query) { combine(to.query->promises, std::move(from.query->promises)); to.query->active_queries += from.query->active_queries; - from.query->proxy = {to_node_id, to.query->generation}; + from.query->proxy = Destination(to_node_id, to.query->generation); } } to.file_source_ids.merge(std::move(from.file_source_ids)); @@ -226,7 +226,7 @@ void FileReferenceManager::run_node(NodeId node_id) { return; } auto file_source_id = node.file_source_ids.next(); - send_query({node_id, node.query->generation}, file_source_id); + send_query(Destination(node_id, node.query->generation), file_source_id); } void FileReferenceManager::send_query(Destination dest, FileSourceId file_source_id) { @@ -326,7 +326,7 @@ FileReferenceManager::Destination FileReferenceManager::on_query_result(Destinat query->active_queries--; CHECK(query->active_queries >= 0); - if (!query->proxy.empty()) { + if (!query->proxy.is_empty()) { query->active_queries -= sub; CHECK(query->active_queries >= 0); auto new_proxy = on_query_result(query->proxy, file_source_id, std::move(status), query->active_queries); diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index d3c5fa8c6..f7322faa4 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -78,11 +78,15 @@ class FileReferenceManager final : public Actor { private: struct Destination { - bool empty() const { - return node_id.empty(); - } NodeId node_id; int64 generation{0}; + + Destination() = default; + Destination(NodeId node_id, int64 generation) : node_id(node_id), generation(generation) { + } + bool is_empty() const { + return node_id.empty(); + } }; struct Query { std::vector> promises; diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 1f145832e..82cd38de7 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -2996,7 +2996,7 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo if (need_message_changed_warning && need_message_text_changed_warning(old_, new_) && old_->text.entities.size() <= MAX_CUSTOM_ENTITIES_COUNT && need_message_entities_changed_warning(old_->text.entities, new_->text.entities)) { - LOG(WARNING) << "Entities has changed in " << get_content_object(old_content) << ". New content is " + LOG(WARNING) << "Entities have changed in " << get_content_object(old_content) << ". New content is " << get_content_object(new_content); } need_update = true; diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 841cac167..dcf37cea3 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -667,17 +667,17 @@ class MessagesDbImpl final : public MessagesDbSyncInterface { int32 limit = min(query.limit, static_cast(message_ids.size())); double delta = static_cast(message_ids.size()) / limit; - vector positions; - positions.reserve(limit); + MessagesDbMessagePositions positions; + positions.total_count = static_cast(message_ids.size()); + positions.positions.reserve(limit); for (int32 i = 0; i < limit; i++) { auto position = static_cast((i + 0.5) * delta); auto message_id = message_ids[position]; TRY_RESULT(message, get_message({query.dialog_id, message_id})); auto date = get_message_info(message).second; - positions.push_back(MessagesDbMessagePosition{position, date, message_id}); + positions.positions.push_back(MessagesDbMessagePosition{position, date, message_id}); } - - return MessagesDbMessagePositions{static_cast(message_ids.size()), std::move(positions)}; + return positions; } Result> get_messages(MessagesDbMessagesQuery query) final { diff --git a/td/telegram/MessagesDb.h b/td/telegram/MessagesDb.h index f2017db93..af3ffff17 100644 --- a/td/telegram/MessagesDb.h +++ b/td/telegram/MessagesDb.h @@ -66,8 +66,8 @@ struct MessagesDbGetDialogSparseMessagePositionsQuery { }; struct MessagesDbMessagePosition { - int32 position{0}; - int32 date{0}; + int32 position; + int32 date; MessageId message_id; }; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 999a6811e..2c732a393 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -27911,7 +27911,7 @@ vector MessagesManager::get_message_notifications_from_database_fo bool is_correct = true; if (notification_id.get() >= from_notification_id.get()) { - // possible if two messages has the same notification_id + // possible if two messages have the same notification_id LOG(ERROR) << "Have nonmonotonic notification identifiers: " << d->dialog_id << " " << m->message_id << " " << notification_id << " " << from_message_id << " " << from_notification_id; is_correct = false; @@ -35045,7 +35045,9 @@ bool MessagesManager::set_dialog_order(Dialog *d, int64 new_order, bool need_sen } auto folder_ptr = get_dialog_folder(d->folder_id); - CHECK(folder_ptr != nullptr); + LOG_CHECK(folder_ptr != nullptr) << is_inited_ << ' ' << G()->close_flag() << ' ' << dialog_id << ' ' << d->folder_id + << ' ' << is_loaded_from_database << ' ' << td_->auth_manager_->is_authorized() + << ' ' << td_->auth_manager_->was_authorized() << ' ' << source; auto &folder = *folder_ptr; if (old_date == new_date) { if (new_order == DEFAULT_ORDER) { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index d1a52d088..a98d3c654 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -2047,7 +2047,7 @@ FileId StickersManager::on_get_sticker(unique_ptr new_sticker, bool rep } else if (replace) { CHECK(s->file_id == file_id); if (s->dimensions != new_sticker->dimensions && new_sticker->dimensions.width != 0) { - LOG(DEBUG) << "Sticker " << file_id << " dimensions has changed"; + LOG(DEBUG) << "Sticker " << file_id << " dimensions have changed"; s->dimensions = new_sticker->dimensions; } if (s->set_id != new_sticker->set_id && new_sticker->set_id.is_valid()) { @@ -6131,7 +6131,7 @@ void StickersManager::reload_recent_stickers(bool is_attached, bool force) { void StickersManager::repair_recent_stickers(bool is_attached, Promise &&promise) { if (td_->auth_manager_->is_bot()) { - return promise.set_error(Status::Error(400, "Bots has no recent stickers")); + return promise.set_error(Status::Error(400, "Bots have no recent stickers")); } repair_recent_stickers_queries_[is_attached].push_back(std::move(promise)); @@ -6536,7 +6536,7 @@ void StickersManager::reload_favorite_stickers(bool force) { void StickersManager::repair_favorite_stickers(Promise &&promise) { if (td_->auth_manager_->is_bot()) { - return promise.set_error(Status::Error(400, "Bots has no favorite stickers")); + return promise.set_error(Status::Error(400, "Bots have no favorite stickers")); } repair_favorite_stickers_queries_.push_back(std::move(promise)); diff --git a/td/telegram/files/FileLocation.hpp b/td/telegram/files/FileLocation.hpp index 8e640b917..a8ba09671 100644 --- a/td/telegram/files/FileLocation.hpp +++ b/td/telegram/files/FileLocation.hpp @@ -127,7 +127,7 @@ void PhotoRemoteFileLocation::AsKey::store(StorerT &storer) const { storer.store_slice(unique); break; case PhotoSizeSource::Type::StickerSetThumbnailVersion: // 13 bytes - // sticker set thumbnails has no photo_id or document_id + // sticker set thumbnails have no photo_id or document_id storer.store_slice(unique); break; default: diff --git a/td/telegram/files/FileUploader.h b/td/telegram/files/FileUploader.h index 4b7daa463..dae468239 100644 --- a/td/telegram/files/FileUploader.h +++ b/td/telegram/files/FileUploader.h @@ -47,7 +47,7 @@ class FileUploader final : public FileLoader { FileType file_type_ = FileType::Temp; std::vector iv_map_; - UInt256 iv_{}; + UInt256 iv_; string generate_iv_; int64 generate_offset_ = 0; int64 next_offset_ = 0; diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index ba0d1e573..18563e383 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -201,6 +201,10 @@ void Session::start_up() { send_closure(session_, &Session::on_online, online_flag); return session_.is_alive(); } + bool on_logging_out(bool logging_out_flag) final { + send_closure(session_, &Session::on_logging_out, logging_out_flag); + return session_.is_alive(); + } private: ActorId session_; @@ -235,9 +239,15 @@ void Session::on_online(bool online_flag) { loop(); } +void Session::on_logging_out(bool logging_out_flag) { + logging_out_flag_ = logging_out_flag; + connection_online_update(true); + loop(); +} + void Session::connection_online_update(bool force) { - bool new_connection_online_flag = - online_flag_ && (has_queries() || last_activity_timestamp_ + 10 > Time::now_cached() || is_main_); + bool new_connection_online_flag = (online_flag_ || logging_out_flag_) && + (has_queries() || last_activity_timestamp_ + 10 > Time::now_cached() || is_main_); if (connection_online_flag_ == new_connection_online_flag && !force) { return; } diff --git a/td/telegram/net/Session.h b/td/telegram/net/Session.h index 1ad277449..23149fb6e 100644 --- a/td/telegram/net/Session.h +++ b/td/telegram/net/Session.h @@ -69,9 +69,9 @@ class Session final Session(unique_ptr callback, std::shared_ptr shared_auth_data, int32 raw_dc_id, int32 dc_id, bool is_main, bool use_pfs, bool is_cdn, bool need_destroy, const mtproto::AuthKey &tmp_auth_key, const vector &server_salts); + void send(NetQueryPtr &&query); - void on_network(bool network_flag, uint32 network_generation); - void on_online(bool online_flag); + void close(); private: @@ -111,6 +111,7 @@ class Session final bool was_on_network_ = false; bool network_flag_ = false; bool online_flag_ = false; + bool logging_out_flag_ = false; bool connection_online_flag_ = false; uint32 network_generation_ = 0; uint64 being_binded_tmp_auth_key_id_ = 0; @@ -195,6 +196,10 @@ class Session final Status on_pong() final; + void on_network(bool network_flag, uint32 network_generation); + void on_online(bool online_flag); + void on_logging_out(bool logging_out_flag); + void on_auth_key_updated() final; void on_tmp_auth_key_updated() final; void on_server_salt_updated() final; diff --git a/tddb/td/db/binlog/Binlog.h b/tddb/td/db/binlog/Binlog.h index b3018722b..1cc50c13e 100644 --- a/tddb/td/db/binlog/Binlog.h +++ b/tddb/td/db/binlog/Binlog.h @@ -134,7 +134,7 @@ class Binlog { // AesCtrEncryption BufferSlice aes_ctr_key_salt_; - UInt256 aes_ctr_key_{}; + UInt256 aes_ctr_key_; AesCtrState aes_ctr_state_; bool byte_flow_flag_ = false;