Get info about the chosen language pack if needed.

GitOrigin-RevId: 8a522ac1eabcb66d1e5fe2d85a617ae4c823f8bb
This commit is contained in:
levlam 2019-07-11 04:22:17 +03:00
parent 8fdd8910e7
commit d69251faba
2 changed files with 40 additions and 8 deletions

View File

@ -207,6 +207,7 @@ void LanguagePackManager::start_up() {
if (language->version_ == -1) {
load_empty_language_pack(language_code_);
}
repair_chosen_language_info();
std::lock_guard<std::mutex> language_lock(language->mutex_);
base_language_code_ = language->base_language_code_;
@ -237,7 +238,7 @@ void LanguagePackManager::tear_down() {
}
}
vector<string> LanguagePackManager::get_used_language_codes() const {
vector<string> LanguagePackManager::get_used_language_codes() {
if (language_pack_.empty() || language_code_.empty()) {
return {};
}
@ -261,18 +262,24 @@ vector<string> LanguagePackManager::get_used_language_codes() const {
}
}
}
CHECK(info != nullptr);
vector<string> result;
if (language_code_.size() <= 2) {
result.push_back(language_code_);
}
if (info == nullptr) {
LOG(ERROR) << "Failed to find information about chosen language " << language_code_;
if (!is_custom_language_code(language_code_)) {
search_language_info(language_code_, Auto());
}
} else {
if (!info->base_language_code_.empty()) {
result.push_back(info->base_language_code_);
}
if (!info->plural_code_.empty()) {
result.push_back(info->plural_code_);
}
}
return result;
}
@ -436,6 +443,7 @@ void LanguagePackManager::inc_generation() {
CHECK(check_language_code_name(language_code_));
auto language = add_language(database_, language_pack_, language_code_);
on_language_pack_version_changed(false, std::numeric_limits<int32>::max());
repair_chosen_language_info();
{
std::lock_guard<std::mutex> lock(language->mutex_);
@ -817,6 +825,28 @@ void LanguagePackManager::search_language_info(string language_code,
std::move(request_promise));
}
void LanguagePackManager::repair_chosen_language_info() {
CHECK(!language_pack_.empty() && !language_code_.empty());
if (is_custom_language_code(language_code_)) {
return;
}
std::lock_guard<std::mutex> packs_lock(database_->mutex_);
auto pack_it = database_->language_packs_.find(language_pack_);
CHECK(pack_it != database_->language_packs_.end());
LanguagePack *pack = pack_it->second.get();
std::lock_guard<std::mutex> languages_lock(pack->mutex_);
for (auto &server_info : pack->server_language_pack_infos_) {
if (server_info.first == language_code_) {
return;
}
}
LOG(INFO) << "Repair info about language " << language_code_;
search_language_info(language_code_, Auto());
}
td_api::object_ptr<td_api::languagePackInfo> LanguagePackManager::get_language_pack_info_object(
const string &language_code, const LanguageInfo &info) {
return td_api::make_object<td_api::languagePackInfo>(language_code, info.base_language_code_, info.name_,

View File

@ -43,7 +43,7 @@ class LanguagePackManager : public NetQueryCallback {
static bool is_custom_language_code(Slice language_code);
vector<string> get_used_language_codes() const;
vector<string> get_used_language_codes();
void on_language_pack_changed();
@ -153,6 +153,8 @@ class LanguagePackManager : public NetQueryCallback {
void inc_generation();
void repair_chosen_language_info();
static bool is_valid_key(Slice key);
void save_strings_to_database(SqliteKeyValue *kv, int32 new_version, bool new_is_full, int32 new_key_count,