2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2022-06-02 16:52:12 +02:00
|
|
|
#include "td/telegram/Dimensions.h"
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/telegram/files/FileId.h"
|
|
|
|
#include "td/telegram/files/FileSourceId.h"
|
2022-04-10 00:15:49 +02:00
|
|
|
#include "td/telegram/PhotoSize.h"
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/telegram/SecretInputMedia.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
2022-02-07 20:41:07 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2022-02-07 22:04:34 +01:00
|
|
|
#include "td/utils/Status.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
class Td;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class AnimationsManager final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
AnimationsManager(Td *td, ActorShared<> parent);
|
|
|
|
|
2018-09-27 20:14:32 +02:00
|
|
|
int32 get_animation_duration(FileId file_id) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-08-28 13:16:29 +02:00
|
|
|
tl_object_ptr<td_api::animation> get_animation_object(FileId file_id) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-07-07 10:41:01 +02:00
|
|
|
void create_animation(FileId file_id, string minithumbnail, PhotoSize thumbnail, AnimationSize animated_thumbnail,
|
2020-05-30 00:48:56 +02:00
|
|
|
bool has_stickers, vector<FileId> &&sticker_file_ids, string file_name, string mime_type,
|
|
|
|
int32 duration, Dimensions dimensions, bool replace);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
tl_object_ptr<telegram_api::InputMedia> get_input_media(FileId file_id,
|
|
|
|
tl_object_ptr<telegram_api::InputFile> input_file,
|
2018-01-30 18:06:54 +01:00
|
|
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
SecretInputMedia get_secret_input_media(FileId animation_file_id,
|
|
|
|
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
2021-06-08 17:31:29 +02:00
|
|
|
const string &caption, BufferSlice thumbnail) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
FileId get_animation_thumbnail_file_id(FileId file_id) const;
|
|
|
|
|
2020-05-30 00:48:56 +02:00
|
|
|
FileId get_animation_animated_thumbnail_file_id(FileId file_id) const;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void delete_animation_thumbnail(FileId file_id);
|
|
|
|
|
|
|
|
FileId dup_animation(FileId new_id, FileId old_id);
|
|
|
|
|
2021-08-26 17:50:28 +02:00
|
|
|
void merge_animations(FileId new_id, FileId old_id, bool can_delete_old);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-05-30 01:42:45 +02:00
|
|
|
void on_update_animation_search_emojis(string animation_search_emojis);
|
|
|
|
|
|
|
|
void on_update_animation_search_provider(string animation_search_provider);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void on_update_saved_animations_limit(int32 saved_animations_limit);
|
|
|
|
|
|
|
|
void reload_saved_animations(bool force);
|
|
|
|
|
2019-02-02 11:54:40 +01:00
|
|
|
void repair_saved_animations(Promise<Unit> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-02 11:54:40 +01:00
|
|
|
void on_get_saved_animations(bool is_repair, tl_object_ptr<telegram_api::messages_SavedGifs> &&saved_animations_ptr);
|
2019-01-15 01:04:10 +01:00
|
|
|
|
2019-02-02 11:54:40 +01:00
|
|
|
void on_get_saved_animations_failed(bool is_repair, Status error);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
vector<FileId> get_saved_animations(Promise<Unit> &&promise);
|
|
|
|
|
2019-01-30 22:37:38 +01:00
|
|
|
FileSourceId get_saved_animations_file_source_id();
|
|
|
|
|
2019-01-23 20:20:48 +01:00
|
|
|
void send_save_gif_query(FileId animation_id, bool unsave, Promise<Unit> &&promise);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void add_saved_animation(const tl_object_ptr<td_api::InputFile> &input_file, Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void add_saved_animation_by_id(FileId animation_id);
|
|
|
|
|
|
|
|
void remove_saved_animation(const tl_object_ptr<td_api::InputFile> &input_file, Promise<Unit> &&promise);
|
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store_animation(FileId file_id, StorerT &storer) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-21 18:54:20 +01:00
|
|
|
template <class ParserT>
|
|
|
|
FileId parse_animation(ParserT &parser);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
string get_animation_search_text(FileId file_id) const;
|
|
|
|
|
2018-09-20 21:38:19 +02:00
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
|
|
|
class Animation {
|
|
|
|
public:
|
|
|
|
string file_name;
|
|
|
|
string mime_type;
|
|
|
|
int32 duration = 0;
|
|
|
|
Dimensions dimensions;
|
2019-03-01 20:51:33 +01:00
|
|
|
string minithumbnail;
|
2018-12-31 20:04:05 +01:00
|
|
|
PhotoSize thumbnail;
|
2020-07-07 10:41:01 +02:00
|
|
|
AnimationSize animated_thumbnail;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-05-29 10:51:51 +02:00
|
|
|
bool has_stickers = false;
|
|
|
|
vector<FileId> sticker_file_ids;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
FileId file_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Animation *get_animation(FileId file_id) const;
|
|
|
|
|
2018-09-27 03:19:03 +02:00
|
|
|
FileId on_get_animation(unique_ptr<Animation> new_animation, bool replace);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-09-03 11:27:59 +02:00
|
|
|
int64 get_saved_animations_hash(const char *source) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-11-30 19:22:40 +01:00
|
|
|
void add_saved_animation_impl(FileId animation_id, bool add_on_server, Promise<Unit> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void load_saved_animations(Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
void on_load_saved_animations_from_database(const string &value);
|
|
|
|
|
|
|
|
void on_load_saved_animations_finished(vector<FileId> &&saved_animation_ids, bool from_database = false);
|
|
|
|
|
2020-05-30 01:42:45 +02:00
|
|
|
void try_send_update_animation_search_parameters() const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::updateAnimationSearchParameters> get_update_animation_search_parameters_object() const;
|
|
|
|
|
2018-09-26 17:48:14 +02:00
|
|
|
td_api::object_ptr<td_api::updateSavedAnimations> get_update_saved_animations_object() const;
|
2018-09-20 21:38:19 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void send_update_saved_animations(bool from_database = false);
|
|
|
|
|
2018-03-08 19:04:28 +01:00
|
|
|
void save_saved_animations_to_database();
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void tear_down() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
class AnimationListLogEvent;
|
|
|
|
|
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
|
2022-02-07 20:41:07 +01:00
|
|
|
FlatHashMap<FileId, unique_ptr<Animation>, FileIdHash> animations_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
int32 saved_animations_limit_ = 200;
|
|
|
|
vector<FileId> saved_animation_ids_;
|
2019-01-23 20:20:48 +01:00
|
|
|
vector<FileId> saved_animation_file_ids_;
|
2018-12-31 20:04:05 +01:00
|
|
|
double next_saved_animations_load_time_ = 0;
|
2020-11-21 14:34:39 +01:00
|
|
|
bool are_saved_animations_being_loaded_ = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
bool are_saved_animations_loaded_ = false;
|
|
|
|
vector<Promise<Unit>> load_saved_animations_queries_;
|
2019-02-02 11:54:40 +01:00
|
|
|
vector<Promise<Unit>> repair_saved_animations_queries_;
|
2019-01-21 21:30:28 +01:00
|
|
|
FileSourceId saved_animations_file_source_id_;
|
2020-05-30 01:42:45 +02:00
|
|
|
|
|
|
|
string animation_search_emojis_;
|
|
|
|
string animation_search_provider_;
|
|
|
|
bool is_animation_search_emojis_inited_ = false;
|
|
|
|
bool is_animation_search_provider_inited_ = false;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|