Update API scheme.

This commit is contained in:
John Preston 2018-08-20 14:31:40 +03:00
parent 34eb834d94
commit 5b88f4d3d2
10 changed files with 80 additions and 20 deletions

View File

@ -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> = 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<int> = 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<string> = Vector<LangPackString>;
langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference;
langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector<string> = Vector<LangPackString>;
langpack.getDifference#b2e4d7d from_version:int = LangPackDifference;
langpack.getLanguages#800fd57d = Vector<LangPackLanguage>;
langpack.getLanguages#42c6978f lang_pack:string = Vector<LangPackLanguage>;
// LAYER 85

View File

@ -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<MTPstring>(1, MTP_string("lng_switch_to_this"))
)).done([=](const MTPVector<MTPLangPackString> &result) {

View File

@ -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<MTPLangPackLanguage> &result) {
_languagesRequestId = request(MTPlangpack_GetLanguages(
MTP_string(CloudLangPackName())
)).done([=](const MTPVector<MTPLangPackLanguage> &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<MTPstring>(std::move(keys)))).done([this, id](const MTPVector<MTPLangPackString> &result) {
_switchingToLanguageRequest = request(MTPlangpack_GetStrings(
MTP_string(Lang::CloudLangPackName()),
MTP_string(id),
MTP_vector<MTPstring>(std::move(keys))
)).done([=](const MTPVector<MTPLangPackString> &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);

View File

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

View File

@ -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<LangKey, QString> ParseStrings(const MTPVector<MTPLangPackString> &strings);
static std::map<LangKey, QString> ParseStrings(
const MTPVector<MTPLangPackString> &strings);
base::Observable<void> &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 <typename SetCallback, typename ResetCallback>
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 <typename Result>
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;

View File

@ -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());

View File

@ -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();
}

View File

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

View File

@ -30,6 +30,7 @@ QString LogIds(const QVector<uint64> &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,

View File

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