tdlight/td/telegram/DialogFilterManager.h

239 lines
10 KiB
C
Raw Normal View History

2023-03-27 10:27:17 +02:00
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
//
// 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
2023-03-27 17:34:25 +02:00
#include "td/telegram/DialogFilterDialogInfo.h"
#include "td/telegram/DialogFilterId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/FolderId.h"
#include "td/telegram/InputDialogId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
2023-03-27 10:27:17 +02:00
#include "td/actor/actor.h"
#include "td/actor/Timeout.h"
2023-03-27 10:27:17 +02:00
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
2023-03-27 10:27:17 +02:00
namespace td {
class DialogFilter;
2023-03-27 10:27:17 +02:00
class Td;
class DialogFilterManager final : public Actor {
public:
DialogFilterManager(Td *td, ActorShared<> parent);
void init();
void on_authorization_success();
void on_update_dialog_filters(Promise<Unit> &&promise);
void schedule_reload_dialog_filters(Promise<Unit> &&promise);
bool have_dialog_filters() const;
vector<FolderId> get_dialog_filter_folder_ids(DialogFilterId dialog_filter_id) const;
vector<DialogFilterId> get_dialog_filters_to_add_dialog(DialogId dialog_id) const;
2023-03-27 17:34:25 +02:00
bool need_dialog_in_filter(DialogFilterId dialog_filter_id, const DialogFilterDialogInfo &dialog_info) const;
bool is_dialog_pinned(DialogFilterId dialog_filter_id, DialogId dialog_id) const;
const vector<InputDialogId> &get_pinned_input_dialog_ids(DialogFilterId dialog_filter_id) const;
vector<DialogId> get_pinned_dialog_ids(DialogFilterId dialog_filter_id) const;
Status set_dialog_is_pinned(DialogFilterId dialog_filter_id, InputDialogId input_dialog_id, bool is_pinned);
Status set_pinned_dialog_ids(DialogFilterId dialog_filter_id, vector<InputDialogId> input_dialog_ids,
bool need_synchronize);
Status add_dialog(DialogFilterId dialog_filter_id, InputDialogId input_dialog_id);
void get_dialog_filter(DialogFilterId dialog_filter_id, Promise<td_api::object_ptr<td_api::chatFolder>> &&promise);
2023-04-03 16:28:51 +02:00
void create_dialog_filter(td_api::object_ptr<td_api::chatFolder> filter,
Promise<td_api::object_ptr<td_api::chatFolderInfo>> &&promise);
2023-04-03 16:28:51 +02:00
void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFolder> filter,
Promise<td_api::object_ptr<td_api::chatFolderInfo>> &&promise);
2023-04-02 11:05:04 +02:00
void delete_dialog_filter(DialogFilterId dialog_filter_id, vector<DialogId> leave_dialog_ids,
Promise<Unit> &&promise);
2023-04-02 11:40:57 +02:00
void get_leave_dialog_filter_suggestions(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> &&promise);
void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
Promise<Unit> &&promise);
void get_dialogs_for_dialog_filter_invite_link(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> promise);
void create_dialog_filter_invite_link(DialogFilterId dialog_filter_id, string invite_link_name,
vector<DialogId> dialog_ids,
2023-04-03 16:28:51 +02:00
Promise<td_api::object_ptr<td_api::chatFolderInviteLink>> promise);
2023-03-30 16:15:04 +02:00
void get_dialog_filter_invite_links(DialogFilterId dialog_filter_id,
2023-04-03 16:28:51 +02:00
Promise<td_api::object_ptr<td_api::chatFolderInviteLinks>> promise);
2023-03-30 16:15:04 +02:00
2023-03-30 18:37:01 +02:00
void edit_dialog_filter_invite_link(DialogFilterId dialog_filter_id, string invite_link, string invite_link_name,
vector<DialogId> dialog_ids,
2023-04-03 16:28:51 +02:00
Promise<td_api::object_ptr<td_api::chatFolderInviteLink>> promise);
2023-03-30 18:37:01 +02:00
void delete_dialog_filter_invite_link(DialogFilterId dialog_filter_id, string invite_link, Promise<Unit> promise);
2023-03-31 14:50:49 +02:00
void check_dialog_filter_invite_link(const string &invite_link,
2023-04-03 16:28:51 +02:00
Promise<td_api::object_ptr<td_api::chatFolderInviteLinkInfo>> &&promise);
2023-03-31 14:50:49 +02:00
void on_get_chatlist_invite(const string &invite_link,
telegram_api::object_ptr<telegram_api::chatlists_ChatlistInvite> &&invite_ptr,
2023-04-03 16:28:51 +02:00
Promise<td_api::object_ptr<td_api::chatFolderInviteLinkInfo>> &&promise);
2023-03-31 14:50:49 +02:00
2023-03-31 15:48:32 +02:00
void add_dialog_filter_by_invite_link(const string &invite_link, vector<DialogId> dialog_ids,
Promise<Unit> &&promise);
2023-04-04 15:35:31 +02:00
void get_dialog_filter_new_chats(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> &&promise);
void add_dialog_filter_new_chats(DialogFilterId dialog_filter_id, vector<DialogId> dialog_ids,
Promise<Unit> &&promise);
2023-04-04 15:21:31 +02:00
void on_get_dialog_filter(telegram_api::object_ptr<telegram_api::DialogFilter> filter);
2023-04-03 16:28:51 +02:00
void get_recommended_dialog_filters(Promise<td_api::object_ptr<td_api::recommendedChatFolders>> &&promise);
void load_dialog_filter_dialogs(DialogFilterId dialog_filter_id, vector<InputDialogId> &&input_dialog_ids,
Promise<Unit> &&promise);
void set_dialog_filter_has_my_invite_links(DialogFilterId dialog_filter_id, bool has_my_invite_links);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
2023-03-27 10:27:17 +02:00
private:
static constexpr int32 DIALOG_FILTERS_CACHE_TIME = 86400;
class DialogFiltersLogEvent;
void hangup() final;
2023-03-27 10:27:17 +02:00
void tear_down() final;
struct RecommendedDialogFilter {
unique_ptr<DialogFilter> dialog_filter;
string description;
};
DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id);
const DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id) const;
static double get_dialog_filters_cache_time();
void schedule_dialog_filters_reload(double timeout);
2023-04-07 15:02:31 +02:00
static void on_reload_dialog_filters_timeout(void *dialog_filter_manager_ptr);
void reload_dialog_filters();
void on_get_dialog_filters(Result<vector<telegram_api::object_ptr<telegram_api::DialogFilter>>> r_filters,
bool dummy);
bool need_synchronize_dialog_filters() const;
void synchronize_dialog_filters();
td_api::object_ptr<td_api::chatFolder> get_chat_folder_object(DialogFilterId dialog_filter_id);
2023-04-03 16:28:51 +02:00
td_api::object_ptr<td_api::chatFolder> get_chat_folder_object(const DialogFilter *dialog_filter);
2023-04-03 16:28:51 +02:00
void send_update_chat_folders();
2023-04-03 16:28:51 +02:00
td_api::object_ptr<td_api::updateChatFolders> get_update_chat_folders_object() const;
void do_edit_dialog_filter(unique_ptr<DialogFilter> &&filter, bool need_synchronize, const char *source);
void update_dialog_filter_on_server(unique_ptr<DialogFilter> &&dialog_filter);
void on_update_dialog_filter(unique_ptr<DialogFilter> dialog_filter, Status result);
void delete_dialog_filter_on_server(DialogFilterId dialog_filter_id, bool is_shareable);
void on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result);
2023-04-02 11:40:57 +02:00
void on_get_leave_dialog_filter_suggestions(DialogFilterId dialog_filter_id,
vector<telegram_api::object_ptr<telegram_api::Peer>> peers,
Promise<td_api::object_ptr<td_api::chats>> &&promise);
void reorder_dialog_filters_on_server(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position);
void on_reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
Status result);
void save_dialog_filters();
void add_dialog_filter(unique_ptr<DialogFilter> dialog_filter, bool at_beginning, const char *source);
void edit_dialog_filter(unique_ptr<DialogFilter> new_dialog_filter, const char *source);
2023-04-02 11:05:04 +02:00
int32 do_delete_dialog_filter(DialogFilterId dialog_filter_id, const char *source);
const DialogFilter *get_server_dialog_filter(DialogFilterId dialog_filter_id) const;
int32 get_server_main_dialog_list_position() const;
bool is_recommended_dialog_filter(const DialogFilter *dialog_filter);
void on_get_recommended_dialog_filters(
Result<vector<telegram_api::object_ptr<telegram_api::dialogFilterSuggested>>> result,
2023-04-03 16:28:51 +02:00
Promise<td_api::object_ptr<td_api::recommendedChatFolders>> &&promise);
void on_load_recommended_dialog_filters(Result<Unit> &&result, vector<RecommendedDialogFilter> &&filters,
2023-04-03 16:28:51 +02:00
Promise<td_api::object_ptr<td_api::recommendedChatFolders>> &&promise);
void load_dialog_filter(const DialogFilter *dialog_filter, Promise<Unit> &&promise);
void on_load_dialog_filter(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chatFolder>> &&promise);
void on_load_dialog_filter_dialogs(DialogFilterId dialog_filter_id, vector<DialogId> &&dialog_ids,
Promise<Unit> &&promise);
void delete_dialogs_from_filter(const DialogFilter *dialog_filter, vector<DialogId> &&dialog_ids, const char *source);
void do_get_dialogs_for_dialog_filter_invite_link(DialogFilterId dialog_filter_id,
Promise<td_api::object_ptr<td_api::chats>> promise);
bool is_inited_ = false;
bool are_dialog_filters_being_synchronized_ = false;
bool are_dialog_filters_being_reloaded_ = false;
bool need_dialog_filters_reload_ = false;
bool disable_get_dialog_filter_ = false;
2023-04-03 16:28:51 +02:00
bool is_update_chat_folders_sent_ = false;
int32 dialog_filters_updated_date_ = 0;
vector<unique_ptr<DialogFilter>> server_dialog_filters_;
vector<unique_ptr<DialogFilter>> dialog_filters_;
vector<Promise<Unit>> dialog_filter_reload_queries_;
int32 server_main_dialog_list_position_ = 0; // position of the main dialog list stored on the server
int32 main_dialog_list_position_ = 0; // local position of the main dialog list stored on the server
vector<RecommendedDialogFilter> recommended_dialog_filters_;
Timeout reload_dialog_filters_timeout_;
2023-03-27 10:27:17 +02:00
Td *td_;
ActorShared<> parent_;
};
} // namespace td