Adjust dimensions of animated emojis.

This commit is contained in:
levlam 2021-10-14 00:18:44 +03:00
parent 0a9f6b1c91
commit cbca467991
6 changed files with 59 additions and 14 deletions

View File

@ -1506,6 +1506,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
bool can_archive_and_mute_new_chats_from_unknown_users = false;
int64 chat_read_mark_expire_period = 0;
int64 chat_read_mark_size_threshold = 0;
double animated_emoji_zoom = 0.0;
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_;
@ -1533,6 +1534,10 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
}
continue;
}
if (key == "emojies_animated_zoom") {
animated_emoji_zoom = get_json_value_double(std::move(key_value->value_), "emojies_animated_zoom");
continue;
}
if (key == "emojies_send_dice") {
if (value->get_id() == telegram_api::jsonArray::ID) {
auto emojis = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
@ -1786,6 +1791,11 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
shared_config.set_option_string("emoji_sounds", implode(emoji_sounds, ','));
if (animated_emoji_zoom <= 0 || animated_emoji_zoom > 2.0) {
shared_config.set_option_empty("animated_emoji_zoom");
} else {
shared_config.set_option_integer("animated_emoji_zoom", static_cast<int64>(animated_emoji_zoom * 1e9));
}
if (animation_search_provider.empty()) {
shared_config.set_option_empty("animation_search_provider");
} else {

View File

@ -217,6 +217,15 @@ int32 get_json_value_int(telegram_api::object_ptr<telegram_api::JSONValue> &&jso
return 0;
}
double get_json_value_double(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name) {
CHECK(json_value != nullptr);
if (json_value->get_id() == telegram_api::jsonNumber::ID) {
return static_cast<const telegram_api::jsonNumber *>(json_value.get())->value_;
}
LOG(ERROR) << "Expected Double as " << name << ", but found " << to_string(json_value);
return 0.0;
}
string get_json_value_string(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name) {
CHECK(json_value != nullptr);
if (json_value->get_id() == telegram_api::jsonString::ID) {

View File

@ -30,6 +30,8 @@ bool get_json_value_bool(telegram_api::object_ptr<telegram_api::JSONValue> &&jso
int32 get_json_value_int(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name);
double get_json_value_double(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name);
string get_json_value_string(telegram_api::object_ptr<telegram_api::JSONValue> &&json_value, Slice name);
} // namespace td

View File

@ -1233,6 +1233,8 @@ class StickersManager::UploadStickerFileCallback final : public FileManager::Upl
StickersManager::StickersManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
upload_sticker_file_callback_ = std::make_shared<UploadStickerFileCallback>();
on_update_animated_emoji_zoom();
on_update_recent_stickers_limit(
narrow_cast<int32>(G()->shared_config().get_option_integer("recent_stickers_limit", 200)));
on_update_favorite_stickers_limit(
@ -1710,7 +1712,8 @@ vector<td_api::object_ptr<td_api::closedVectorPath>> StickersManager::get_sticke
return result;
}
tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_id) const {
tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_id, bool for_animated_emoji,
bool for_clicked_animated_emoji) const {
if (!file_id.is_valid()) {
return nullptr;
}
@ -1746,11 +1749,17 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
}
}
auto thumbnail_object = get_thumbnail_object(td_->file_manager_.get(), thumbnail, thumbnail_format);
int32 width = sticker->dimensions.width;
int32 height = sticker->dimensions.height;
if (sticker->is_animated && (for_animated_emoji || for_clicked_animated_emoji)) {
double zoom = for_clicked_animated_emoji ? 3 * animated_emoji_zoom_ : animated_emoji_zoom_;
width = static_cast<int32>(width * zoom + 0.5);
height = static_cast<int32>(height * zoom + 0.5);
}
return make_tl_object<td_api::sticker>(
sticker->set_id.get(), sticker->dimensions.width, sticker->dimensions.height, sticker->alt, sticker->is_animated,
sticker->is_mask, std::move(mask_position),
get_sticker_minithumbnail(sticker->minithumbnail, sticker->set_id, document_id), std::move(thumbnail_object),
td_->file_manager_->get_file_object(file_id));
sticker->set_id.get(), width, height, sticker->alt, sticker->is_animated, sticker->is_mask,
std::move(mask_position), get_sticker_minithumbnail(sticker->minithumbnail, sticker->set_id, document_id),
std::move(thumbnail_object), td_->file_manager_->get_file_object(file_id));
}
tl_object_ptr<td_api::stickers> StickersManager::get_stickers_object(const vector<FileId> &sticker_ids) const {
@ -1787,7 +1796,7 @@ tl_object_ptr<td_api::DiceStickers> StickersManager::get_dice_stickers_object(co
}
auto get_sticker = [&](int32 value) {
return get_sticker_object(sticker_set->sticker_ids[value]);
return get_sticker_object(sticker_set->sticker_ids[value], true);
};
if (emoji == "🎰") {
@ -2011,7 +2020,7 @@ td_api::object_ptr<td_api::MessageContent> StickersManager::get_message_content_
auto sound_file_id =
it != emoji_messages_.end() ? it->second.sound_file_id : get_animated_emoji_sound_file_id(emoji);
return td_api::make_object<td_api::messageAnimatedEmoji>(
emoji, get_sticker_object(animated_sticker.first), get_color_replacements_object(animated_sticker.second),
emoji, get_sticker_object(animated_sticker.first, true), get_color_replacements_object(animated_sticker.second),
sound_file_id.is_valid() ? td_->file_manager_->get_file_object(sound_file_id) : nullptr);
}
return td_api::make_object<td_api::messageText>(
@ -4380,7 +4389,7 @@ void StickersManager::choose_animated_emoji_click_sticker(const StickerSet *stic
}
if (now >= next_click_animated_emoji_message_time_) {
next_click_animated_emoji_message_time_ = now + MIN_ANIMATED_EMOJI_CLICK_DELAY;
promise.set_value(get_sticker_object(result.second));
promise.set_value(get_sticker_object(result.second, false, true));
} else {
create_actor<SleepActor>("SendClickAnimatedEmojiMessageResponse", next_click_animated_emoji_message_time_ - now,
PromiseCreator::lambda([actor_id = actor_id(this), sticker_id = result.second,
@ -4396,7 +4405,7 @@ void StickersManager::choose_animated_emoji_click_sticker(const StickerSet *stic
void StickersManager::send_click_animated_emoji_message_response(
FileId sticker_id, Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
promise.set_value(get_sticker_object(sticker_id));
promise.set_value(get_sticker_object(sticker_id, false, true));
}
void StickersManager::timeout_expired() {
@ -4614,9 +4623,10 @@ void StickersManager::send_update_animated_emoji_clicked(FullMessageId full_mess
return;
}
send_closure(G()->td(), &Td::send_update,
td_api::make_object<td_api::updateAnimatedEmojiMessageClicked>(
dialog_id.get(), full_message_id.get_message_id().get(), get_sticker_object(sticker_id)));
send_closure(
G()->td(), &Td::send_update,
td_api::make_object<td_api::updateAnimatedEmojiMessageClicked>(
dialog_id.get(), full_message_id.get_message_id().get(), get_sticker_object(sticker_id, false, true)));
}
void StickersManager::view_featured_sticker_sets(const vector<StickerSetId> &sticker_set_ids) {
@ -6429,6 +6439,11 @@ void StickersManager::save_recent_stickers_to_database(bool is_attached) {
}
}
void StickersManager::on_update_animated_emoji_zoom() {
animated_emoji_zoom_ =
static_cast<double>(G()->shared_config().get_option_integer("animated_emoji_zoom", 625000000)) * 1e-9;
}
void StickersManager::on_update_recent_stickers_limit(int32 recent_stickers_limit) {
if (recent_stickers_limit != recent_stickers_limit_) {
if (recent_stickers_limit > 0) {

View File

@ -49,7 +49,8 @@ class StickersManager final : public Actor {
void init();
tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id) const;
tl_object_ptr<td_api::sticker> get_sticker_object(FileId file_id, bool for_animated_emoji = false,
bool for_clicked_animated_emoji = false) const;
tl_object_ptr<td_api::stickers> get_stickers_object(const vector<FileId> &sticker_ids) const;
@ -148,6 +149,8 @@ class StickersManager final : public Actor {
void on_uninstall_sticker_set(StickerSetId set_id);
void on_update_animated_emoji_zoom();
void on_update_disable_animated_emojis();
void on_update_dice_emojis();
@ -838,6 +841,8 @@ class StickersManager final : public Actor {
string emoji_sounds_str_;
std::unordered_map<string, FileId> emoji_sounds_;
double animated_emoji_zoom_ = 0.0;
bool disable_animated_emojis_ = false;
};

View File

@ -3265,7 +3265,8 @@ void Td::on_result(NetQueryPtr query) {
bool Td::is_internal_config_option(Slice name) {
switch (name[0]) {
case 'a':
return name == "animation_search_emojis" || name == "animation_search_provider" || name == "auth";
return name == "animated_emoji_zoom" || name == "animation_search_emojis" ||
name == "animation_search_provider" || name == "auth";
case 'b':
return name == "base_language_pack_version";
case 'c':
@ -3315,6 +3316,9 @@ void Td::on_config_option_updated(const string &name) {
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 == "animated_emoji_zoom") {
// update animated emoji zoom only at launch
return;
} else if (name == "recent_stickers_limit") {
return stickers_manager_->on_update_recent_stickers_limit(
narrow_cast<int32>(G()->shared_config().get_option_integer(name)));