Skip to content

Commit

Permalink
Add td_api::editCustomLanguageInfo.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: df4919a0b4b781751be4f6eb60063ddd48560741
  • Loading branch information
levlam committed Aug 31, 2018
1 parent d125e11 commit 3022046
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 3 deletions.
3 changes: 3 additions & 0 deletions td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -3139,6 +3139,9 @@ getLanguagePackStrings language_code:string keys:vector<string> = LanguagePackSt
//@description Adds or changes a custom language to the used language pack @info Information about the language. Language code must start with 'X', consist only of English letters, digits and hyphens and be not longer than 64 characters @strings New language pack strings
setCustomLanguage info:languageInfo strings:vector<languagePackString> = Ok;

//@description Edits informatioan about a custom language @info New information about the custom language
editCustomLanguageInfo info:languageInfo = Ok;

//@description Sets new value for a string in a custom language in the used language pack @language_code The code of previously added custom language, must start with 'X' @new_string New language pack string
setCustomLanguageString language_code:string new_string:languagePackString = Ok;

Expand Down
Binary file modified td/generate/scheme/td_api.tlo
Binary file not shown.
36 changes: 33 additions & 3 deletions td/telegram/LanguagePackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,10 +1066,40 @@ void LanguagePackManager::set_custom_language(string language_code, string langu
CHECK(pack_it != database_->language_packs_.end());
LanguagePack *pack = pack_it->second.get();
auto &info = pack->language_infos_[language_code];
info.name = language_name;
info.native_name = language_native_name;
info.name = std::move(language_name);
info.native_name = std::move(language_native_name);
if (!pack->pack_kv_.empty()) {
pack->pack_kv_.set(language_code, PSLICE() << language_name << '\x00' << language_native_name);
pack->pack_kv_.set(language_code, PSLICE() << info.name << '\x00' << info.native_name);
}

promise.set_value(Unit());
}

void LanguagePackManager::edit_custom_language_info(string language_code, string language_name,
string language_native_name, Promise<Unit> &&promise) {
if (language_pack_.empty()) {
return promise.set_error(Status::Error(400, "Option \"language_pack\" needs to be set first"));
}
if (!check_language_code_name(language_code)) {
return promise.set_error(Status::Error(400, "Language code name must contain only letters and hyphen"));
}
if (!is_custom_language_code(language_code)) {
return promise.set_error(Status::Error(400, "Custom language code must begin with 'X'"));
}

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();
auto language_info_it = pack->language_infos_.find(language_code);
if (language_info_it == pack->language_infos_.end()) {
return promise.set_error(Status::Error(400, "Custom language pack is not found"));
}
auto &info = language_info_it->second;
info.name = std::move(language_name);
info.native_name = std::move(language_native_name);
if (!pack->pack_kv_.empty()) {
pack->pack_kv_.set(language_code, PSLICE() << info.name << '\x00' << info.native_name);
}

promise.set_value(Unit());
Expand Down
3 changes: 3 additions & 0 deletions td/telegram/LanguagePackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class LanguagePackManager : public NetQueryCallback {
void set_custom_language(string language_code, string language_name, string language_native_name,
vector<tl_object_ptr<td_api::languagePackString>> strings, Promise<Unit> &&promise);

void edit_custom_language_info(string language_code, string language_name, string language_native_name,
Promise<Unit> &&promise);

void set_custom_language_string(string language_code, tl_object_ptr<td_api::languagePackString> str,
Promise<Unit> &&promise);

Expand Down
14 changes: 14 additions & 0 deletions td/telegram/Td.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,7 @@ bool Td::is_preauthentication_request(int32 id) {
case td_api::getLanguagePackInfo::ID:
case td_api::getLanguagePackStrings::ID:
case td_api::setCustomLanguage::ID:
case td_api::editCustomLanguageInfo::ID:
case td_api::setCustomLanguageString::ID:
case td_api::deleteLanguage::ID:
case td_api::getOption::ID:
Expand Down Expand Up @@ -6054,6 +6055,19 @@ void Td::on_request(uint64 id, td_api::setCustomLanguage &request) {
std::move(promise));
}

void Td::on_request(uint64 id, td_api::editCustomLanguageInfo &request) {
CHECK_IS_USER();
if (request.info_ == nullptr) {
return send_error_raw(id, 400, "Language info must not be empty");
}
CLEAN_INPUT_STRING(request.info_->code_);
CLEAN_INPUT_STRING(request.info_->name_);
CLEAN_INPUT_STRING(request.info_->native_name_);
CREATE_OK_REQUEST_PROMISE();
send_closure(language_pack_manager_, &LanguagePackManager::edit_custom_language_info, std::move(request.info_->code_),
std::move(request.info_->name_), std::move(request.info_->native_name_), std::move(promise));
}

void Td::on_request(uint64 id, td_api::setCustomLanguageString &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.language_code_);
Expand Down
2 changes: 2 additions & 0 deletions td/telegram/Td.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ class Td final : public NetQueryCallback {

void on_request(uint64 id, td_api::setCustomLanguage &request);

void on_request(uint64 id, td_api::editCustomLanguageInfo &request);

void on_request(uint64 id, td_api::setCustomLanguageString &request);

void on_request(uint64 id, td_api::deleteLanguage &request);
Expand Down
10 changes: 10 additions & 0 deletions td/telegram/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,16 @@ class CliClient final : public Actor {

send_request(make_tl_object<td_api::setCustomLanguage>(
make_tl_object<td_api::languageInfo>(language_code, name, native_name, 3), std::move(strings)));
} else if (op == "ecli") {
string language_code;
string name;
string native_name;

std::tie(language_code, args) = split(args);
std::tie(name, native_name) = split(args);

send_request(make_tl_object<td_api::editCustomLanguageInfo>(
make_tl_object<td_api::languageInfo>(language_code, name, native_name, 3)));
} else if (op == "sclsv" || op == "sclsp" || op == "sclsd") {
string language_code;
string key;
Expand Down

0 comments on commit 3022046

Please sign in to comment.