2023-03-27 10:27:17 +02:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2023-03-27 10:27:17 +02: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
|
|
|
|
|
2023-03-27 17:34:25 +02:00
|
|
|
#include "td/telegram/DialogFilterDialogInfo.h"
|
2023-03-27 13:09:55 +02:00
|
|
|
#include "td/telegram/DialogFilterId.h"
|
|
|
|
#include "td/telegram/DialogId.h"
|
2023-03-27 16:44:13 +02:00
|
|
|
#include "td/telegram/FolderId.h"
|
2023-03-27 13:09:55 +02:00
|
|
|
#include "td/telegram/InputDialogId.h"
|
2023-03-27 10:50:40 +02:00
|
|
|
#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"
|
2023-03-27 16:44:13 +02:00
|
|
|
#include "td/actor/Timeout.h"
|
2023-03-27 10:27:17 +02:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2023-03-27 10:50:40 +02:00
|
|
|
#include "td/utils/Promise.h"
|
|
|
|
#include "td/utils/Status.h"
|
2023-03-27 10:27:17 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2023-03-27 10:50:40 +02:00
|
|
|
class DialogFilter;
|
2023-03-27 10:27:17 +02:00
|
|
|
class Td;
|
|
|
|
|
|
|
|
class DialogFilterManager final : public Actor {
|
|
|
|
public:
|
|
|
|
DialogFilterManager(Td *td, ActorShared<> parent);
|
2023-04-24 14:09:37 +02:00
|
|
|
DialogFilterManager(const DialogFilterManager &) = delete;
|
|
|
|
DialogFilterManager &operator=(const DialogFilterManager &) = delete;
|
|
|
|
DialogFilterManager(DialogFilterManager &&) = delete;
|
|
|
|
DialogFilterManager &operator=(DialogFilterManager &&) = delete;
|
|
|
|
~DialogFilterManager() final;
|
2023-03-27 10:27:17 +02:00
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
void init();
|
2023-03-27 13:09:55 +02:00
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
void on_authorization_success();
|
2023-03-27 13:09:55 +02:00
|
|
|
|
2023-04-02 10:53:25 +02:00
|
|
|
void on_update_dialog_filters(Promise<Unit> &&promise);
|
2023-03-27 16:44:13 +02:00
|
|
|
|
|
|
|
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;
|
2023-03-27 16:44:13 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-04-09 00:35:42 +02:00
|
|
|
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-03-27 16:44:13 +02:00
|
|
|
|
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-03-27 16:44:13 +02:00
|
|
|
|
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-03-27 16:44:13 +02:00
|
|
|
|
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);
|
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2023-04-09 20:54:40 +02:00
|
|
|
void get_dialogs_for_dialog_filter_invite_link(DialogFilterId dialog_filter_id,
|
|
|
|
Promise<td_api::object_ptr<td_api::chats>> promise);
|
|
|
|
|
2023-03-27 20:36:44 +02:00
|
|
|
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-27 20:36:44 +02:00
|
|
|
|
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
|
|
|
|
2023-03-30 18:52:55 +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
|
|
|
|
2023-03-27 20:36:44 +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);
|
2023-03-27 10:50:40 +02:00
|
|
|
|
2023-03-27 13:09:55 +02:00
|
|
|
void load_dialog_filter_dialogs(DialogFilterId dialog_filter_id, vector<InputDialogId> &&input_dialog_ids,
|
|
|
|
Promise<Unit> &&promise);
|
|
|
|
|
2023-11-01 19:32:09 +01:00
|
|
|
void load_input_dialog(const InputDialogId &input_dialog_id, Promise<Unit> &&promise);
|
|
|
|
|
2023-04-03 14:16:11 +02:00
|
|
|
void set_dialog_filter_has_my_invite_links(DialogFilterId dialog_filter_id, bool has_my_invite_links);
|
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
2023-03-27 10:27:17 +02:00
|
|
|
private:
|
2023-03-27 16:44:13 +02:00
|
|
|
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;
|
|
|
|
|
2023-03-27 10:50:40 +02:00
|
|
|
struct RecommendedDialogFilter {
|
|
|
|
unique_ptr<DialogFilter> dialog_filter;
|
|
|
|
string description;
|
|
|
|
};
|
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
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);
|
2023-03-27 16:44:13 +02:00
|
|
|
|
|
|
|
void reload_dialog_filters();
|
|
|
|
|
2024-02-19 12:07:10 +01:00
|
|
|
void on_get_dialog_filters(Result<telegram_api::object_ptr<telegram_api::messages_dialogFilters>> r_filters,
|
2023-03-27 16:44:13 +02:00
|
|
|
bool dummy);
|
|
|
|
|
|
|
|
bool need_synchronize_dialog_filters() const;
|
|
|
|
|
|
|
|
void synchronize_dialog_filters();
|
|
|
|
|
2023-04-09 00:35:42 +02:00
|
|
|
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-03-27 16:44:13 +02:00
|
|
|
|
2023-04-03 16:28:51 +02:00
|
|
|
void send_update_chat_folders();
|
2023-03-27 16:44:13 +02:00
|
|
|
|
2023-04-03 16:28:51 +02:00
|
|
|
td_api::object_ptr<td_api::updateChatFolders> get_update_chat_folders_object() const;
|
2023-03-27 16:44:13 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-04-01 22:24:57 +02:00
|
|
|
void delete_dialog_filter_on_server(DialogFilterId dialog_filter_id, bool is_shareable);
|
2023-03-27 16:44:13 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
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);
|
2023-03-27 16:44:13 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-03-27 10:50:40 +02:00
|
|
|
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);
|
2023-03-27 10:50:40 +02:00
|
|
|
|
|
|
|
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);
|
2023-03-27 10:50:40 +02:00
|
|
|
|
2023-04-09 00:35:42 +02:00
|
|
|
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);
|
2023-03-27 13:09:55 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-04-09 20:54:40 +02:00
|
|
|
void do_get_dialogs_for_dialog_filter_invite_link(DialogFilterId dialog_filter_id,
|
|
|
|
Promise<td_api::object_ptr<td_api::chats>> promise);
|
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
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;
|
2023-03-27 16:44:13 +02:00
|
|
|
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
|
|
|
|
|
2023-03-27 10:50:40 +02:00
|
|
|
vector<RecommendedDialogFilter> recommended_dialog_filters_;
|
|
|
|
|
2023-03-27 16:44:13 +02:00
|
|
|
Timeout reload_dialog_filters_timeout_;
|
|
|
|
|
2023-03-27 10:27:17 +02:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|