From 65f968ec1b56294f5285450335d57fb1f6fd5a35 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 25 Apr 2018 13:24:48 +0400 Subject: [PATCH] Update API scheme to layer 78. --- Telegram/Resources/scheme.tl | 7 +- Telegram/SourceFiles/apiwrap.cpp | 5 +- .../codegen/scheme/codegen_scheme.py | 18 ++- Telegram/SourceFiles/config.h | 16 +- .../SourceFiles/data/data_notify_settings.cpp | 39 +---- .../SourceFiles/mtproto/config_loader.cpp | 4 +- Telegram/SourceFiles/mtproto/connection.cpp | 3 +- Telegram/SourceFiles/mtproto/dc_options.cpp | 144 +++++++++++++++--- Telegram/SourceFiles/mtproto/dc_options.h | 24 ++- Telegram/SourceFiles/storage/localstorage.cpp | 14 +- 10 files changed, 194 insertions(+), 80 deletions(-) diff --git a/Telegram/Resources/scheme.tl b/Telegram/Resources/scheme.tl index c92b4f89f..7f357c3a5 100644 --- a/Telegram/Resources/scheme.tl +++ b/Telegram/Resources/scheme.tl @@ -220,7 +220,7 @@ userStatusLastMonth#77ebc742 = UserStatus; chatEmpty#9ba2d800 id:int = Chat; chat#d91cdd54 flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true admins_enabled:flags.3?true admin:flags.4?true deactivated:flags.5?true id:int title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel = Chat; chatForbidden#7328bdb id:int title:string = Chat; -channel#450b7115 flags:# creator:flags.0?true left:flags.2?true editor:flags.3?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights participants_count:flags.17?int = Chat; +channel#c88974ac flags:# creator:flags.0?true left:flags.2?true editor:flags.3?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights participants_count:flags.17?int = Chat; channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat; chatFull#2e02a614 id:int participants:ChatParticipants chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector = ChatFull; @@ -306,7 +306,6 @@ inputPeerNotifySettings#38935eb2 flags:# show_previews:flags.0?true silent:flags peerNotifyEventsEmpty#add53cb3 = PeerNotifyEvents; peerNotifyEventsAll#6d1ded88 = PeerNotifyEvents; -peerNotifySettingsEmpty#70a68512 = PeerNotifySettings; peerNotifySettings#9acda4c0 flags:# show_previews:flags.0?true silent:flags.1?true mute_until:int sound:string = PeerNotifySettings; peerSettings#818426cd flags:# report_spam:flags.0?true = PeerSettings; @@ -461,7 +460,7 @@ photos.photo#20212ca8 photo:Photo users:Vector = photos.Photo; upload.file#96a18d5 type:storage.FileType mtime:int bytes:bytes = upload.File; upload.fileCdnRedirect#f18cda44 dc_id:int file_token:bytes encryption_key:bytes encryption_iv:bytes file_hashes:Vector = upload.File; -dcOption#5d8c6cc flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int = DcOption; +dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption; config#86b5778e flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config; @@ -1220,4 +1219,4 @@ langpack.getStrings#2e1ee318 lang_code:string keys:Vector = Vector; -// LAYER 76 +// LAYER 78 diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 30ff7c43a..edfaf99c0 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1623,7 +1623,10 @@ void ApiWrap::requestNotifySetting(PeerData *peer) { notifySettingReceived(notifyPeer, result); _notifySettingRequests.remove(peer); }).fail([this, notifyPeer, peer](const RPCError &error) { - notifySettingReceived(notifyPeer, MTP_peerNotifySettingsEmpty()); + notifySettingReceived(notifyPeer, MTP_peerNotifySettings( + MTP_flags(MTPDpeerNotifySettings::Flag::f_show_previews), + MTP_int(0), + MTP_string("default"))); _notifySettingRequests.remove(peer); }).send(); diff --git a/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py b/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py index 4a53a5aec..80de3beea 100644 --- a/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py +++ b/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py @@ -54,7 +54,13 @@ addChildParentFlags('MTPDchannelForbidden', 'MTPDchannel'); # each key flag of parentFlags should be a subset of the value flag here parentFlagsCheck = {}; +countedTypeIdExceptions = {}; +countedTypeIdExceptions[77] = countedTypeIdExceptions[78] = {} +countedTypeIdExceptions[77]['channel'] = countedTypeIdExceptions[78]['channel'] = True + +lines = []; layer = ''; +layerIndex = 0; funcs = 0 types = 0; consts = 0 @@ -83,7 +89,12 @@ with open(input_file) as f: for line in f: layerline = re.match(r'// LAYER (\d+)', line) if (layerline): - layer = 'constexpr auto CurrentLayer = mtpPrime(' + layerline.group(1) + ');'; + layerIndex = int(layerline.group(1)); + layer = 'constexpr auto CurrentLayer = mtpPrime(' + str(layerIndex) + ');'; + else: + lines.append(line); + +for line in lines: nocomment = re.match(r'^(.*?)//', line) if (nocomment): line = nocomment.group(1); @@ -131,8 +142,9 @@ with open(input_file) as f: if (typeid and len(typeid) > 0): typeid = '0x' + typeid; if (typeid != countTypeId): - print('Warning: counted ' + countTypeId + ' mismatch with provided ' + typeid + ' (' + cleanline + ')'); - continue; + if (not layerIndex in countedTypeIdExceptions or not name in countedTypeIdExceptions[layerIndex]): + print('Warning: counted ' + countTypeId + ' mismatch with provided ' + typeid + ' (' + cleanline + ')'); + continue; else: typeid = countTypeId; diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index d07c18c69..17cff201b 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -152,11 +152,11 @@ static const BuiltInDc _builtInDcs[] = { }; static const BuiltInDc _builtInDcsIPv6[] = { - { 1, "2001:b28:f23d:f001::a", 443 }, - { 2, "2001:67c:4e8:f002::a", 443 }, - { 3, "2001:b28:f23d:f003::a", 443 }, - { 4, "2001:67c:4e8:f004::a", 443 }, - { 5, "2001:b28:f23f:f005::a", 443 } + { 1, "2001:0b28:f23d:f001:0000:0000:0000:000a", 443 }, + { 2, "2001:067c:04e8:f002:0000:0000:0000:000a", 443 }, + { 3, "2001:0b28:f23d:f003:0000:0000:0000:000a", 443 }, + { 4, "2001:067c:04e8:f004:0000:0000:0000:000a", 443 }, + { 5, "2001:0b28:f23f:f005:0000:0000:0000:000a", 443 } }; static const BuiltInDc _builtInTestDcs[] = { @@ -166,9 +166,9 @@ static const BuiltInDc _builtInTestDcs[] = { }; static const BuiltInDc _builtInTestDcsIPv6[] = { - { 1, "2001:b28:f23d:f001::e", 443 }, - { 2, "2001:67c:4e8:f002::e", 443 }, - { 3, "2001:b28:f23d:f003::e", 443 } + { 1, "2001:0b28:f23d:f001:0000:0000:0000:000e", 443 }, + { 2, "2001:067c:04e8:f002:0000:0000:0000:000e", 443 }, + { 3, "2001:0b28:f23d:f003:0000:0000:0000:000e", 443 } }; inline const BuiltInDc *builtInDcs() { diff --git a/Telegram/SourceFiles/data/data_notify_settings.cpp b/Telegram/SourceFiles/data/data_notify_settings.cpp index f6a56ad2e..aa0cf5e91 100644 --- a/Telegram/SourceFiles/data/data_notify_settings.cpp +++ b/Telegram/SourceFiles/data/data_notify_settings.cpp @@ -114,28 +114,15 @@ MTPinputPeerNotifySettings NotifySettingsValue::serialize() const { } bool NotifySettings::change(const MTPPeerNotifySettings &settings) { - switch (settings.type()) { - case mtpc_peerNotifySettingsEmpty: { - if (!_known || _value) { - _known = true; - _value = nullptr; - return true; - } - return false; - } break; + Expects(settings.type() == mtpc_peerNotifySettings); - case mtpc_peerNotifySettings: { - auto &data = settings.c_peerNotifySettings(); - if (_value) { - return _value->change(data); - } - _known = true; - _value = std::make_unique(data); - return true; - } break; + auto &data = settings.c_peerNotifySettings(); + if (_value) { + return _value->change(data); } - - Unexpected("Type in NotifySettings::change()"); + _known = true; + _value = std::make_unique(data); + return true; } NotifySettings::NotifySettings() = default; @@ -152,18 +139,6 @@ bool NotifySettings::change( if (_value) { return _value->change(mute, silent, muteForSeconds); } - const auto asEmpty = [&] { - if (mute == MuteChange::Mute) { - return false; - } - if (silent == SilentPostsChange::Silent) { - return false; - } - return true; - }(); - if (asEmpty) { - return change(MTP_peerNotifySettingsEmpty()); - } const auto flags = MTPDpeerNotifySettings::Flag::f_show_previews | ((silent == SilentPostsChange::Silent) ? MTPDpeerNotifySettings::Flag::f_silent diff --git a/Telegram/SourceFiles/mtproto/config_loader.cpp b/Telegram/SourceFiles/mtproto/config_loader.cpp index eec1b6fad..4305ccd99 100644 --- a/Telegram/SourceFiles/mtproto/config_loader.cpp +++ b/Telegram/SourceFiles/mtproto/config_loader.cpp @@ -139,13 +139,15 @@ void ConfigLoader::sendSpecialRequest() { const auto weak = base::make_weak(this); const auto index = rand_value() % _specialEndpoints.size(); + const auto secret = bytes::vector(); const auto endpoint = _specialEndpoints.begin() + index; _specialEnumCurrent = specialToRealDcId(endpoint->dcId); _instance->dcOptions()->constructAddOne( _specialEnumCurrent, MTPDdcOption::Flag::f_tcpo_only, endpoint->ip, - endpoint->port); + endpoint->port, + secret); _specialEnumRequest = _instance->send( MTPhelp_GetConfig(), rpcDone([weak](const MTPConfig &result) { diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index a901de64e..3cc16adce 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -362,7 +362,8 @@ void ConnectionPrivate::appendTestConnection( QWriteLocker lock(&stateConnMutex); const auto priority = (qthelp::is_ipv6(ip) ? 0 : 1) - + (protocol == DcOptions::Variants::Tcp ? 1 : 0); + + (protocol == DcOptions::Variants::Tcp ? 1 : 0) + + (protocolSecret.empty() ? 0 : 1); _testConnections.push_back({ AbstractConnection::create(protocol, thread()), priority diff --git a/Telegram/SourceFiles/mtproto/dc_options.cpp b/Telegram/SourceFiles/mtproto/dc_options.cpp index 238d721db..d9f97c3a8 100644 --- a/Telegram/SourceFiles/mtproto/dc_options.cpp +++ b/Telegram/SourceFiles/mtproto/dc_options.cpp @@ -112,7 +112,7 @@ void DcOptions::constructFromBuiltIn() { idWithShift, std::vector