2018-12-05 10:32:31 +01:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
|
|
|
//
|
|
|
|
// 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/actor/actor.h"
|
|
|
|
#include "td/actor/PromiseFuture.h"
|
|
|
|
|
2019-01-14 19:46:04 +01:00
|
|
|
#include "td/telegram/ChannelId.h"
|
2019-01-19 18:19:29 +01:00
|
|
|
#include "td/telegram/ChatId.h"
|
2019-01-19 03:44:31 +01:00
|
|
|
#include "td/telegram/files/FileId.h"
|
|
|
|
#include "td/telegram/files/FileSourceId.h"
|
2018-12-05 10:32:31 +01:00
|
|
|
#include "td/telegram/MessageId.h"
|
2019-01-18 17:39:19 +01:00
|
|
|
#include "td/telegram/SetWithPosition.h"
|
2019-01-14 19:46:04 +01:00
|
|
|
#include "td/telegram/UserId.h"
|
|
|
|
|
2019-01-19 18:19:29 +01:00
|
|
|
#include "td/utils/logging.h"
|
2019-01-21 19:22:56 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2019-01-19 18:19:29 +01:00
|
|
|
#include "td/utils/Status.h"
|
2019-01-14 19:46:04 +01:00
|
|
|
#include "td/utils/Variant.h"
|
2018-12-05 10:32:31 +01:00
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2019-01-14 19:46:04 +01:00
|
|
|
extern int VERBOSITY_NAME(file_references);
|
|
|
|
|
2018-12-05 10:32:31 +01:00
|
|
|
class FileReferenceManager : public Actor {
|
|
|
|
public:
|
2019-01-23 17:00:56 +01:00
|
|
|
static bool is_file_reference_error(const Status &error);
|
|
|
|
|
2019-01-14 19:46:04 +01:00
|
|
|
FileSourceId create_message_file_source(FullMessageId full_message_id);
|
2019-01-18 20:36:23 +01:00
|
|
|
FileSourceId create_user_photo_file_source(UserId user_id, int64 photo_id);
|
|
|
|
FileSourceId create_chat_photo_file_source(ChatId chat_id);
|
|
|
|
FileSourceId create_channel_photo_file_source(ChannelId channel_id);
|
|
|
|
FileSourceId create_wallpapers_file_source();
|
|
|
|
FileSourceId create_web_page_file_source(string url);
|
|
|
|
FileSourceId create_saved_animations_file_source();
|
2019-01-14 19:46:04 +01:00
|
|
|
|
2019-01-17 21:42:00 +01:00
|
|
|
using NodeId = FileId;
|
2019-01-18 21:12:09 +01:00
|
|
|
void repair_file_reference(NodeId node_id, Promise<> promise);
|
2019-01-23 20:20:48 +01:00
|
|
|
|
2019-01-17 21:42:00 +01:00
|
|
|
void add_file_source(NodeId node_id, FileSourceId file_source_id);
|
2019-01-23 20:20:48 +01:00
|
|
|
|
2019-01-29 12:07:58 +01:00
|
|
|
std::vector<FileSourceId> get_some_file_sources(NodeId node_id);
|
|
|
|
|
2019-01-18 21:12:09 +01:00
|
|
|
void remove_file_source(NodeId node_id, FileSourceId file_source_id);
|
2019-01-23 20:20:48 +01:00
|
|
|
|
2019-01-17 21:42:00 +01:00
|
|
|
void merge(NodeId to_node_id, NodeId from_node_id);
|
2018-12-05 10:32:31 +01:00
|
|
|
|
|
|
|
private:
|
2019-01-17 21:42:00 +01:00
|
|
|
struct Destination {
|
|
|
|
bool empty() const {
|
|
|
|
return node_id.empty();
|
|
|
|
}
|
|
|
|
NodeId node_id;
|
|
|
|
int64 generation;
|
|
|
|
};
|
|
|
|
struct Query {
|
|
|
|
std::vector<Promise<>> promises;
|
|
|
|
int32 active_queries{0};
|
|
|
|
Destination proxy;
|
|
|
|
int64 generation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Node {
|
|
|
|
SetWithPosition<FileSourceId> file_source_ids;
|
|
|
|
unique_ptr<Query> query;
|
|
|
|
};
|
|
|
|
|
2019-01-14 19:46:04 +01:00
|
|
|
struct FileSourceMessage {
|
|
|
|
FullMessageId full_message_id;
|
|
|
|
};
|
|
|
|
struct FileSourceUserPhoto {
|
|
|
|
int64 photo_id;
|
2019-01-18 19:24:03 +01:00
|
|
|
UserId user_id;
|
2019-01-14 19:46:04 +01:00
|
|
|
};
|
|
|
|
struct FileSourceChatPhoto {
|
|
|
|
ChatId chat_id;
|
|
|
|
};
|
|
|
|
struct FileSourceChannelPhoto {
|
|
|
|
ChannelId channel_id;
|
|
|
|
};
|
|
|
|
struct FileSourceWallpapers {
|
|
|
|
// empty
|
|
|
|
};
|
|
|
|
struct FileSourceWebPage {
|
|
|
|
string url;
|
|
|
|
};
|
|
|
|
struct FileSourceSavedAnimations {
|
|
|
|
// empty
|
|
|
|
};
|
|
|
|
|
|
|
|
using FileSource = Variant<FileSourceMessage, FileSourceUserPhoto, FileSourceChatPhoto, FileSourceChannelPhoto,
|
|
|
|
FileSourceWallpapers, FileSourceWebPage, FileSourceSavedAnimations>;
|
|
|
|
vector<FileSource> file_sources_;
|
|
|
|
|
2019-01-18 20:36:23 +01:00
|
|
|
int64 query_generation_{0};
|
2019-01-17 21:42:00 +01:00
|
|
|
|
|
|
|
std::unordered_map<NodeId, Node, FileIdHash> nodes_;
|
|
|
|
|
|
|
|
void run_node(NodeId node);
|
|
|
|
void send_query(Destination dest, FileSourceId file_source_id);
|
|
|
|
Destination on_query_result(Destination dest, FileSourceId file_source_id, Status status, int32 sub = 0);
|
2019-01-18 20:10:38 +01:00
|
|
|
|
2019-01-18 20:36:23 +01:00
|
|
|
template <class T>
|
2019-01-21 19:22:56 +01:00
|
|
|
FileSourceId add_file_source_id(T source, Slice source_str);
|
2019-01-18 20:36:23 +01:00
|
|
|
|
2019-01-18 20:10:38 +01:00
|
|
|
FileSourceId get_current_file_source_id() const;
|
2018-12-05 10:32:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|