2020-06-02 12:58:53 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2020-06-02 12:58:53 +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
|
|
|
|
|
|
|
|
#include "td/telegram/DialogFilterId.h"
|
2023-03-24 12:14:37 +01:00
|
|
|
#include "td/telegram/DialogId.h"
|
2023-03-21 15:02:09 +01:00
|
|
|
#include "td/telegram/FolderId.h"
|
2020-06-02 12:58:53 +02:00
|
|
|
#include "td/telegram/InputDialogId.h"
|
2020-06-05 02:43:13 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
2020-06-02 12:58:53 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2022-02-07 22:04:34 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
2020-06-02 12:58:53 +02:00
|
|
|
#include "td/utils/Status.h"
|
2020-06-07 17:14:52 +02:00
|
|
|
#include "td/utils/StringBuilder.h"
|
2020-06-02 12:58:53 +02:00
|
|
|
|
2023-03-21 14:12:47 +01:00
|
|
|
#include <functional>
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
namespace td {
|
|
|
|
|
2023-03-21 14:26:06 +01:00
|
|
|
class Td;
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
class DialogFilter {
|
|
|
|
public:
|
2022-05-23 18:04:09 +02:00
|
|
|
static int32 get_max_filter_dialogs();
|
|
|
|
|
2022-04-19 16:43:24 +02:00
|
|
|
static unique_ptr<DialogFilter> get_dialog_filter(telegram_api::object_ptr<telegram_api::DialogFilter> filter_ptr,
|
2020-06-02 12:58:53 +02:00
|
|
|
bool with_id);
|
|
|
|
|
2023-03-21 14:55:07 +01:00
|
|
|
static Result<unique_ptr<DialogFilter>> create_dialog_filter(Td *td, DialogFilterId dialog_filter_id,
|
|
|
|
td_api::object_ptr<td_api::chatFilter> filter);
|
|
|
|
|
2023-03-21 21:21:19 +01:00
|
|
|
void set_dialog_is_pinned(InputDialogId input_dialog_id, bool is_pinned);
|
|
|
|
|
2023-03-22 12:14:21 +01:00
|
|
|
void set_pinned_dialog_ids(vector<InputDialogId> &&input_dialog_ids);
|
|
|
|
|
2023-03-21 21:21:19 +01:00
|
|
|
void include_dialog(InputDialogId input_dialog_id);
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
void remove_secret_chat_dialog_ids();
|
|
|
|
|
2023-03-21 21:20:33 +01:00
|
|
|
void remove_dialog_id(DialogId dialog_id);
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
bool is_empty(bool for_server) const;
|
|
|
|
|
2023-03-22 21:19:32 +01:00
|
|
|
const DialogFilterId &get_dialog_filter_id() const {
|
2023-03-23 15:26:24 +01:00
|
|
|
return dialog_filter_id_;
|
2023-03-21 22:28:18 +01:00
|
|
|
}
|
2023-03-22 21:05:13 +01:00
|
|
|
|
2023-03-22 21:09:57 +01:00
|
|
|
const vector<InputDialogId> &get_pinned_dialog_ids() const {
|
2023-03-23 15:26:24 +01:00
|
|
|
return pinned_dialog_ids_;
|
2023-03-22 21:09:57 +01:00
|
|
|
}
|
|
|
|
|
2023-03-22 21:05:13 +01:00
|
|
|
bool is_dialog_pinned(DialogId dialog_id) const;
|
2023-03-21 22:28:18 +01:00
|
|
|
|
2023-03-22 20:30:00 +01:00
|
|
|
bool is_dialog_included(DialogId dialog_id) const;
|
|
|
|
|
2023-03-22 12:26:05 +01:00
|
|
|
bool can_include_dialog(DialogId dialog_id) const;
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
Status check_limits() const;
|
|
|
|
|
|
|
|
static string get_emoji_by_icon_name(const string &icon_name);
|
|
|
|
|
|
|
|
string get_icon_name() const;
|
|
|
|
|
2020-06-05 02:43:13 +02:00
|
|
|
static string get_default_icon_name(const td_api::chatFilter *filter);
|
|
|
|
|
2022-04-19 16:43:24 +02:00
|
|
|
telegram_api::object_ptr<telegram_api::DialogFilter> get_input_dialog_filter() const;
|
2020-06-02 12:58:53 +02:00
|
|
|
|
2023-03-21 23:00:54 +01:00
|
|
|
td_api::object_ptr<td_api::chatFilter> get_chat_filter_object(const vector<DialogId> &unknown_dialog_ids) const;
|
|
|
|
|
2020-06-07 20:51:21 +02:00
|
|
|
td_api::object_ptr<td_api::chatFilterInfo> get_chat_filter_info_object() const;
|
|
|
|
|
2023-03-21 14:12:47 +01:00
|
|
|
void for_each_dialog(std::function<void(const InputDialogId &)> callback) const;
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
// merges changes from old_server_filter to new_server_filter in old_filter
|
|
|
|
static unique_ptr<DialogFilter> merge_dialog_filter_changes(const DialogFilter *old_filter,
|
|
|
|
const DialogFilter *old_server_filter,
|
|
|
|
const DialogFilter *new_server_filter);
|
|
|
|
|
2023-03-21 14:26:06 +01:00
|
|
|
void sort_input_dialog_ids(const Td *td, const char *source);
|
|
|
|
|
2023-03-21 15:02:09 +01:00
|
|
|
vector<FolderId> get_folder_ids() const;
|
|
|
|
|
2023-03-22 20:35:37 +01:00
|
|
|
bool can_have_archived_dialogs() const;
|
|
|
|
|
2023-03-21 23:17:07 +01:00
|
|
|
bool need_dialog(const Td *td, DialogId dialog_id, bool has_unread_mentions, bool is_muted, bool has_unread_messages,
|
|
|
|
FolderId folder_id) const;
|
|
|
|
|
2023-03-21 20:35:00 +01:00
|
|
|
static vector<DialogFilterId> get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters,
|
|
|
|
int32 main_dialog_list_position);
|
|
|
|
|
2023-03-21 23:24:14 +01:00
|
|
|
static bool set_dialog_filters_order(vector<unique_ptr<DialogFilter>> &dialog_filters,
|
|
|
|
vector<DialogFilterId> dialog_filter_ids);
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
static bool are_similar(const DialogFilter &lhs, const DialogFilter &rhs);
|
|
|
|
|
|
|
|
static bool are_equivalent(const DialogFilter &lhs, const DialogFilter &rhs);
|
|
|
|
|
|
|
|
static bool are_flags_equal(const DialogFilter &lhs, const DialogFilter &rhs);
|
|
|
|
|
2023-03-22 21:19:32 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
|
|
|
|
2020-06-02 12:58:53 +02:00
|
|
|
private:
|
2023-03-23 15:26:24 +01:00
|
|
|
DialogFilterId dialog_filter_id_;
|
|
|
|
string title_;
|
|
|
|
string emoji_;
|
|
|
|
vector<InputDialogId> pinned_dialog_ids_;
|
|
|
|
vector<InputDialogId> included_dialog_ids_;
|
|
|
|
vector<InputDialogId> excluded_dialog_ids_;
|
|
|
|
bool exclude_muted_ = false;
|
|
|
|
bool exclude_read_ = false;
|
|
|
|
bool exclude_archived_ = false;
|
|
|
|
bool include_contacts_ = false;
|
|
|
|
bool include_non_contacts_ = false;
|
|
|
|
bool include_bots_ = false;
|
|
|
|
bool include_groups_ = false;
|
|
|
|
bool include_channels_ = false;
|
2023-03-22 21:19:32 +01:00
|
|
|
|
2022-02-07 20:41:07 +01:00
|
|
|
static FlatHashMap<string, string> emoji_to_icon_name_;
|
|
|
|
static FlatHashMap<string, string> icon_name_to_emoji_;
|
2020-06-02 12:58:53 +02:00
|
|
|
|
|
|
|
static void init_icon_names();
|
2021-12-24 18:42:49 +01:00
|
|
|
|
|
|
|
string get_chosen_or_default_icon_name() const;
|
2023-03-22 21:19:32 +01:00
|
|
|
|
|
|
|
friend bool operator==(const DialogFilter &lhs, const DialogFilter &rhs);
|
|
|
|
|
|
|
|
friend StringBuilder &operator<<(StringBuilder &string_builder, const DialogFilter &filter);
|
2020-06-02 12:58:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator==(const DialogFilter &lhs, const DialogFilter &rhs) {
|
2023-03-23 15:26:24 +01:00
|
|
|
return lhs.dialog_filter_id_ == rhs.dialog_filter_id_ && lhs.title_ == rhs.title_ && lhs.emoji_ == rhs.emoji_ &&
|
|
|
|
lhs.pinned_dialog_ids_ == rhs.pinned_dialog_ids_ && lhs.included_dialog_ids_ == rhs.included_dialog_ids_ &&
|
|
|
|
lhs.excluded_dialog_ids_ == rhs.excluded_dialog_ids_ && DialogFilter::are_flags_equal(lhs, rhs);
|
2020-06-02 12:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const DialogFilter &lhs, const DialogFilter &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator==(const unique_ptr<DialogFilter> &lhs, const unique_ptr<DialogFilter> &rhs) {
|
|
|
|
return *lhs == *rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const unique_ptr<DialogFilter> &lhs, const unique_ptr<DialogFilter> &rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringBuilder &operator<<(StringBuilder &string_builder, const DialogFilter &filter);
|
|
|
|
|
|
|
|
} // namespace td
|