Add SecretChatLayer.h.

This commit is contained in:
levlam 2021-07-05 05:42:37 +03:00
parent f02b2ee4b6
commit 4b0bda767c
6 changed files with 43 additions and 26 deletions

View File

@ -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

View File

@ -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 <class StorerT>
void ContactsManager::SecretChat::store(StorerT &storer) const {
using td::store;
bool has_layer = layer > SecretChatActor::DEFAULT_LAYER;
bool has_layer = layer > static_cast<int32>(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<int32>(SecretChatLayer::DEFAULT_LAYER);
}
if (has_initial_folder_id) {
parse(initial_folder_id, parser);

View File

@ -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<tl_object_ptr<secret_api::MessageEntity>> get_input_secret_message_entiti
result.push_back(make_tl_object<secret_api::messageEntityItalic>(entity.offset, entity.length));
break;
case MessageEntity::Type::Underline:
if (layer >= SecretChatActor::NEW_ENTITIES_LAYER) {
if (layer >= static_cast<int32>(SecretChatLayer::NEW_ENTITIES_LAYER)) {
result.push_back(make_tl_object<secret_api::messageEntityUnderline>(entity.offset, entity.length));
}
break;
case MessageEntity::Type::Strikethrough:
if (layer >= SecretChatActor::NEW_ENTITIES_LAYER) {
if (layer >= static_cast<int32>(SecretChatLayer::NEW_ENTITIES_LAYER)) {
result.push_back(make_tl_object<secret_api::messageEntityStrike>(entity.offset, entity.length));
}
break;
case MessageEntity::Type::BlockQuote:
if (layer >= SecretChatActor::NEW_ENTITIES_LAYER) {
if (layer >= static_cast<int32>(SecretChatLayer::NEW_ENTITIES_LAYER)) {
result.push_back(make_tl_object<secret_api::messageEntityBlockquote>(entity.offset, entity.length));
}
break;

View File

@ -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<secret_api::decryptedMessageActionNotifyLayer>(MY_LAYER), SendFlag::None,
auto my_layer = static_cast<int32>(SecretChatLayer::MY_LAYER);
if (config_state_.my_layer < my_layer) {
send_action(secret_api::make_object<secret_api::decryptedMessageActionNotifyLayer>(my_layer), SendFlag::None,
Promise<>());
}
}
@ -845,7 +846,8 @@ Status SecretChatActor::do_inbound_message_encrypted(unique_ptr<log_event::Inbou
parser.fetch_end();
if (!parser.get_error()) {
auto layer = message_with_layer->layer_;
if (layer < DEFAULT_LAYER && false /* old Android app could send such messages */) {
if (layer < static_cast<int32>(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_ptr<log_event::Inbou
context_->secret_chat_db()->set_value(config_state_);
send_update_secret_chat();
}
if (layer >= MTPROTO_2_LAYER && mtproto_version < 2) {
if (layer >= static_cast<int32>(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<log_event::Inbou
// support for older layer
LOG(WARNING) << "Failed to fetch update: " << status;
send_action(secret_api::make_object<secret_api::decryptedMessageActionNotifyLayer>(MY_LAYER), SendFlag::None,
Promise<>());
send_action(secret_api::make_object<secret_api::decryptedMessageActionNotifyLayer>(
static_cast<int32>(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<secret_api::decryptedMessageActionNotifyLayer>(MY_LAYER), SendFlag::None,
Promise<>());
send_action(secret_api::make_object<secret_api::decryptedMessageActionNotifyLayer>(
static_cast<int32>(SecretChatLayer::MY_LAYER)),
SendFlag::None, Promise<>());
return Status::OK();
}
Status SecretChatActor::on_update_chat(telegram_api::encryptedChatDiscarded &update) {

View File

@ -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<int32>(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<int32>(SecretChatLayer::DEFAULT_LAYER)) {
layer = static_cast<int32>(SecretChatLayer::DEFAULT_LAYER);
}
return layer;
}

View File

@ -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