Add class DialogFilterDialogInfo.

This commit is contained in:
levlam 2023-03-27 18:34:25 +03:00
parent ee0922d23d
commit f12fedd4d6
8 changed files with 51 additions and 26 deletions

View File

@ -560,6 +560,7 @@ set(TDLIB_SOURCE
td/telegram/DialogDb.h
td/telegram/DialogEventLog.h
td/telegram/DialogFilter.h
td/telegram/DialogFilterDialogInfo.h
td/telegram/DialogFilterId.h
td/telegram/DialogFilterInviteLink.h
td/telegram/DialogFilterManager.h

View File

@ -650,8 +650,8 @@ vector<FolderId> DialogFilter::get_folder_ids() const {
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 {
bool DialogFilter::need_dialog(const Td *td, const DialogFilterDialogInfo &dialog_info) const {
auto dialog_id = dialog_info.dialog_id_;
if (is_dialog_included(dialog_id)) {
return true;
}
@ -670,15 +670,15 @@ bool DialogFilter::need_dialog(const Td *td, DialogId dialog_id, bool has_unread
}
}
}
if (!has_unread_mentions) {
if (exclude_muted_ && is_muted) {
if (!dialog_info.has_unread_mentions_) {
if (exclude_muted_ && dialog_info.is_muted_) {
return false;
}
if (exclude_read_ && !has_unread_messages) {
if (exclude_read_ && !dialog_info.has_unread_messages_) {
return false;
}
}
if (exclude_archived_ && folder_id == FolderId::archive()) {
if (exclude_archived_ && dialog_info.folder_id_ == FolderId::archive()) {
return false;
}
switch (dialog_id.get_type()) {

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/DialogFilterDialogInfo.h"
#include "td/telegram/DialogFilterId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/FolderId.h"
@ -85,8 +86,7 @@ class DialogFilter {
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;
bool need_dialog(const Td *td, const DialogFilterDialogInfo &dialog_info) const;
static vector<DialogFilterId> get_dialog_filter_ids(const vector<unique_ptr<DialogFilter>> &dialog_filters,
int32 main_dialog_list_position);

View File

@ -0,0 +1,24 @@
//
// 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
#include "td/telegram/DialogId.h"
#include "td/telegram/FolderId.h"
#include "td/utils/common.h"
namespace td {
struct DialogFilterDialogInfo {
DialogId dialog_id_;
FolderId folder_id_;
bool has_unread_mentions_ = false;
bool is_muted_ = false;
bool has_unread_messages_ = false;
};
} // namespace td

View File

@ -368,12 +368,11 @@ vector<DialogFilterId> DialogFilterManager::get_dialog_filters_to_add_dialog(Dia
return result;
}
bool DialogFilterManager::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 DialogFilterManager::need_dialog_in_filter(DialogFilterId dialog_filter_id,
const DialogFilterDialogInfo &dialog_info) const {
const auto *dialog_filter = get_dialog_filter(dialog_filter_id);
CHECK(dialog_filter != nullptr);
return dialog_filter->need_dialog(td_, dialog_id, has_unread_mentions, is_muted, has_unread_messages, folder_id);
return dialog_filter->need_dialog(td_, dialog_info);
}
bool DialogFilterManager::is_dialog_pinned(DialogFilterId dialog_filter_id, DialogId dialog_id) const {

View File

@ -6,6 +6,7 @@
//
#pragma once
#include "td/telegram/DialogFilterDialogInfo.h"
#include "td/telegram/DialogFilterId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/FolderId.h"
@ -43,8 +44,7 @@ class DialogFilterManager final : public Actor {
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 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;

View File

@ -33063,7 +33063,7 @@ void MessagesManager::edit_dialog_list_for_dialog_filter(unique_ptr<DialogFilter
const DialogPositionInList old_position = get_dialog_position_in_list(old_list_ptr, d);
// can't use get_dialog_position_in_list, because need_dialog_in_list calls get_dialog_filter
DialogPositionInList new_position;
if (need_dialog_in_filter(d, new_dialog_filter.get())) {
if (new_dialog_filter->need_dialog(td_, get_dialog_info_for_dialog_filter(d))) {
new_position.private_order = get_dialog_private_order(&new_list, d);
if (new_position.private_order != 0) {
new_position.public_order =
@ -37783,14 +37783,16 @@ void MessagesManager::remove_dialog_from_list(Dialog *d, DialogListId dialog_lis
CHECK(is_removed);
}
bool MessagesManager::need_dialog_in_filter(const Dialog *d, const DialogFilter *dialog_filter) const {
DialogFilterDialogInfo MessagesManager::get_dialog_info_for_dialog_filter(const Dialog *d) const {
CHECK(d != nullptr);
CHECK(dialog_filter != nullptr);
CHECK(d->order != DEFAULT_ORDER);
return dialog_filter->need_dialog(
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);
DialogFilterDialogInfo dialog_info;
dialog_info.dialog_id_ = d->dialog_id;
dialog_info.folder_id_ = d->folder_id;
dialog_info.has_unread_mentions_ = d->unread_mention_count != 0 && !is_dialog_mention_notifications_disabled(d);
dialog_info.is_muted_ = is_dialog_muted(d);
dialog_info.has_unread_messages_ = d->server_unread_count + d->local_unread_count != 0 || d->is_marked_as_unread;
return dialog_info;
}
bool MessagesManager::is_dialog_in_dialog_list(DialogId dialog_id) const {
@ -37808,10 +37810,8 @@ bool MessagesManager::need_dialog_in_list(const Dialog *d, const DialogList &lis
return d->folder_id == list.dialog_list_id.get_folder_id();
}
if (list.dialog_list_id.is_filter()) {
return td_->dialog_filter_manager_->need_dialog_in_filter(
list.dialog_list_id.get_filter_id(), 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);
return td_->dialog_filter_manager_->need_dialog_in_filter(list.dialog_list_id.get_filter_id(),
get_dialog_info_for_dialog_filter(d));
}
UNREACHABLE();
return false;

View File

@ -13,6 +13,7 @@
#include "td/telegram/DialogAction.h"
#include "td/telegram/DialogDate.h"
#include "td/telegram/DialogDb.h"
#include "td/telegram/DialogFilterDialogInfo.h"
#include "td/telegram/DialogFilterId.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogListId.h"
@ -2818,7 +2819,7 @@ class MessagesManager final : public Actor {
static void remove_dialog_from_list(Dialog *d, DialogListId dialog_list_id);
bool need_dialog_in_filter(const Dialog *d, const DialogFilter *dialog_filter) const;
DialogFilterDialogInfo get_dialog_info_for_dialog_filter(const Dialog *d) const;
bool need_dialog_in_list(const Dialog *d, const DialogList &list) const;