Support for recent_stickers_limit.

GitOrigin-RevId: f49119eb0703bb03e7c564a4f90a1f91f9c6074b
This commit is contained in:
levlam 2018-03-08 16:49:45 +03:00
parent ae319fa10b
commit 6669bd8c7b
7 changed files with 34 additions and 14 deletions

View File

@ -40,10 +40,9 @@ tl_object_ptr<td_api::audio> AudiosManager::get_audio_object(FileId file_id) {
auto &audio = audios_[file_id];
CHECK(audio != nullptr);
audio->is_changed = false;
return make_tl_object<td_api::audio>(audio->duration, audio->title, audio->performer, audio->file_name,
audio->mime_type,
get_photo_size_object(td_->file_manager_.get(), &audio->thumbnail),
td_->file_manager_->get_file_object(file_id));
return make_tl_object<td_api::audio>(
audio->duration, audio->title, audio->performer, audio->file_name, audio->mime_type,
get_photo_size_object(td_->file_manager_.get(), &audio->thumbnail), td_->file_manager_->get_file_object(file_id));
}
FileId AudiosManager::on_get_audio(std::unique_ptr<Audio> new_audio, bool replace) {

View File

@ -661,6 +661,7 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
// Do not save dc_options in config, because it will be interpreted and saved by ConnectionCreator.
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(config->dc_options_));
shared_config.set_option_integer("recent_stickers_limit", config->stickers_recent_limit_);
shared_config.set_option_integer("favorite_stickers_limit", config->stickers_faved_limit_);
shared_config.set_option_integer("saved_animations_limit", config->saved_gifs_limit_);
shared_config.set_option_integer("channels_read_media_period", config->channels_read_media_period_);

View File

@ -3546,7 +3546,7 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i
auto it = std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id);
if (it == sticker_ids.end()) {
if (sticker_ids.size() == RECENT_STICKERS_LIMIT) {
if (static_cast<int32>(sticker_ids.size()) == recent_stickers_limit_) {
sticker_ids.back() = sticker_id;
} else {
sticker_ids.push_back(sticker_id);
@ -3648,6 +3648,23 @@ void StickersManager::send_update_recent_stickers(bool from_database) {
}
}
void StickersManager::on_update_recent_stickers_limit(int32 recent_stickers_limit) {
if (recent_stickers_limit != recent_stickers_limit_) {
if (recent_stickers_limit > 0) {
LOG(INFO) << "Update recent stickers limit to " << recent_stickers_limit;
recent_stickers_limit_ = recent_stickers_limit;
for (int is_attached = 0; is_attached < 2; is_attached++) {
if (static_cast<int32>(recent_sticker_ids_[is_attached].size()) > recent_stickers_limit) {
recent_sticker_ids_[is_attached].resize(recent_stickers_limit);
send_update_recent_stickers();
}
}
} else {
LOG(ERROR) << "Receive wrong recent stickers limit = " << recent_stickers_limit;
}
}
}
void StickersManager::on_update_favorite_stickers_limit(int32 favorite_stickers_limit) {
if (favorite_stickers_limit != favorite_stickers_limit_) {
if (favorite_stickers_limit > 0) {

View File

@ -155,6 +155,8 @@ class StickersManager : public Actor {
void clear_recent_stickers(bool is_attached, Promise<Unit> &&promise);
void on_update_recent_stickers_limit(int32 recent_stickers_limit);
void on_update_favorite_stickers_limit(int32 favorite_stickers_limit);
void reload_favorite_stickers(bool force);
@ -205,7 +207,6 @@ class StickersManager : public Actor {
private:
static constexpr int32 MAX_FEATURED_STICKER_SET_VIEW_DELAY = 5;
static constexpr size_t RECENT_STICKERS_LIMIT = 30;
static constexpr int64 MAX_STICKER_FILE_SIZE = 1 << 19; // server side limit
static constexpr size_t MAX_STICKER_SET_TITLE_LENGTH = 64; // server side limit
@ -469,7 +470,8 @@ class StickersManager : public Actor {
std::unordered_set<int64> pending_viewed_featured_sticker_set_ids_;
Timeout pending_featured_sticker_set_views_timeout_;
int32 favorite_stickers_limit_ = 200;
int32 recent_stickers_limit_ = 200;
int32 favorite_stickers_limit_ = 5;
struct StickerSetLoadRequest {
Promise<Unit> promise;

View File

@ -3975,7 +3975,7 @@ bool Td::is_internal_config_option(Slice name) {
return name == "call_ring_timeout_ms" || name == "call_receive_timeout_ms" || name == "channels_read_media_period" ||
name == "edit_time_limit" || name == "revoke_pm_inbox" || name == "revoke_time_limit" ||
name == "revoke_pm_time_limit" || name == "rating_e_decay" || name == "saved_animations_limit" ||
name == "auth";
name == "recent_stickers_limit" || name == "auth";
}
void Td::on_config_option_updated(const string &name) {
@ -3987,6 +3987,8 @@ void Td::on_config_option_updated(const string &name) {
return;
} else if (name == "saved_animations_limit") {
return animations_manager_->on_update_saved_animations_limit(G()->shared_config().get_option_integer(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") {
stickers_manager_->on_update_favorite_stickers_limit(G()->shared_config().get_option_integer(name));
} else if (name == "my_id") {

View File

@ -42,11 +42,10 @@ tl_object_ptr<td_api::video> VideosManager::get_video_object(FileId file_id) {
CHECK(video != nullptr);
video->is_changed = false;
return make_tl_object<td_api::video>(video->duration, video->dimensions.width, video->dimensions.height,
video->file_name, video->mime_type, video->has_stickers,
video->supports_streaming,
get_photo_size_object(td_->file_manager_.get(), &video->thumbnail),
td_->file_manager_->get_file_object(file_id));
return make_tl_object<td_api::video>(
video->duration, video->dimensions.width, video->dimensions.height, video->file_name, video->mime_type,
video->has_stickers, video->supports_streaming,
get_photo_size_object(td_->file_manager_.get(), &video->thumbnail), td_->file_manager_->get_file_object(file_id));
}
FileId VideosManager::on_get_video(std::unique_ptr<Video> new_video, bool replace) {

View File

@ -288,7 +288,7 @@ Result<CpuStat> cpu_stat() {
return Status::Error("Not supported");
#endif
}
}
} // namespace td
#endif
#if TD_PORT_WINDOWS