diff --git a/Telegram/Resources/scheme.tl b/Telegram/Resources/scheme.tl index 7125ec24a..485fdc5fe 100644 --- a/Telegram/Resources/scheme.tl +++ b/Telegram/Resources/scheme.tl @@ -1039,6 +1039,9 @@ inputCheckPasswordSRP#d27ff082 srp_id:long A:bytes M1:bytes = InputCheckPassword secureRequiredType#829d99da flags:# native_names:flags.0?true selfie_required:flags.1?true translation_required:flags.2?true type:SecureValueType = SecureRequiredType; secureRequiredTypeOneOf#27477b4 types:Vector = SecureRequiredType; +help.passportConfigNotModified#bfb9f457 = help.PassportConfig; +help.passportConfig#a098d6af hash:int countries_langs:DataJSON = help.PassportConfig; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1263,6 +1266,7 @@ help.getProxyData#3d7758e1 = help.ProxyData; help.getTermsOfServiceUpdate#2ca51fd1 = help.TermsOfServiceUpdate; help.acceptTermsOfService#ee72f79a id:DataJSON = Bool; help.getDeepLinkInfo#3fedc75f path:string = help.DeepLinkInfo; +help.getPassportConfig#c661ad08 hash:int = help.PassportConfig; channels.readHistory#cc104937 channel:InputChannel max_id:int = Bool; channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector = messages.AffectedMessages; @@ -1322,9 +1326,9 @@ phone.discardCall#78d413a6 peer:InputPhoneCall duration:int reason:PhoneCallDisc phone.setCallRating#1c536a34 peer:InputPhoneCall rating:int comment:string = Updates; phone.saveCallDebug#277add7e peer:InputPhoneCall debug:DataJSON = Bool; -langpack.getLangPack#9ab5c58e lang_code:string = LangPackDifference; -langpack.getStrings#2e1ee318 lang_code:string keys:Vector = Vector; +langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference; +langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector = Vector; langpack.getDifference#b2e4d7d from_version:int = LangPackDifference; -langpack.getLanguages#800fd57d = Vector; +langpack.getLanguages#42c6978f lang_pack:string = Vector; // LAYER 85 diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index d7a2b1d7d..ec099af23 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -136,6 +136,7 @@ void Widget::createLanguageLink() { createLink(Lang::GetOriginalValue(lng_switch_to_this), defaultId); } else if (!suggestedId.isEmpty() && suggestedId != currentId) { request(MTPlangpack_GetStrings( + MTP_string(Lang::CloudLangPackName()), MTP_string(suggestedId), MTP_vector(1, MTP_string("lng_switch_to_this")) )).done([=](const MTPVector &result) { diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index 76321246d..09f1f7366 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -32,17 +32,22 @@ void CloudManager::requestLangPackDifference() { auto version = _langpack.version(); if (version > 0) { - _langPackRequestId = request(MTPlangpack_GetDifference(MTP_int(version))).done([this](const MTPLangPackDifference &result) { + _langPackRequestId = request(MTPlangpack_GetDifference( + MTP_int(version) + )).done([=](const MTPLangPackDifference &result) { _langPackRequestId = 0; applyLangPackDifference(result); - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { _langPackRequestId = 0; }).send(); } else { - _langPackRequestId = request(MTPlangpack_GetLangPack(MTP_string(_langpack.cloudLangCode()))).done([this](const MTPLangPackDifference &result) { + _langPackRequestId = request(MTPlangpack_GetLangPack( + MTP_string(CloudLangPackName()), + MTP_string(_langpack.cloudLangCode()) + )).done([=](const MTPLangPackDifference &result) { _langPackRequestId = 0; applyLangPackDifference(result); - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { _langPackRequestId = 0; }).send(); } @@ -100,7 +105,9 @@ void CloudManager::applyLangPackDifference(const MTPLangPackDifference &differen } void CloudManager::requestLanguageList() { - _languagesRequestId = request(MTPlangpack_GetLanguages()).done([this](const MTPVector &result) { + _languagesRequestId = request(MTPlangpack_GetLanguages( + MTP_string(CloudLangPackName()) + )).done([=](const MTPVector &result) { auto languages = Languages(); for_const (auto &langData, result.v) { Assert(langData.type() == mtpc_langPackLanguage); @@ -112,7 +119,7 @@ void CloudManager::requestLanguageList() { _languagesChanged.notify(); } _languagesRequestId = 0; - }).fail([this](const RPCError &error) { + }).fail([=](const RPCError &error) { _languagesRequestId = 0; }).send(); } @@ -212,11 +219,17 @@ void CloudManager::switchToLanguage(QString id) { keys.push_back(MTP_string("lng_sure_save_language")); keys.push_back(MTP_string("lng_box_ok")); keys.push_back(MTP_string("lng_cancel")); - _switchingToLanguageRequest = request(MTPlangpack_GetStrings(MTP_string(id), MTP_vector(std::move(keys)))).done([this, id](const MTPVector &result) { + _switchingToLanguageRequest = request(MTPlangpack_GetStrings( + MTP_string(Lang::CloudLangPackName()), + MTP_string(id), + MTP_vector(std::move(keys)) + )).done([=](const MTPVector &result) { auto values = Instance::ParseStrings(result); auto getValue = [&values](LangKey key) { auto it = values.find(key); - return (it == values.cend()) ? GetOriginalValue(key) : it->second; + return (it == values.cend()) + ? GetOriginalValue(key) + : it->second; }; auto text = getValue(lng_sure_save_language); auto save = getValue(lng_box_ok); diff --git a/Telegram/SourceFiles/lang/lang_instance.cpp b/Telegram/SourceFiles/lang/lang_instance.cpp index e5831490a..9297b472c 100644 --- a/Telegram/SourceFiles/lang/lang_instance.cpp +++ b/Telegram/SourceFiles/lang/lang_instance.cpp @@ -19,14 +19,19 @@ namespace Lang { namespace { constexpr auto kDefaultLanguage = str_const("en"); +constexpr auto kCloudLangPackName = str_const("tdesktop"); constexpr auto kLangValuesLimit = 20000; class ValueParser { public: - ValueParser(const QByteArray &key, LangKey keyIndex, const QByteArray &value); + ValueParser( + const QByteArray &key, + LangKey keyIndex, + const QByteArray &value); QString takeResult() { Expects(!_failed); + return std::move(_result); } @@ -164,6 +169,10 @@ QString DefaultLanguageId() { return str_const_toString(kDefaultLanguage); } +QString CloudLangPackName() { + return str_const_toString(kCloudLangPackName); +} + void Instance::switchToId(const QString &id) { reset(); _id = id; @@ -228,6 +237,10 @@ QString Instance::cloudLangCode() const { return id(); } +QString Instance::langPackName() const { + return isCustom() ? QString() : CloudLangPackName(); +} + QByteArray Instance::serialize() const { auto size = Serialize::stringSize(_id); size += sizeof(qint32); // version @@ -462,7 +475,9 @@ void Instance::applyValue(const QByteArray &key, const QByteArray &value) { void Instance::updatePluralRules() { auto id = _id; if (isCustom()) { - auto path = _customFilePathAbsolute.isEmpty() ? _customFilePathRelative : _customFilePathAbsolute; + auto path = _customFilePathAbsolute.isEmpty() + ? _customFilePathRelative + : _customFilePathAbsolute; auto name = QFileInfo(path).fileName(); if (auto match = qthelp::regex_match("_([a-z]{2,3})(_[A-Z]{2,3}|\\-[a-z]{2,3})?\\.", name)) { id = match->captured(1); diff --git a/Telegram/SourceFiles/lang/lang_instance.h b/Telegram/SourceFiles/lang/lang_instance.h index ea630122b..586e1d9fc 100644 --- a/Telegram/SourceFiles/lang/lang_instance.h +++ b/Telegram/SourceFiles/lang/lang_instance.h @@ -32,6 +32,7 @@ inline QString ConvertLegacyLanguageId(const QString &languageId) { } QString DefaultLanguageId(); +QString CloudLangPackName(); class Instance; Instance &Current(); @@ -53,12 +54,15 @@ public: QString systemLangCode() const; QString cloudLangCode() const; + QString langPackName() const; QString id() const { return _id; } bool isCustom() const { - return (_id == qstr("custom") || _id == qstr("TEST_X") || _id == qstr("TEST_0")); + return (_id == qstr("custom") + || _id == qstr("TEST_X") + || _id == qstr("TEST_0")); } int version() const { return _version; @@ -69,7 +73,8 @@ public: void fillFromLegacy(int legacyId, const QString &legacyPath); void applyDifference(const MTPDlangPackDifference &difference); - static std::map ParseStrings(const MTPVector &strings); + static std::map ParseStrings( + const MTPVector &strings); base::Observable &updated() { return _updated; } @@ -77,11 +82,13 @@ public: QString getValue(LangKey key) const { Expects(key >= 0 && key < kLangKeysCount); Expects(_values.size() == kLangKeysCount); + return _values[key]; } bool isNonDefaultPlural(LangKey key) const { Expects(key >= 0 && key < kLangKeysCount); Expects(_nonDefaultSet.size() == kLangKeysCount); + return _nonDefaultSet[key] || _nonDefaultSet[key + 1] || _nonDefaultSet[key + 2] @@ -95,11 +102,17 @@ private: // It is called for all key-value pairs in string. // ResetCallback takes one QByteArray: key. template - static void HandleString(const MTPLangPackString &mtpString, SetCallback setCallback, ResetCallback resetCallback); + static void HandleString( + const MTPLangPackString &mtpString, + SetCallback setCallback, + ResetCallback resetCallback); // Writes each key-value pair in the result container. template - static LangKey ParseKeyValue(const QByteArray &key, const QByteArray &value, Result &result); + static LangKey ParseKeyValue( + const QByteArray &key, + const QByteArray &value, + Result &result); void applyValue(const QByteArray &key, const QByteArray &value); void resetValue(const QByteArray &key); @@ -107,7 +120,10 @@ private: void fillDefaults(); void fillFromCustomFile(const QString &filePath); void loadFromContent(const QByteArray &content); - void loadFromCustomContent(const QString &absolutePath, const QString &relativePath, const QByteArray &content); + void loadFromCustomContent( + const QString &absolutePath, + const QString &relativePath, + const QByteArray &content); void updatePluralRules(); QString _id; diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index b27cb877c..96284301a 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -817,7 +817,7 @@ void ConnectionPrivate::tryToSend() { Assert(_connectionOptions != nullptr); const auto systemLangCode = _connectionOptions->systemLangCode; const auto cloudLangCode = _connectionOptions->cloudLangCode; - const auto langPack = "tdesktop"; + const auto langPackName = _connectionOptions->langPackName; const auto deviceModel = (_dcType == DcType::Cdn) ? "n/a" : Messenger::Instance().launcher()->deviceModel(); @@ -845,7 +845,7 @@ void ConnectionPrivate::tryToSend() { MTP_string(systemVersion), MTP_string(appVersion), MTP_string(systemLangCode), - MTP_string(langPack), + MTP_string(langPackName), MTP_string(cloudLangCode), clientProxyFields, SecureRequest()); diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 3697280e6..adac1e111 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -1524,6 +1524,10 @@ QString Instance::cloudLangCode() const { return Lang::Current().cloudLangCode(); } +QString Instance::langPackName() const { + return Lang::Current().langPackName(); +} + void Instance::requestConfig() { _private->requestConfig(); } diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.h b/Telegram/SourceFiles/mtproto/mtp_instance.h index be489553b..bc39e9d6e 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.h +++ b/Telegram/SourceFiles/mtproto/mtp_instance.h @@ -53,6 +53,7 @@ public: DcId mainDcId() const; QString systemLangCode() const; QString cloudLangCode() const; + QString langPackName() const; void setKeyForWrite(DcId dcId, const AuthKeyPtr &key); AuthKeysList getKeysForWrite() const; diff --git a/Telegram/SourceFiles/mtproto/session.cpp b/Telegram/SourceFiles/mtproto/session.cpp index c0bec07af..b055c382f 100644 --- a/Telegram/SourceFiles/mtproto/session.cpp +++ b/Telegram/SourceFiles/mtproto/session.cpp @@ -30,6 +30,7 @@ QString LogIds(const QVector &ids) { ConnectionOptions::ConnectionOptions( const QString &systemLangCode, const QString &cloudLangCode, + const QString &langPackName, const ProxyData &proxy, bool useIPv4, bool useIPv6, @@ -37,6 +38,7 @@ ConnectionOptions::ConnectionOptions( bool useTcp) : systemLangCode(systemLangCode) , cloudLangCode(cloudLangCode) +, langPackName(langPackName) , proxy(proxy) , useIPv4(useIPv4) , useIPv6(useIPv6) @@ -63,6 +65,7 @@ void SessionData::notifyConnectionInited(const ConnectionOptions &options) { QWriteLocker locker(&_lock); if (options.cloudLangCode == _options.cloudLangCode && options.systemLangCode == _options.systemLangCode + && options.langPackName == _options.langPackName && options.proxy == _options.proxy && !_options.inited) { _options.inited = true; @@ -178,6 +181,7 @@ void Session::refreshOptions() { data.applyConnectionOptions(ConnectionOptions( _instance->systemLangCode(), _instance->cloudLangCode(), + _instance->langPackName(), Global::UseProxy() ? proxy : ProxyData(), useIPv4, useIPv6, diff --git a/Telegram/SourceFiles/mtproto/session.h b/Telegram/SourceFiles/mtproto/session.h index ce4dbb0c2..da27be0d8 100644 --- a/Telegram/SourceFiles/mtproto/session.h +++ b/Telegram/SourceFiles/mtproto/session.h @@ -108,6 +108,7 @@ struct ConnectionOptions { ConnectionOptions( const QString &systemLangCode, const QString &cloudLangCode, + const QString &langPackName, const ProxyData &proxy, bool useIPv4, bool useIPv6, @@ -118,6 +119,7 @@ struct ConnectionOptions { QString systemLangCode; QString cloudLangCode; + QString langPackName; ProxyData proxy; bool useIPv4 = true; bool useIPv6 = true;