Add td_api::updateAnimationSearchParameters.

GitOrigin-RevId: 6f53679977437f279a10fee8b6b1069d37a4e7a6
This commit is contained in:
levlam 2020-05-30 02:42:45 +03:00
parent 4a1e2ee34c
commit 6196bab690
6 changed files with 123 additions and 2 deletions

View File

@ -3070,6 +3070,9 @@ updateUsersNearby users_nearby:vector<chatNearby> = Update;
//@description The list of supported dice emojis has changed @emojis The new list of supported dice emojis
updateDiceEmojis emojis:vector<string> = Update;
//@description The parameters of animation search through GetOption("animation_search_bot_username") bot has changed @provider Name of the animation search provider @emojis The new list of emojis suggested for searching
updateAnimationSearchParameters provider:string emojis:vector<string> = Update;
//@description A new incoming inline query; for bots only @id Unique query identifier @sender_user_id Identifier of the user who sent the query @user_location User location, provided by the client; may be null
//@query Text of the query @offset Offset of the first entry to return
updateNewInlineQuery id:int64 sender_user_id:int32 user_location:location query:string offset:string = Update;

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include "td/telegram/AnimationsManager.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h"
@ -434,6 +435,42 @@ SecretInputMedia AnimationsManager::get_secret_input_media(FileId animation_file
BufferSlice(encryption_key.iv_slice()), std::move(attributes), caption)};
}
void AnimationsManager::on_update_animation_search_emojis(string animation_search_emojis) {
if (G()->close_flag()) {
return;
}
if (td_->auth_manager_->is_bot()) {
G()->shared_config().set_option_empty("animation_search_emojis");
return;
}
is_animation_search_emojis_inited_ = true;
if (animation_search_emojis_ == animation_search_emojis) {
return;
}
animation_search_emojis_ = std::move(animation_search_emojis);
try_send_update_animation_search_parameters();
}
void AnimationsManager::on_update_animation_search_provider(string animation_search_provider) {
if (G()->close_flag()) {
return;
}
if (td_->auth_manager_->is_bot()) {
G()->shared_config().set_option_empty("animation_search_provider");
return;
}
is_animation_search_provider_inited_ = true;
if (animation_search_provider_ == animation_search_provider) {
return;
}
animation_search_provider_ = std::move(animation_search_provider);
try_send_update_animation_search_parameters();
}
void AnimationsManager::on_update_saved_animations_limit(int32 saved_animations_limit) {
if (saved_animations_limit != saved_animations_limit_) {
if (saved_animations_limit > 0) {
@ -800,6 +837,22 @@ void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::Input
send_update_saved_animations();
}
void AnimationsManager::try_send_update_animation_search_parameters() const {
auto update_animation_search_parameters = get_update_animation_search_parameters_object();
if (update_animation_search_parameters != nullptr) {
send_closure(G()->td(), &Td::send_update, std::move(update_animation_search_parameters));
}
}
td_api::object_ptr<td_api::updateAnimationSearchParameters>
AnimationsManager::get_update_animation_search_parameters_object() const {
if (!is_animation_search_emojis_inited_ || !is_animation_search_provider_inited_) {
return nullptr;
}
return td_api::make_object<td_api::updateAnimationSearchParameters>(animation_search_provider_,
full_split(animation_search_emojis_, ','));
}
td_api::object_ptr<td_api::updateSavedAnimations> AnimationsManager::get_update_saved_animations_object() const {
return td_api::make_object<td_api::updateSavedAnimations>(
td_->file_manager_->get_file_ids_object(saved_animation_ids_));
@ -868,6 +921,10 @@ void AnimationsManager::get_current_state(vector<td_api::object_ptr<td_api::Upda
if (are_saved_animations_loaded_) {
updates.push_back(get_update_saved_animations_object());
}
auto update_animation_search_parameters = get_update_animation_search_parameters_object();
if (update_animation_search_parameters != nullptr) {
updates.push_back(std::move(update_animation_search_parameters));
}
}
} // namespace td

View File

@ -57,6 +57,10 @@ class AnimationsManager : public Actor {
bool merge_animations(FileId new_id, FileId old_id, bool can_delete_old);
void on_update_animation_search_emojis(string animation_search_emojis);
void on_update_animation_search_provider(string animation_search_provider);
void on_update_saved_animations_limit(int32 saved_animations_limit);
void reload_saved_animations(bool force);
@ -124,6 +128,10 @@ class AnimationsManager : public Actor {
void on_load_saved_animations_finished(vector<FileId> &&saved_animation_ids, bool from_database = false);
void try_send_update_animation_search_parameters() const;
td_api::object_ptr<td_api::updateAnimationSearchParameters> get_update_animation_search_parameters_object() const;
td_api::object_ptr<td_api::updateSavedAnimations> get_update_saved_animations_object() const;
void send_update_saved_animations(bool from_database = false);
@ -147,6 +155,11 @@ class AnimationsManager : public Actor {
vector<Promise<Unit>> load_saved_animations_queries_;
vector<Promise<Unit>> repair_saved_animations_queries_;
FileSourceId saved_animations_file_source_id_;
string animation_search_emojis_;
string animation_search_provider_;
bool is_animation_search_emojis_inited_ = false;
bool is_animation_search_provider_inited_ = false;
};
} // namespace td

View File

@ -1289,6 +1289,8 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
vector<string> dice_emojis;
std::unordered_map<string, size_t> dice_emoji_index;
std::unordered_map<string, string> dice_emoji_success_value;
string animation_search_provider;
string animation_search_emojis;
if (config->get_id() == telegram_api::jsonObject::ID) {
for (auto &key_value : static_cast<telegram_api::jsonObject *>(config.get())->value_) {
Slice key = key_value->key_;
@ -1394,6 +1396,38 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
}
continue;
}
if (key == "gif_search_branding") {
if (value->get_id() == telegram_api::jsonString::ID) {
animation_search_provider = std::move(static_cast<telegram_api::jsonString *>(value)->value_);
} else {
LOG(ERROR) << "Receive unexpected gif_search_branding " << to_string(*value);
}
continue;
}
if (key == "gif_search_emojies") {
if (value->get_id() == telegram_api::jsonArray::ID) {
auto emojis = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
for (auto &emoji : emojis) {
CHECK(emoji != nullptr);
if (emoji->get_id() == telegram_api::jsonString::ID) {
Slice emoji_str = static_cast<telegram_api::jsonString *>(emoji.get())->value_;
if (!emoji_str.empty() && emoji_str.find(',') == Slice::npos) {
if (!animation_search_emojis.empty()) {
animation_search_emojis += ',';
}
animation_search_emojis.append(emoji_str.begin(), emoji_str.end());
} else {
LOG(ERROR) << "Receive unexpected animation search emoji " << emoji_str;
}
} else {
LOG(ERROR) << "Receive unexpected animation search emoji " << to_string(emoji);
}
}
} else {
LOG(ERROR) << "Receive unexpected gif_search_emojies " << to_string(*value);
}
continue;
}
new_values.push_back(std::move(key_value));
}
@ -1437,6 +1471,17 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
shared_config.set_option_string("dice_success_values", implode(dice_success_values, ','));
shared_config.set_option_string("dice_emojis", implode(dice_emojis, '\x01'));
}
if (animation_search_provider.empty()) {
shared_config.set_option_empty("animation_search_provider");
} else {
shared_config.set_option_string("animation_search_provider", animation_search_provider);
}
if (animation_search_emojis.empty()) {
shared_config.set_option_empty("animation_search_emojis");
} else {
shared_config.set_option_string("animation_search_emojis", animation_search_emojis);
}
}
} // namespace td

