Improve constant names.

This commit is contained in:
levlam 2021-07-05 19:17:26 +03:00
parent 4b0bda767c
commit 1d3e72aa9d
7 changed files with 48 additions and 48 deletions

View File

@ -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 > static_cast<int32>(SecretChatLayer::DEFAULT_LAYER);
bool has_layer = layer > static_cast<int32>(SecretChatLayer::Default);
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 = static_cast<int32>(SecretChatLayer::DEFAULT_LAYER);
layer = static_cast<int32>(SecretChatLayer::Default);
}
if (has_initial_folder_id) {
parse(initial_folder_id, parser);

View File

@ -132,51 +132,51 @@ void DeviceTokenManager::register_device(tl_object_ptr<td_api::DeviceToken> devi
case td_api::deviceTokenApplePush::ID: {
auto device_token = static_cast<td_api::deviceTokenApplePush *>(device_token_ptr.get());
token = std::move(device_token->device_token_);
token_type = TokenType::APNS;
token_type = TokenType::Apns;
is_app_sandbox = device_token->is_app_sandbox_;
break;
}
case td_api::deviceTokenFirebaseCloudMessaging::ID: {
auto device_token = static_cast<td_api::deviceTokenFirebaseCloudMessaging *>(device_token_ptr.get());
token = std::move(device_token->token_);
token_type = TokenType::FCM;
token_type = TokenType::Fcm;
encrypt = device_token->encrypt_;
break;
}
case td_api::deviceTokenMicrosoftPush::ID: {
auto device_token = static_cast<td_api::deviceTokenMicrosoftPush *>(device_token_ptr.get());
token = std::move(device_token->channel_uri_);
token_type = TokenType::MPNS;
token_type = TokenType::Mpns;
break;
}
case td_api::deviceTokenSimplePush::ID: {
auto device_token = static_cast<td_api::deviceTokenSimplePush *>(device_token_ptr.get());
token = std::move(device_token->endpoint_);
token_type = TokenType::SIMPLE_PUSH;
token_type = TokenType::SimplePush;
break;
}
case td_api::deviceTokenUbuntuPush::ID: {
auto device_token = static_cast<td_api::deviceTokenUbuntuPush *>(device_token_ptr.get());
token = std::move(device_token->token_);
token_type = TokenType::UBUNTU_PHONE;
token_type = TokenType::UbuntuPhone;
break;
}
case td_api::deviceTokenBlackBerryPush::ID: {
auto device_token = static_cast<td_api::deviceTokenBlackBerryPush *>(device_token_ptr.get());
token = std::move(device_token->token_);
token_type = TokenType::BLACKBERRY;
token_type = TokenType::BlackBerry;
break;
}
case td_api::deviceTokenWindowsPush::ID: {
auto device_token = static_cast<td_api::deviceTokenWindowsPush *>(device_token_ptr.get());
token = std::move(device_token->access_token_);
token_type = TokenType::WNS;
token_type = TokenType::Wns;
break;
}
case td_api::deviceTokenApplePushVoIP::ID: {
auto device_token = static_cast<td_api::deviceTokenApplePushVoIP *>(device_token_ptr.get());
token = std::move(device_token->device_token_);
token_type = TokenType::APNS_VOIP;
token_type = TokenType::ApnsVoip;
is_app_sandbox = device_token->is_app_sandbox_;
encrypt = device_token->encrypt_;
break;
@ -205,19 +205,19 @@ void DeviceTokenManager::register_device(tl_object_ptr<td_api::DeviceToken> devi
}));
}));
}
token_type = TokenType::WEB_PUSH;
token_type = TokenType::WebPush;
break;
}
case td_api::deviceTokenMicrosoftPushVoIP::ID: {
auto device_token = static_cast<td_api::deviceTokenMicrosoftPushVoIP *>(device_token_ptr.get());
token = std::move(device_token->channel_uri_);
token_type = TokenType::MPNS_VOIP;
token_type = TokenType::MpnsVoip;
break;
}
case td_api::deviceTokenTizenPush::ID: {
auto device_token = static_cast<td_api::deviceTokenTizenPush *>(device_token_ptr.get());
token = std::move(device_token->reg_id_);
token_type = TokenType::TIZEN;
token_type = TokenType::Tizen;
break;
}
default:
@ -273,7 +273,7 @@ void DeviceTokenManager::register_device(tl_object_ptr<td_api::DeviceToken> devi
}
void DeviceTokenManager::reregister_device() {
for (int32 token_type = 1; token_type < TokenType::SIZE; token_type++) {
for (int32 token_type = 1; token_type < TokenType::Size; token_type++) {
auto &token = tokens_[token_type];
if (token.state == TokenInfo::State::Sync && !token.token.empty()) {
token.state = TokenInfo::State::Reregister;
@ -284,7 +284,7 @@ void DeviceTokenManager::reregister_device() {
vector<std::pair<int64, Slice>> DeviceTokenManager::get_encryption_keys() const {
vector<std::pair<int64, Slice>> result;
for (int32 token_type = 1; token_type < TokenType::SIZE; token_type++) {
for (int32 token_type = 1; token_type < TokenType::Size; token_type++) {
auto &info = tokens_[token_type];
if (!info.token.empty() && info.state != TokenInfo::State::Unregister) {
if (info.encrypt) {
@ -302,7 +302,7 @@ string DeviceTokenManager::get_database_key(int32 token_type) {
}
void DeviceTokenManager::start_up() {
for (int32 token_type = 1; token_type < TokenType::SIZE; token_type++) {
for (int32 token_type = 1; token_type < TokenType::Size; token_type++) {
auto serialized = G()->td_db()->get_binlog_pmc()->get(get_database_key(token_type));
if (serialized.empty()) {
continue;
@ -360,7 +360,7 @@ void DeviceTokenManager::loop() {
if (sync_cnt_ != 0 || G()->close_flag()) {
return;
}
for (int32 token_type = 1; token_type < TokenType::SIZE; token_type++) {
for (int32 token_type = 1; token_type < TokenType::Size; token_type++) {
auto &info = tokens_[token_type];
if (info.state == TokenInfo::State::Sync) {
continue;
@ -387,7 +387,7 @@ void DeviceTokenManager::loop() {
void DeviceTokenManager::on_result(NetQueryPtr net_query) {
auto token_type = static_cast<TokenType>(get_link_token());
CHECK(token_type >= 1 && token_type < TokenType::SIZE);
CHECK(token_type >= 1 && token_type < TokenType::Size);
auto &info = tokens_[token_type];
if (info.net_query_id != net_query->id()) {
net_query->clear();

View File

@ -36,19 +36,19 @@ class DeviceTokenManager final : public NetQueryCallback {
private:
ActorShared<> parent_;
enum TokenType : int32 {
APNS = 1,
FCM = 2,
MPNS = 3,
SIMPLE_PUSH = 4,
UBUNTU_PHONE = 5,
BLACKBERRY = 6,
UNUSED = 7,
WNS = 8,
APNS_VOIP = 9,
WEB_PUSH = 10,
MPNS_VOIP = 11,
TIZEN = 12,
SIZE
Apns = 1,
Fcm = 2,
Mpns = 3,
SimplePush = 4,
UbuntuPhone = 5,
BlackBerry = 6,
Unused = 7,
Wns = 8,
ApnsVoip = 9,
WebPush = 10,
MpnsVoip = 11,
Tizen = 12,
Size
};
struct TokenInfo {
enum class State : int32 { Sync, Unregister, Register, Reregister };
@ -73,7 +73,7 @@ class DeviceTokenManager final : public NetQueryCallback {
friend StringBuilder &operator<<(StringBuilder &string_builder, const TokenInfo &token_info);
std::array<TokenInfo, TokenType::SIZE> tokens_;
std::array<TokenInfo, TokenType::Size> tokens_;
int32 sync_cnt_{0};
void start_up() final;

View File

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

View File

@ -440,7 +440,7 @@ 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) {
auto my_layer = static_cast<int32>(SecretChatLayer::MY_LAYER);
auto my_layer = static_cast<int32>(SecretChatLayer::Current);
if (config_state_.my_layer < my_layer) {
send_action(secret_api::make_object<secret_api::decryptedMessageActionNotifyLayer>(my_layer), SendFlag::None,
Promise<>());
@ -846,7 +846,7 @@ 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 < static_cast<int32>(SecretChatLayer::DEFAULT_LAYER) &&
if (layer < static_cast<int32>(SecretChatLayer::Default) &&
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();
@ -856,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 >= static_cast<int32>(SecretChatLayer::MTPROTO_2_LAYER) && mtproto_version < 2) {
if (layer >= static_cast<int32>(SecretChatLayer::Mtproto2) && mtproto_version < 2) {
return Status::Error(PSLICE() << "MTProto 1.0 encryption is forbidden for this layer");
}
if (message_with_layer->in_seq_no_ < 0) {
@ -874,7 +874,7 @@ 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>(
static_cast<int32>(SecretChatLayer::MY_LAYER)),
static_cast<int32>(SecretChatLayer::Current)),
SendFlag::None, Promise<>());
if (config_state_.his_layer == 8) {
@ -1848,7 +1848,7 @@ Status SecretChatActor::on_update_chat(telegram_api::encryptedChat &update) {
context_->secret_chat_db()->set_value(auth_state_);
send_update_secret_chat();
send_action(secret_api::make_object<secret_api::decryptedMessageActionNotifyLayer>(
static_cast<int32>(SecretChatLayer::MY_LAYER)),
static_cast<int32>(SecretChatLayer::Current)),
SendFlag::None, Promise<>());
return Status::OK();
}

View File

@ -639,12 +639,12 @@ class SecretChatActor final : public NetQueryCallback {
Status save_common_info(T &update);
int32 current_layer() const {
int32 layer = static_cast<int32>(SecretChatLayer::MY_LAYER);
int32 layer = static_cast<int32>(SecretChatLayer::Current);
if (config_state_.his_layer < layer) {
layer = config_state_.his_layer;
}
if (layer < static_cast<int32>(SecretChatLayer::DEFAULT_LAYER)) {
layer = static_cast<int32>(SecretChatLayer::DEFAULT_LAYER);
if (layer < static_cast<int32>(SecretChatLayer::Default)) {
layer = static_cast<int32>(SecretChatLayer::Default);
}
return layer;
}

View File

@ -9,11 +9,11 @@
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
Default = 73,
Mtproto2 = 73,
NewEntities = 101,
DeleteMessagesOnClose = 123,
Current = DeleteMessagesOnClose
};
} // namespace td