From 4b0bda767c81a8b6743e19ae64de67086810f29c Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 5 Jul 2021 05:42:37 +0300 Subject: [PATCH] Add SecretChatLayer.h. --- CMakeLists.txt | 1 + td/telegram/ContactsManager.cpp | 6 +++--- td/telegram/MessageEntity.cpp | 8 ++++---- td/telegram/SecretChatActor.cpp | 20 ++++++++++++-------- td/telegram/SecretChatActor.h | 15 ++++----------- td/telegram/SecretChatLayer.h | 19 +++++++++++++++++++ 6 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 td/telegram/SecretChatLayer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 5625059f9..ba7350885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -593,6 +593,7 @@ set(TDLIB_SOURCE td/telegram/SecretChatActor.h td/telegram/SecretChatId.h td/telegram/SecretChatDb.h + td/telegram/SecretChatLayer.h td/telegram/SecretChatsManager.h td/telegram/SecretInputMedia.h td/telegram/SecureManager.h diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 8c887e680..892a7cd29 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -36,7 +36,7 @@ #include "td/telegram/PasswordManager.h" #include "td/telegram/Photo.h" #include "td/telegram/Photo.hpp" -#include "td/telegram/SecretChatActor.h" +#include "td/telegram/SecretChatLayer.h" #include "td/telegram/SecretChatsManager.h" #include "td/telegram/ServerMessageId.h" #include "td/telegram/StickerSetId.hpp" @@ -4459,7 +4459,7 @@ void ContactsManager::ChannelFull::parse(ParserT &parser) { template void ContactsManager::SecretChat::store(StorerT &storer) const { using td::store; - bool has_layer = layer > SecretChatActor::DEFAULT_LAYER; + bool has_layer = layer > static_cast(SecretChatLayer::DEFAULT_LAYER); bool has_initial_folder_id = initial_folder_id != FolderId(); BEGIN_STORE_FLAGS(); STORE_FLAG(is_outbound); @@ -4505,7 +4505,7 @@ void ContactsManager::SecretChat::parse(ParserT &parser) { if (has_layer) { parse(layer, parser); } else { - layer = SecretChatActor::DEFAULT_LAYER; + layer = static_cast(SecretChatLayer::DEFAULT_LAYER); } if (has_initial_folder_id) { parse(initial_folder_id, parser); diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index c67679e3b..100b272cd 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -10,7 +10,7 @@ #include "td/telegram/Dependencies.h" #include "td/telegram/LinkManager.h" #include "td/telegram/misc.h" -#include "td/telegram/SecretChatActor.h" +#include "td/telegram/SecretChatLayer.h" #include "td/utils/algorithm.h" #include "td/utils/format.h" @@ -2992,17 +2992,17 @@ vector> get_input_secret_message_entiti result.push_back(make_tl_object(entity.offset, entity.length)); break; case MessageEntity::Type::Underline: - if (layer >= SecretChatActor::NEW_ENTITIES_LAYER) { + if (layer >= static_cast(SecretChatLayer::NEW_ENTITIES_LAYER)) { result.push_back(make_tl_object(entity.offset, entity.length)); } break; case MessageEntity::Type::Strikethrough: - if (layer >= SecretChatActor::NEW_ENTITIES_LAYER) { + if (layer >= static_cast(SecretChatLayer::NEW_ENTITIES_LAYER)) { result.push_back(make_tl_object(entity.offset, entity.length)); } break; case MessageEntity::Type::BlockQuote: - if (layer >= SecretChatActor::NEW_ENTITIES_LAYER) { + if (layer >= static_cast(SecretChatLayer::NEW_ENTITIES_LAYER)) { result.push_back(make_tl_object(entity.offset, entity.length)); } break; diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 7aad834c4..032e51dd6 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -440,8 +440,9 @@ void SecretChatActor::binlog_replay_finish() { LOG(INFO) << "Binlog replay is finished with PfsState " << pfs_state_; binlog_replay_finish_flag_ = true; if (auth_state_.state == State::Ready) { - if (config_state_.my_layer < MY_LAYER) { - send_action(secret_api::make_object(MY_LAYER), SendFlag::None, + auto my_layer = static_cast(SecretChatLayer::MY_LAYER); + if (config_state_.my_layer < my_layer) { + send_action(secret_api::make_object(my_layer), SendFlag::None, Promise<>()); } } @@ -845,7 +846,8 @@ Status SecretChatActor::do_inbound_message_encrypted(unique_ptrlayer_; - if (layer < DEFAULT_LAYER && false /* old Android app could send such messages */) { + if (layer < static_cast(SecretChatLayer::DEFAULT_LAYER) && + false /* old Android app could send such messages */) { LOG(ERROR) << "Layer " << layer << " is not supported, drop message " << to_string(message_with_layer); return Status::OK(); } @@ -854,7 +856,7 @@ Status SecretChatActor::do_inbound_message_encrypted(unique_ptrsecret_chat_db()->set_value(config_state_); send_update_secret_chat(); } - if (layer >= MTPROTO_2_LAYER && mtproto_version < 2) { + if (layer >= static_cast(SecretChatLayer::MTPROTO_2_LAYER) && mtproto_version < 2) { return Status::Error(PSLICE() << "MTProto 1.0 encryption is forbidden for this layer"); } if (message_with_layer->in_seq_no_ < 0) { @@ -871,8 +873,9 @@ Status SecretChatActor::do_inbound_message_encrypted(unique_ptr(MY_LAYER), SendFlag::None, - Promise<>()); + send_action(secret_api::make_object( + static_cast(SecretChatLayer::MY_LAYER)), + SendFlag::None, Promise<>()); if (config_state_.his_layer == 8) { TlBufferParser new_parser(&data_buffer); @@ -1844,8 +1847,9 @@ Status SecretChatActor::on_update_chat(telegram_api::encryptedChat &update) { context_->secret_chat_db()->set_value(pfs_state_); context_->secret_chat_db()->set_value(auth_state_); send_update_secret_chat(); - send_action(secret_api::make_object(MY_LAYER), SendFlag::None, - Promise<>()); + send_action(secret_api::make_object( + static_cast(SecretChatLayer::MY_LAYER)), + SendFlag::None, Promise<>()); return Status::OK(); } Status SecretChatActor::on_update_chat(telegram_api::encryptedChatDiscarded &update) { diff --git a/td/telegram/SecretChatActor.h b/td/telegram/SecretChatActor.h index 4726bb540..97a33d852 100644 --- a/td/telegram/SecretChatActor.h +++ b/td/telegram/SecretChatActor.h @@ -14,6 +14,7 @@ #include "td/telegram/secret_api.h" #include "td/telegram/SecretChatDb.h" #include "td/telegram/SecretChatId.h" +#include "td/telegram/SecretChatLayer.h" #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" @@ -48,14 +49,6 @@ class NetQueryCreator; class SecretChatActor final : public NetQueryCallback { public: - enum : int32 { - DEFAULT_LAYER = 73, - MTPROTO_2_LAYER = 73, - NEW_ENTITIES_LAYER = 101, - DELETE_MESSAGES_ON_CLOSE_LAYER = 123, - MY_LAYER = DELETE_MESSAGES_ON_CLOSE_LAYER - }; - class Context { public: Context() = default; @@ -646,12 +639,12 @@ class SecretChatActor final : public NetQueryCallback { Status save_common_info(T &update); int32 current_layer() const { - int32 layer = MY_LAYER; + int32 layer = static_cast(SecretChatLayer::MY_LAYER); if (config_state_.his_layer < layer) { layer = config_state_.his_layer; } - if (layer < DEFAULT_LAYER) { - layer = DEFAULT_LAYER; + if (layer < static_cast(SecretChatLayer::DEFAULT_LAYER)) { + layer = static_cast(SecretChatLayer::DEFAULT_LAYER); } return layer; } diff --git a/td/telegram/SecretChatLayer.h b/td/telegram/SecretChatLayer.h new file mode 100644 index 000000000..ff1aa770e --- /dev/null +++ b/td/telegram/SecretChatLayer.h @@ -0,0 +1,19 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +namespace td { + +enum class SecretChatLayer : int32 { + DEFAULT_LAYER = 73, + MTPROTO_2_LAYER = 73, + NEW_ENTITIES_LAYER = 101, + DELETE_MESSAGES_ON_CLOSE_LAYER = 123, + MY_LAYER = DELETE_MESSAGES_ON_CLOSE_LAYER +}; + +} // namespace td