2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
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/DialogId.h"
|
|
|
|
#include "td/telegram/files/FileId.h"
|
2019-01-30 22:37:38 +01:00
|
|
|
#include "td/telegram/files/FileSourceId.h"
|
2019-11-26 17:53:10 +01:00
|
|
|
#include "td/telegram/FullMessageId.h"
|
2020-01-27 00:55:18 +01:00
|
|
|
#include "td/telegram/SecretInputMedia.h"
|
2021-10-27 16:32:09 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
#include "td/telegram/telegram_api.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/WebPageId.h"
|
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
2022-07-02 22:32:18 +02:00
|
|
|
#include "td/actor/MultiTimeout.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-02-07 22:04:34 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2022-03-11 19:38:48 +01:00
|
|
|
#include "td/utils/FlatHashSet.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2022-10-12 14:59:58 +02:00
|
|
|
#include "td/utils/Slice.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
2022-08-04 13:48:10 +02:00
|
|
|
#include "td/utils/WaitFreeHashMap.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-02-20 22:20:45 +01:00
|
|
|
#include <utility>
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2019-01-06 20:11:02 +01:00
|
|
|
struct BinlogEvent;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class Td;
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class WebPagesManager final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
WebPagesManager(Td *td, ActorShared<> parent);
|
|
|
|
|
|
|
|
WebPagesManager(const WebPagesManager &) = delete;
|
|
|
|
WebPagesManager &operator=(const WebPagesManager &) = delete;
|
|
|
|
WebPagesManager(WebPagesManager &&) = delete;
|
|
|
|
WebPagesManager &operator=(WebPagesManager &&) = delete;
|
2021-07-03 22:51:36 +02:00
|
|
|
~WebPagesManager() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
WebPageId on_get_web_page(tl_object_ptr<telegram_api::WebPage> &&web_page_ptr, DialogId owner_dialog_id);
|
|
|
|
|
|
|
|
void on_get_web_page_by_url(const string &url, WebPageId web_page_id, bool from_database);
|
|
|
|
|
2020-03-13 23:56:47 +01:00
|
|
|
void on_get_web_page_instant_view_view_count(WebPageId web_page_id, int32 view_count);
|
|
|
|
|
2020-02-22 17:21:58 +01:00
|
|
|
void register_web_page(WebPageId web_page_id, FullMessageId full_message_id, const char *source);
|
2020-01-27 00:55:18 +01:00
|
|
|
|
2020-02-22 17:21:58 +01:00
|
|
|
void unregister_web_page(WebPageId web_page_id, FullMessageId full_message_id, const char *source);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
bool have_web_page(WebPageId web_page_id) const;
|
|
|
|
|
|
|
|
bool have_web_page_force(WebPageId web_page_id);
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::webPage> get_web_page_object(WebPageId web_page_id) const;
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(WebPageId web_page_id) const;
|
|
|
|
|
2023-02-15 13:05:37 +01:00
|
|
|
void get_web_page_preview(td_api::object_ptr<td_api::formattedText> &&text,
|
|
|
|
Promise<td_api::object_ptr<td_api::webPage>> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-10-07 12:00:41 +02:00
|
|
|
void get_web_page_instant_view(const string &url, bool force_full, Promise<WebPageId> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
WebPageId get_web_page_by_url(const string &url) const;
|
|
|
|
|
2021-10-07 11:49:46 +02:00
|
|
|
void get_web_page_by_url(const string &url, Promise<WebPageId> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-10-07 11:49:46 +02:00
|
|
|
void reload_web_page_by_url(const string &url, Promise<WebPageId> &&promise);
|
2019-01-14 19:46:04 +01:00
|
|
|
|
2023-02-15 13:05:37 +01:00
|
|
|
void on_get_web_page_preview(const string &url, tl_object_ptr<telegram_api::MessageMedia> &&message_media_ptr,
|
|
|
|
Promise<td_api::object_ptr<td_api::webPage>> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
SecretInputMedia get_secret_input_media(WebPageId web_page_id) const;
|
|
|
|
|
|
|
|
void on_binlog_web_page_event(BinlogEvent &&event);
|
|
|
|
|
2019-01-30 22:37:38 +01:00
|
|
|
FileSourceId get_url_file_source_id(const string &url);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
string get_web_page_search_text(WebPageId web_page_id) const;
|
|
|
|
|
2021-08-05 01:09:04 +02:00
|
|
|
int32 get_web_page_media_duration(WebPageId web_page_id) const;
|
2021-07-26 03:33:56 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
private:
|
|
|
|
class WebPage;
|
|
|
|
|
|
|
|
class WebPageInstantView;
|
|
|
|
|
|
|
|
class WebPageLogEvent;
|
|
|
|
|
|
|
|
void update_web_page(unique_ptr<WebPage> web_page, WebPageId web_page_id, bool from_binlog, bool from_database);
|
|
|
|
|
|
|
|
void update_web_page_instant_view(WebPageId web_page_id, WebPageInstantView &new_instant_view,
|
|
|
|
WebPageInstantView &&old_instant_view);
|
|
|
|
|
|
|
|
static bool need_use_old_instant_view(const WebPageInstantView &new_instant_view,
|
|
|
|
const WebPageInstantView &old_instant_view);
|
|
|
|
|
2020-01-27 00:55:18 +01:00
|
|
|
void on_web_page_changed(WebPageId web_page_id, bool have_web_page);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
const WebPage *get_web_page(WebPageId web_page_id) const;
|
|
|
|
|
|
|
|
const WebPageInstantView *get_web_page_instant_view(WebPageId web_page_id) const;
|
|
|
|
|
2022-02-16 17:14:25 +01:00
|
|
|
void get_web_page_instant_view_impl(WebPageId web_page_id, bool force_full, Promise<WebPageId> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
tl_object_ptr<td_api::webPageInstantView> get_web_page_instant_view_object(
|
2022-09-26 18:24:39 +02:00
|
|
|
WebPageId web_page_id, const WebPageInstantView *web_page_instant_view, Slice web_page_url) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-11-13 20:37:41 +01:00
|
|
|
static void on_pending_web_page_timeout_callback(void *web_pages_manager_ptr, int64 web_page_id_int);
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void on_pending_web_page_timeout(WebPageId web_page_id);
|
|
|
|
|
2023-02-15 13:05:37 +01:00
|
|
|
void on_get_web_page_preview_success(const string &url, WebPageId web_page_id,
|
|
|
|
Promise<td_api::object_ptr<td_api::webPage>> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-04 23:08:15 +01:00
|
|
|
void on_get_web_page_instant_view(WebPage *web_page, tl_object_ptr<telegram_api::page> &&page, int32 hash,
|
2018-12-31 20:04:05 +01:00
|
|
|
DialogId owner_dialog_id);
|
|
|
|
|
2019-01-21 21:55:26 +01:00
|
|
|
void save_web_page(const WebPage *web_page, WebPageId web_page_id, bool from_binlog);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static string get_web_page_database_key(WebPageId web_page_id);
|
|
|
|
|
|
|
|
void on_save_web_page_to_database(WebPageId web_page_id, bool success);
|
|
|
|
|
|
|
|
void load_web_page_from_database(WebPageId web_page_id, Promise<Unit> promise);
|
|
|
|
|
|
|
|
void on_load_web_page_from_database(WebPageId web_page_id, string value);
|
|
|
|
|
2019-01-21 21:55:26 +01:00
|
|
|
const WebPage *get_web_page_force(WebPageId web_page_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static string get_web_page_instant_view_database_key(WebPageId web_page_id);
|
|
|
|
|
2021-10-07 11:49:46 +02:00
|
|
|
void load_web_page_instant_view(WebPageId web_page_id, bool force_full, Promise<WebPageId> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void on_load_web_page_instant_view_from_database(WebPageId web_page_id, string value);
|
|
|
|
|
|
|
|
void reload_web_page_instant_view(WebPageId web_page_id);
|
|
|
|
|
2021-10-07 11:49:46 +02:00
|
|
|
void update_web_page_instant_view_load_requests(WebPageId web_page_id, bool force_update,
|
|
|
|
Result<WebPageId> r_web_page_id);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
static string get_web_page_url_database_key(const string &url);
|
|
|
|
|
2021-10-19 17:11:16 +02:00
|
|
|
void load_web_page_by_url(string url, Promise<WebPageId> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-10-07 11:49:46 +02:00
|
|
|
void on_load_web_page_id_by_url_from_database(string url, string value, Promise<WebPageId> &&promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-10-07 11:49:46 +02:00
|
|
|
void on_load_web_page_by_url_from_database(WebPageId web_page_id, string url, Promise<WebPageId> &&promise,
|
|
|
|
Result<Unit> &&result);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void tear_down() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-08-05 01:09:04 +02:00
|
|
|
static int32 get_web_page_media_duration(const WebPage *web_page);
|
|
|
|
|
2019-01-30 22:37:38 +01:00
|
|
|
FileSourceId get_web_page_file_source_id(WebPage *web_page);
|
|
|
|
|
2019-02-28 19:40:57 +01:00
|
|
|
vector<FileId> get_web_page_file_ids(const WebPage *web_page) const;
|
2019-01-21 22:59:55 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
2022-08-04 13:48:10 +02:00
|
|
|
WaitFreeHashMap<WebPageId, unique_ptr<WebPage>, WebPageIdHash> web_pages_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-02-07 20:41:07 +01:00
|
|
|
FlatHashMap<WebPageId, vector<Promise<Unit>>, WebPageIdHash> load_web_page_from_database_queries_;
|
2022-03-11 19:38:48 +01:00
|
|
|
FlatHashSet<WebPageId, WebPageIdHash> loaded_from_database_web_pages_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
struct PendingWebPageInstantViewQueries {
|
2021-10-07 11:49:46 +02:00
|
|
|
vector<Promise<WebPageId>> partial;
|
|
|
|
vector<Promise<WebPageId>> full;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2022-02-07 20:41:07 +01:00
|
|
|
FlatHashMap<WebPageId, PendingWebPageInstantViewQueries, WebPageIdHash> load_web_page_instant_view_queries_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-03-11 19:38:48 +01:00
|
|
|
FlatHashMap<WebPageId, FlatHashSet<FullMessageId, FullMessageIdHash>, WebPageIdHash> web_page_messages_;
|
2020-01-27 00:55:18 +01:00
|
|
|
|
2023-02-15 13:05:37 +01:00
|
|
|
FlatHashMap<WebPageId, vector<std::pair<string, Promise<td_api::object_ptr<td_api::webPage>>>>, WebPageIdHash>
|
|
|
|
pending_get_web_pages_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-02-07 20:41:07 +01:00
|
|
|
FlatHashMap<string, WebPageId> url_to_web_page_id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2022-02-07 20:41:07 +01:00
|
|
|
FlatHashMap<string, FileSourceId> url_to_file_source_id_;
|
2019-01-30 22:37:38 +01:00
|
|
|
|
2018-08-01 19:31:20 +02:00
|
|
|
MultiTimeout pending_web_pages_timeout_{"PendingWebPagesTimeout"};
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|