Add disable_animated_emoji option.

This commit is contained in:
levlam 2021-10-05 17:17:29 +03:00
parent ffe03ecb10
commit eb20f82730
3 changed files with 51 additions and 23 deletions

View File

@ -1235,7 +1235,6 @@ StickersManager::StickersManager(Td *td, ActorShared<> parent) : td_(td), parent
narrow_cast<int32>(G()->shared_config().get_option_integer("recent_stickers_limit", 200))); narrow_cast<int32>(G()->shared_config().get_option_integer("recent_stickers_limit", 200)));
on_update_favorite_stickers_limit( on_update_favorite_stickers_limit(
narrow_cast<int32>(G()->shared_config().get_option_integer("favorite_stickers_limit", 5))); narrow_cast<int32>(G()->shared_config().get_option_integer("favorite_stickers_limit", 5)));
on_update_dice_emojis();
next_click_animated_emoji_message_time_ = Time::now(); next_click_animated_emoji_message_time_ = Time::now();
next_update_animated_emoji_clicked_time_ = Time::now(); next_update_animated_emoji_clicked_time_ = Time::now();
@ -1280,7 +1279,11 @@ void StickersManager::init() {
on_update_dice_success_values(); on_update_dice_success_values();
on_update_disable_animated_emojis();
if (!disable_animated_emojis_) {
load_special_sticker_set(add_special_sticker_set(SpecialStickerSetType::animated_emoji())); load_special_sticker_set(add_special_sticker_set(SpecialStickerSetType::animated_emoji()));
}
if (G()->parameters().use_file_db) { if (G()->parameters().use_file_db) {
auto old_featured_sticker_set_count_str = G()->td_db()->get_binlog_pmc()->get("old_featured_sticker_set_count"); auto old_featured_sticker_set_count_str = G()->td_db()->get_binlog_pmc()->get("old_featured_sticker_set_count");
@ -1408,17 +1411,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
CHECK(sticker_set->was_loaded); CHECK(sticker_set->was_loaded);
if (type.type_ == SpecialStickerSetType::animated_emoji()) { if (type.type_ == SpecialStickerSetType::animated_emoji()) {
vector<FullMessageId> full_message_ids; try_update_animated_emoji_messages();
for (const auto &it : emoji_messages_) {
if (get_animated_emoji_sticker(sticker_set, it.first).first.is_valid()) {
for (auto full_message_id : it.second) {
full_message_ids.push_back(full_message_id);
}
}
}
for (auto full_message_id : full_message_ids) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
return; return;
} }
@ -1944,7 +1937,7 @@ std::pair<FileId, int> StickersManager::get_animated_emoji_sticker(const Sticker
} }
std::pair<FileId, int> StickersManager::get_animated_emoji_sticker(const string &emoji) { std::pair<FileId, int> StickersManager::get_animated_emoji_sticker(const string &emoji) {
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot() || disable_animated_emojis_) {
return {}; return {};
} }
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_emoji()); auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_emoji());
@ -1966,7 +1959,7 @@ std::pair<FileId, int> StickersManager::get_animated_emoji_sticker(const string
td_api::object_ptr<td_api::MessageContent> StickersManager::get_message_content_animated_emoji_object( td_api::object_ptr<td_api::MessageContent> StickersManager::get_message_content_animated_emoji_object(
const string &emoji) { const string &emoji) {
auto animated_sticker = get_animated_emoji_sticker(emoji); auto animated_sticker = get_animated_emoji_sticker(emoji);
if (animated_sticker.first.is_valid()) { if (animated_sticker.first.is_valid() && !disable_animated_emojis_) {
return td_api::make_object<td_api::messageAnimatedEmoji>(get_sticker_object(animated_sticker.first), emoji); return td_api::make_object<td_api::messageAnimatedEmoji>(get_sticker_object(animated_sticker.first), emoji);
} }
return td_api::make_object<td_api::messageText>( return td_api::make_object<td_api::messageText>(
@ -2945,14 +2938,6 @@ void StickersManager::on_get_special_sticker_set(const SpecialStickerSetType &ty
CHECK(s->is_inited); CHECK(s->is_inited);
CHECK(s->is_loaded); CHECK(s->is_loaded);
/*
if (type.type_ == SpecialStickerSetType::animated_emoji_click()) {
for (auto &sticker_id : s->sticker_ids) {
// TODO get supported emoji and their numbers
}
}
*/
LOG(INFO) << "Receive special sticker set " << type.type_ << ": " << sticker_set_id << ' ' << s->access_hash << ' ' LOG(INFO) << "Receive special sticker set " << type.type_ << ": " << sticker_set_id << ' ' << s->access_hash << ' '
<< s->short_name; << s->short_name;
auto &sticker_set = add_special_sticker_set(type.type_); auto &sticker_set = add_special_sticker_set(type.type_);
@ -4040,6 +4025,22 @@ void StickersManager::on_update_dice_success_values() {
}); });
} }
void StickersManager::on_update_disable_animated_emojis() {
if (G()->close_flag() || td_->auth_manager_->is_bot() || !is_inited_) {
return;
}
auto disable_animated_emojis = G()->shared_config().get_option_boolean("disable_animated_emoji");
if (disable_animated_emojis == disable_animated_emojis_) {
return;
}
disable_animated_emojis_ = disable_animated_emojis;
if (!disable_animated_emojis_) {
load_special_sticker_set(add_special_sticker_set(SpecialStickerSetType::animated_emoji()));
}
try_update_animated_emoji_messages();
}
void StickersManager::on_update_sticker_sets() { void StickersManager::on_update_sticker_sets() {
// TODO better support // TODO better support
archived_sticker_set_ids_[0].clear(); archived_sticker_set_ids_[0].clear();
@ -4051,6 +4052,22 @@ void StickersManager::on_update_sticker_sets() {
reload_installed_sticker_sets(true, true); reload_installed_sticker_sets(true, true);
} }
void StickersManager::try_update_animated_emoji_messages() {
vector<FullMessageId> full_message_ids;
/*
for (const auto &it : emoji_messages_) {
if (get_animated_emoji_sticker(sticker_set, it.first).first.is_valid()) {
for (auto full_message_id : it.second) {
full_message_ids.push_back(full_message_id);
}
}
}
*/
for (auto full_message_id : full_message_ids) {
td_->messages_manager_->on_external_update_message_content(full_message_id);
}
}
void StickersManager::register_dice(const string &emoji, int32 value, FullMessageId full_message_id, void StickersManager::register_dice(const string &emoji, int32 value, FullMessageId full_message_id,
const char *source) { const char *source) {
CHECK(!emoji.empty()); CHECK(!emoji.empty());

View File

@ -148,6 +148,8 @@ class StickersManager final : public Actor {
void on_uninstall_sticker_set(StickerSetId set_id); void on_uninstall_sticker_set(StickerSetId set_id);
void on_update_disable_animated_emojis();
void on_update_dice_emojis(); void on_update_dice_emojis();
void on_update_dice_success_values(); void on_update_dice_success_values();
@ -607,6 +609,8 @@ class StickersManager final : public Actor {
std::pair<FileId, int> get_animated_emoji_sticker(const string &emoji); std::pair<FileId, int> get_animated_emoji_sticker(const string &emoji);
void try_update_animated_emoji_messages();
vector<FileId> get_animated_emoji_click_stickers(const StickerSet *sticker_set, Slice emoji) const; vector<FileId> get_animated_emoji_click_stickers(const StickerSet *sticker_set, Slice emoji) const;
void choose_animated_emoji_click_sticker(const StickerSet *sticker_set, Slice message_text, void choose_animated_emoji_click_sticker(const StickerSet *sticker_set, Slice message_text,
@ -812,6 +816,8 @@ class StickersManager final : public Actor {
string dice_success_values_str_; string dice_success_values_str_;
vector<std::pair<int32, int32>> dice_success_values_; vector<std::pair<int32, int32>> dice_success_values_;
bool disable_animated_emojis_ = false;
}; };
} // namespace td } // namespace td

View File

@ -3321,6 +3321,8 @@ void Td::on_config_option_updated(const string &name) {
} else if (name == "favorite_stickers_limit") { } else if (name == "favorite_stickers_limit") {
stickers_manager_->on_update_favorite_stickers_limit( stickers_manager_->on_update_favorite_stickers_limit(
narrow_cast<int32>(G()->shared_config().get_option_integer(name))); narrow_cast<int32>(G()->shared_config().get_option_integer(name)));
} else if (name == "disable_animated_emoji") {
stickers_manager_->on_update_disable_animated_emojis();
} else if (name == "my_id") { } else if (name == "my_id") {
G()->set_my_id(G()->shared_config().get_option_integer(name)); G()->set_my_id(G()->shared_config().get_option_integer(name));
} else if (name == "session_count") { } else if (name == "session_count") {
@ -7338,6 +7340,9 @@ void Td::on_request(uint64 id, td_api::setOption &request) {
} }
break; break;
case 'd': case 'd':
if (!is_bot && set_boolean_option("disable_animated_emoji")) {
return;
}
if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) { if (!is_bot && set_boolean_option("disable_contact_registered_notifications")) {
return; return;
} }