Move dialog filter list to DialogFilterManager.

This commit is contained in:
levlam 2023-03-27 17:44:13 +03:00
parent 9259728d16
commit f4daa4b61a
9 changed files with 1577 additions and 1418 deletions

View File

@ -10,6 +10,7 @@
#include "td/telegram/AuthManager.hpp"
#include "td/telegram/ConfigManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogFilterManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/MessagesManager.h"
@ -1036,6 +1037,8 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
}
td_->attach_menu_manager_->init();
td_->messages_manager_->on_authorization_success();
td_->dialog_filter_manager_->on_authorization_success(); // must be after MessagesManager::on_authorization_success()
// to have folders created
td_->notification_manager_->init();
td_->stickers_manager_->init();
td_->theme_manager_->init();

View File

@ -644,16 +644,12 @@ void DialogFilter::sort_input_dialog_ids(const Td *td, const char *source) {
}
vector<FolderId> DialogFilter::get_folder_ids() const {
if (!can_have_archived_dialogs()) {
if (exclude_archived_ && pinned_dialog_ids_.empty() && included_dialog_ids_.empty()) {
return {FolderId::main()};
}
return {FolderId::main(), FolderId::archive()};
}
bool DialogFilter::can_have_archived_dialogs() const {
return !(exclude_archived_ && pinned_dialog_ids_.empty() && included_dialog_ids_.empty());
}
bool DialogFilter::need_dialog(const Td *td, DialogId dialog_id, bool has_unread_mentions, bool is_muted,
bool has_unread_messages, FolderId folder_id) const {
if (is_dialog_included(dialog_id)) {

View File

@ -50,7 +50,7 @@ class DialogFilter {
return dialog_filter_id_;
}
const vector<InputDialogId> &get_pinned_dialog_ids() const {
const vector<InputDialogId> &get_pinned_input_dialog_ids() const {
return pinned_dialog_ids_;
}
@ -85,8 +85,6 @@ class DialogFilter {
vector<FolderId> get_folder_ids() const;
bool can_have_archived_dialogs() const;
bool need_dialog(const Td *td, DialogId dialog_id, bool has_unread_mentions, bool is_muted, bool has_unread_messages,
FolderId folder_id) const;

File diff suppressed because it is too large Load Diff

View File

@ -8,11 +8,13 @@
#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"
#include "td/actor/actor.h"
#include "td/actor/Timeout.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
@ -27,12 +29,49 @@ class DialogFilterManager final : public Actor {
public:
DialogFilterManager(Td *td, ActorShared<> parent);
void init();
void on_authorization_success();
void on_update_dialog_filters();
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;
bool need_dialog_in_filter(DialogFilterId dialog_filter_id, DialogId dialog_id, bool has_unread_mentions,
bool is_muted, bool has_unread_messages, FolderId folder_id) 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 create_dialog_filter(td_api::object_ptr<td_api::chatFilter> filter,
Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise);
void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter,
Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise);
void delete_dialog_filter(DialogFilterId dialog_filter_id, Promise<Unit> &&promise);
void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
Promise<Unit> &&promise);
td_api::object_ptr<td_api::chatFilter> get_chat_filter_object(DialogFilterId dialog_filter_id);
td_api::object_ptr<td_api::chatFilter> get_chat_filter_object(const DialogFilter *dialog_filter);
bool is_recommended_dialog_filter(const DialogFilter *dialog_filter);
void get_recommended_dialog_filters(Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise);
void load_dialog_filter(DialogFilterId dialog_filter_id, bool force, Promise<Unit> &&promise);
@ -40,7 +79,15 @@ class DialogFilterManager final : public Actor {
void load_dialog_filter_dialogs(DialogFilterId dialog_filter_id, vector<InputDialogId> &&input_dialog_ids,
Promise<Unit> &&promise);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
private:
static constexpr int32 DIALOG_FILTERS_CACHE_TIME = 86400;
class DialogFiltersLogEvent;
void hangup() final;
void tear_down() final;
struct RecommendedDialogFilter {
@ -48,6 +95,63 @@ class DialogFilterManager final : public Actor {
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);
static void on_reload_dialog_filters_timeout(void *messages_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::chatFilter> get_chat_filter_object(const DialogFilter *dialog_filter);
void send_update_chat_filters();
td_api::object_ptr<td_api::updateChatFilters> get_update_chat_filters_object() const;
void do_edit_dialog_filter(unique_ptr<DialogFilter> &&filter, bool need_synchronize, const char *source);
Result<unique_ptr<DialogFilter>> create_dialog_filter(DialogFilterId dialog_filter_id,
td_api::object_ptr<td_api::chatFilter> filter);
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);
void on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result);
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);
int32 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,
Promise<td_api::object_ptr<td_api::recommendedChatFilters>> &&promise);
@ -62,8 +166,24 @@ class DialogFilterManager final : public Actor {
void delete_dialogs_from_filter(const DialogFilter *dialog_filter, vector<DialogId> &&dialog_ids, const char *source);
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;
bool is_update_chat_filters_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_;
Td *td_;
ActorShared<> parent_;
};

File diff suppressed because it is too large Load Diff

View File

@ -318,8 +318,6 @@ class MessagesManager final : public Actor {
void on_update_dialog_message_ttl(DialogId dialog_id, MessageTtl message_ttl);
void on_update_dialog_filters();
void on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&update,
bool skip_new_entities, Promise<Unit> &&promise);
@ -532,6 +530,14 @@ class MessagesManager final : public Actor {
void after_set_typing_query(DialogId dialog_id, int32 generation);
void add_dialog_list_for_dialog_filter(DialogFilterId dialog_filter_id);
void edit_dialog_list_for_dialog_filter(unique_ptr<DialogFilter> &old_dialog_filter,
unique_ptr<DialogFilter> new_dialog_filter, bool &disable_get_dialog_filter,
const char *source);
void delete_dialog_list_for_dialog_filter(DialogFilterId dialog_filter_id, const char *source);
vector<DialogListId> get_dialog_lists_to_add_dialog(DialogId dialog_id);
void add_dialog_to_list(DialogId dialog_id, DialogListId dialog_list_id, Promise<Unit> &&promise);
@ -667,21 +673,7 @@ class MessagesManager final : public Actor {
bool is_dialog_in_dialog_list(DialogId dialog_id) const;
DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id);
const DialogFilter *get_dialog_filter(DialogFilterId dialog_filter_id) const;
void create_dialog_filter(td_api::object_ptr<td_api::chatFilter> filter,
Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise);
void edit_dialog_filter(DialogFilterId dialog_filter_id, td_api::object_ptr<td_api::chatFilter> filter,
Promise<td_api::object_ptr<td_api::chatFilterInfo>> &&promise);
void do_edit_dialog_filter(unique_ptr<DialogFilter> &&filter, bool need_synchronize, const char *source);
void delete_dialog_filter(DialogFilterId dialog_filter_id, Promise<Unit> &&promise);
void reorder_dialog_filters(vector<DialogFilterId> dialog_filter_ids, int32 main_dialog_list_position,
Promise<Unit> &&promise);
Status can_add_dialog_to_filter(DialogId dialog_id);
Status delete_dialog_reply_markup(DialogId dialog_id, MessageId message_id) TD_WARN_UNUSED_RESULT;
@ -1788,8 +1780,6 @@ class MessagesManager final : public Actor {
class UnpinAllDialogMessagesOnServerLogEvent;
class UpdateDialogNotificationSettingsOnServerLogEvent;
class DialogFiltersLogEvent;
static constexpr size_t MAX_GROUPED_MESSAGES = 10; // server side limit
static constexpr int32 MAX_GET_DIALOGS = 100; // server side limit
static constexpr int32 MAX_GET_HISTORY = 100; // server side limit
@ -1802,7 +1792,6 @@ class MessagesManager final : public Actor {
static constexpr size_t MAX_TITLE_LENGTH = 128; // server side limit for chat title
static constexpr size_t MAX_DESCRIPTION_LENGTH = 255; // server side limit for chat description
static constexpr int32 MAX_PRIVATE_MESSAGE_TTL = 60; // server side limit
static constexpr int32 DIALOG_FILTERS_CACHE_TIME = 86400;
static constexpr size_t MIN_DELETED_ASYNCHRONOUSLY_MESSAGES = 10;
static constexpr size_t MAX_UNLOADED_MESSAGES = 5000;
@ -2540,8 +2529,6 @@ class MessagesManager final : public Actor {
void send_update_chat_last_message_impl(const Dialog *d, const char *source) const;
void send_update_chat_filters();
void send_update_unread_message_count(DialogList &list, DialogId dialog_id, bool force, const char *source,
bool from_database = false);
@ -2619,8 +2606,6 @@ class MessagesManager final : public Actor {
void recalc_unread_count(DialogListId dialog_list_id, int32 old_dialog_total_count, bool force);
td_api::object_ptr<td_api::updateChatFilters> get_update_chat_filters_object() const;
td_api::object_ptr<td_api::updateUnreadMessageCount> get_update_unread_message_count_object(
const DialogList &list) const;
@ -2820,51 +2805,9 @@ class MessagesManager final : public Actor {
void reload_pinned_dialogs(DialogListId dialog_list_id, Promise<Unit> &&promise);
static double get_dialog_filters_cache_time();
void schedule_dialog_filters_reload(double timeout);
static void on_reload_dialog_filters_timeout(void *messages_manager_ptr);
void reload_dialog_filters();
void on_get_dialog_filters(Result<vector<tl_object_ptr<telegram_api::DialogFilter>>> r_filters, bool dummy);
bool need_synchronize_dialog_filters() const;
void synchronize_dialog_filters();
void update_dialogs_hints(const Dialog *d);
void update_dialogs_hints_rating(const Dialog *d);
Result<unique_ptr<DialogFilter>> create_dialog_filter(DialogFilterId dialog_filter_id,
td_api::object_ptr<td_api::chatFilter> filter);
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);
void on_delete_dialog_filter(DialogFilterId dialog_filter_id, Status result);
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);
int32 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;
vector<FolderId> get_dialog_list_folder_ids(const DialogList &list) const;
bool has_dialogs_from_folder(const DialogList &list, const DialogFolder &folder) const;
@ -3590,18 +3533,6 @@ class MessagesManager final : public Actor {
std::unordered_map<DialogListId, DialogList, DialogListIdHash> dialog_lists_;
std::unordered_map<FolderId, DialogFolder, FolderIdHash> dialog_folders_;
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;
bool is_update_chat_filters_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
FlatHashMap<DialogId, string, DialogIdHash> active_get_channel_differencies_;
FlatHashMap<DialogId, uint64, DialogIdHash> get_channel_difference_to_log_event_id_;
FlatHashMap<DialogId, int32, DialogIdHash> channel_get_difference_retry_timeouts_;
@ -3623,8 +3554,6 @@ class MessagesManager final : public Actor {
MultiTimeout preload_folder_dialog_list_timeout_{"PreloadFolderDialogListTimeout"};
MultiTimeout update_viewed_messages_timeout_{"UpdateViewedMessagesTimeout"};
Timeout reload_dialog_filters_timeout_;
Hints dialogs_hints_; // search dialogs by title and usernames
FlatHashSet<FullMessageId, FullMessageIdHash> active_live_location_full_message_ids_;

View File

@ -4269,6 +4269,8 @@ void Td::on_request(uint64 id, const td_api::getCurrentState &request) {
notification_settings_manager_->get_current_state(updates);
dialog_filter_manager_->get_current_state(updates);
messages_manager_->get_current_state(updates);
notification_manager_->get_current_state(updates);
@ -6131,7 +6133,7 @@ void Td::on_request(uint64 id, td_api::createChatFilter &request) {
CLEAN_INPUT_STRING(request.filter_->title_);
CLEAN_INPUT_STRING(request.filter_->icon_name_);
CREATE_REQUEST_PROMISE();
messages_manager_->create_dialog_filter(std::move(request.filter_), std::move(promise));
dialog_filter_manager_->create_dialog_filter(std::move(request.filter_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::editChatFilter &request) {
@ -6142,20 +6144,20 @@ void Td::on_request(uint64 id, td_api::editChatFilter &request) {
CLEAN_INPUT_STRING(request.filter_->title_);
CLEAN_INPUT_STRING(request.filter_->icon_name_);
CREATE_REQUEST_PROMISE();
messages_manager_->edit_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(request.filter_),
std::move(promise));
dialog_filter_manager_->edit_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(request.filter_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::deleteChatFilter &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->delete_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(promise));
dialog_filter_manager_->delete_dialog_filter(DialogFilterId(request.chat_filter_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::reorderChatFilters &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->reorder_dialog_filters(
dialog_filter_manager_->reorder_dialog_filters(
transform(request.chat_filter_ids_, [](int32 id) { return DialogFilterId(id); }),
request.main_chat_list_position_, std::move(promise));
}

View File

@ -17,6 +17,7 @@
#include "td/telegram/ConfigManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/DialogAction.h"
#include "td/telegram/DialogFilterManager.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogInviteLink.h"
#include "td/telegram/DialogParticipant.h"
@ -3658,17 +3659,17 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogUnreadMar
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogFilter> update, Promise<Unit> &&promise) {
td_->messages_manager_->on_update_dialog_filters();
td_->dialog_filter_manager_->on_update_dialog_filters();
promise.set_value(Unit());
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogFilters> update, Promise<Unit> &&promise) {
td_->messages_manager_->on_update_dialog_filters();
td_->dialog_filter_manager_->on_update_dialog_filters();
promise.set_value(Unit());
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateDialogFilterOrder> update, Promise<Unit> &&promise) {
td_->messages_manager_->on_update_dialog_filters();
td_->dialog_filter_manager_->on_update_dialog_filters();
promise.set_value(Unit());
}