Add DialogFilter::need_dialog.

This commit is contained in:
levlam 2023-03-22 01:17:07 +03:00
parent 06940b2817
commit f792137692
3 changed files with 75 additions and 64 deletions

View File

@ -541,6 +541,75 @@ vector<FolderId> DialogFilter::get_folder_ids() const {
return {FolderId::main(), FolderId::archive()}; return {FolderId::main(), FolderId::archive()};
} }
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 (InputDialogId::contains(pinned_dialog_ids, dialog_id)) {
return true;
}
if (InputDialogId::contains(included_dialog_ids, dialog_id)) {
return true;
}
if (InputDialogId::contains(excluded_dialog_ids, dialog_id)) {
return false;
}
if (dialog_id.get_type() == DialogType::SecretChat) {
auto user_id = td->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
if (user_id.is_valid()) {
auto user_dialog_id = DialogId(user_id);
if (InputDialogId::contains(pinned_dialog_ids, user_dialog_id)) {
return true;
}
if (InputDialogId::contains(included_dialog_ids, user_dialog_id)) {
return true;
}
if (InputDialogId::contains(excluded_dialog_ids, user_dialog_id)) {
return false;
}
}
}
if (!has_unread_mentions) {
if (exclude_muted && is_muted) {
return false;
}
if (exclude_read && !has_unread_messages) {
return false;
}
}
if (exclude_archived && folder_id == FolderId::archive()) {
return false;
}
switch (dialog_id.get_type()) {
case DialogType::User: {
auto user_id = dialog_id.get_user_id();
if (td->contacts_manager_->is_user_bot(user_id)) {
return include_bots;
}
if (user_id == td->contacts_manager_->get_my_id() || td->contacts_manager_->is_user_contact(user_id)) {
return include_contacts;
}
return include_non_contacts;
}
case DialogType::Chat:
return include_groups;
case DialogType::Channel:
return td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id()) ? include_channels
: include_groups;
case DialogType::SecretChat: {
auto user_id = td->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
if (td->contacts_manager_->is_user_bot(user_id)) {
return include_bots;
}
if (td->contacts_manager_->is_user_contact(user_id)) {
return include_contacts;
}
return include_non_contacts;
}
default:
UNREACHABLE();
return false;
}
}
vector<DialogFilterId> DialogFilter::get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters, vector<DialogFilterId> DialogFilter::get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters,
int32 main_dialog_list_position) { int32 main_dialog_list_position) {
auto result = transform(dialog_filters, [](const auto &dialog_filter) { return dialog_filter->dialog_filter_id; }); auto result = transform(dialog_filters, [](const auto &dialog_filter) { return dialog_filter->dialog_filter_id; });

View File

@ -93,6 +93,9 @@ class DialogFilter {
vector<FolderId> get_folder_ids() const; vector<FolderId> get_folder_ids() 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;
static vector<DialogFilterId> get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters, static vector<DialogFilterId> get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters,
int32 main_dialog_list_position); int32 main_dialog_list_position);

View File

@ -39111,70 +39111,9 @@ bool MessagesManager::need_dialog_in_filter(const Dialog *d, const DialogFilter
CHECK(filter != nullptr); CHECK(filter != nullptr);
CHECK(d->order != DEFAULT_ORDER); CHECK(d->order != DEFAULT_ORDER);
if (InputDialogId::contains(filter->pinned_dialog_ids, d->dialog_id)) { return filter->need_dialog(
return true; td_, d->dialog_id, d->unread_mention_count != 0 && !is_dialog_mention_notifications_disabled(d),
} is_dialog_muted(d), d->server_unread_count + d->local_unread_count != 0 || d->is_marked_as_unread, d->folder_id);
if (InputDialogId::contains(filter->included_dialog_ids, d->dialog_id)) {
return true;
}
if (InputDialogId::contains(filter->excluded_dialog_ids, d->dialog_id)) {
return false;
}
if (d->dialog_id.get_type() == DialogType::SecretChat) {
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(d->dialog_id.get_secret_chat_id());
if (user_id.is_valid()) {
auto dialog_id = DialogId(user_id);
if (InputDialogId::contains(filter->pinned_dialog_ids, dialog_id)) {
return true;
}
if (InputDialogId::contains(filter->included_dialog_ids, dialog_id)) {
return true;
}
if (InputDialogId::contains(filter->excluded_dialog_ids, dialog_id)) {
return false;
}
}
}
if (d->unread_mention_count == 0 || is_dialog_mention_notifications_disabled(d)) {
if (filter->exclude_muted && is_dialog_muted(d)) {
return false;
}
if (filter->exclude_read && d->server_unread_count + d->local_unread_count == 0 && !d->is_marked_as_unread) {
return false;
}
}
if (filter->exclude_archived && d->folder_id == FolderId::archive()) {
return false;
}
switch (d->dialog_id.get_type()) {
case DialogType::User: {
auto user_id = d->dialog_id.get_user_id();
if (td_->contacts_manager_->is_user_bot(user_id)) {
return filter->include_bots;
}
if (user_id == td_->contacts_manager_->get_my_id() || td_->contacts_manager_->is_user_contact(user_id)) {
return filter->include_contacts;
}
return filter->include_non_contacts;
}
case DialogType::Chat:
return filter->include_groups;
case DialogType::Channel:
return is_broadcast_channel(d->dialog_id) ? filter->include_channels : filter->include_groups;
case DialogType::SecretChat: {
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(d->dialog_id.get_secret_chat_id());
if (td_->contacts_manager_->is_user_bot(user_id)) {
return filter->include_bots;
}
if (td_->contacts_manager_->is_user_contact(user_id)) {
return filter->include_contacts;
}
return filter->include_non_contacts;
}
default:
UNREACHABLE();
return false;
}
} }
bool MessagesManager::need_dialog_in_list(const Dialog *d, const DialogList &list) const { bool MessagesManager::need_dialog_in_list(const Dialog *d, const DialogList &list) const {