View File

@ -3545,7 +3545,7 @@ void Td::on_result(NetQueryPtr query) {
bool Td::is_internal_config_option(Slice name) {
switch (name[0]) {
case 'a':
return name == "auth";
return name == "animation_search_emojis" || name == "animation_search_provider" || name == "auth";
case 'b':
return name == "base_language_pack_version";
case 'c':
@ -3585,6 +3585,10 @@ void Td::on_config_option_updated(const string &name) {
return on_authorization_lost();
} else if (name == "saved_animations_limit") {
return animations_manager_->on_update_saved_animations_limit(G()->shared_config().get_option_integer(name));
} else if (name == "animation_search_emojis") {
return animations_manager_->on_update_animation_search_emojis(G()->shared_config().get_option_string(name));
} else if (name == "animation_search_provider") {
return animations_manager_->on_update_animation_search_provider(G()->shared_config().get_option_string(name));
} else if (name == "recent_stickers_limit") {
return stickers_manager_->on_update_recent_stickers_limit(G()->shared_config().get_option_integer(name));
} else if (name == "favorite_stickers_limit") {
@ -4452,7 +4456,6 @@ void Td::send_update(tl_object_ptr<td_api::Update> &&object) {
case td_api::updateUnreadChatCount::ID / 2:
case td_api::updateChatOnlineMemberCount::ID / 2:
case td_api::updateUserChatAction::ID / 2:
case td_api::updateDiceEmojis::ID / 2:
LOG(ERROR) << "Sending update: " << oneline(to_string(object));
break;
default: