2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-01-02 14:42:31 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
|
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
|
|
|
|
|
|
|
|
#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/telegram/files/FileId.h"
|
|
|
|
#include "td/telegram/Photo.h"
|
|
|
|
#include "td/telegram/SecretInputMedia.h"
|
|
|
|
|
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
class Td;
|
|
|
|
} // namespace td
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class AnimationsManager : public Actor {
|
|
|
|
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
|
|
|
|
|
|
|
tl_object_ptr<td_api::animation> get_animation_object(FileId file_id, const char *source);
|
|
|
|
|
|
|
|
void create_animation(FileId file_id, PhotoSize thumbnail, string file_name, string mime_type, int32 duration,
|
|
|
|
Dimensions dimensions, bool replace);
|
|
|
|
|
|
|
|
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,
|
2018-12-04 19:18:07 +01:00
|
|
|
const string &caption, BufferSlice thumbnail, int32 layer) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
FileId get_animation_thumbnail_file_id(FileId file_id) const;
|
|
|
|
|
|
|
|
void delete_animation_thumbnail(FileId file_id);
|
|
|
|
|
|
|
|
FileId dup_animation(FileId new_id, FileId old_id);
|
|
|
|
|
|
|
|
bool merge_animations(FileId new_id, FileId old_id, bool can_delete_old);
|
|
|
|
|
|
|
|
void on_update_saved_animations_limit(int32 saved_animations_limit);
|
|
|
|
|
|
|
|
void reload_saved_animations(bool force);
|
|
|
|
|
|
|
|
void on_get_saved_animations(tl_object_ptr<telegram_api::messages_SavedGifs> &&saved_animations_ptr);
|
|
|
|
|
|
|
|
void on_get_saved_animations_failed(Status error);
|
|
|
|
|
|
|
|
vector<FileId> get_saved_animations(Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void store_animation(FileId file_id, T &storer) const;
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
FileId parse_animation(T &parser);
|
|
|
|
|
|
|
|
string get_animation_search_text(FileId file_id) const;
|
|
|
|
|
2018-12-12 03:47:20 +01:00
|
|
|
void after_get_difference();
|
|
|
|
|
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;
|
|
|
|
PhotoSize thumbnail;
|
|
|
|
|
|
|
|
FileId file_id;
|
|
|
|
|
|
|
|
bool is_changed = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-08-05 16:03:08 +02:00
|
|
|
int32 get_saved_animations_hash(const char *source) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void add_saved_animation_inner(FileId animation_id, Promise<Unit> &&promise);
|
|
|
|
|
|
|
|
bool add_saved_animation_impl(FileId animation_id, Promise<Unit> &promise);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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();
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void tear_down() override;
|
|
|
|
|
|
|
|
class AnimationListLogEvent;
|
|
|
|
|
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
|
|
|
|
std::unordered_map<FileId, unique_ptr<Animation>, FileIdHash> animations_;
|
|
|
|
|
|
|
|
int32 saved_animations_limit_ = 200;
|
|
|
|
vector<FileId> saved_animation_ids_;
|
|
|
|
double next_saved_animations_load_time_ = 0;
|
|
|
|
bool are_saved_animations_loaded_ = false;
|
|
|
|
vector<Promise<Unit>> load_saved_animations_queries_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|