Add DialogFilter::can_include_dialog.
This commit is contained in:
parent
4c5651027e
commit
dbf66634cf
@ -172,6 +172,23 @@ bool DialogFilter::is_empty(bool for_server) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DialogFilter::can_include_dialog(DialogId dialog_id) const {
|
||||||
|
if (InputDialogId::contains(included_dialog_ids, dialog_id) ||
|
||||||
|
InputDialogId::contains(pinned_dialog_ids, dialog_id)) {
|
||||||
|
// the dialog is already included
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (included_dialog_ids.size() + pinned_dialog_ids.size() < narrow_cast<size_t>(get_max_filter_dialogs())) {
|
||||||
|
// fast path
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto new_dialog_filter = make_unique<DialogFilter>(*this);
|
||||||
|
new_dialog_filter->include_dialog(InputDialogId(dialog_id));
|
||||||
|
return new_dialog_filter->check_limits().is_ok();
|
||||||
|
}
|
||||||
|
|
||||||
Status DialogFilter::check_limits() const {
|
Status DialogFilter::check_limits() const {
|
||||||
auto get_server_dialog_count = [](const vector<InputDialogId> &input_dialog_ids) {
|
auto get_server_dialog_count = [](const vector<InputDialogId> &input_dialog_ids) {
|
||||||
int32 result = 0;
|
int32 result = 0;
|
||||||
|
@ -70,6 +70,8 @@ class DialogFilter {
|
|||||||
return dialog_filter_id;
|
return dialog_filter_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool can_include_dialog(DialogId dialog_id) const;
|
||||||
|
|
||||||
Status check_limits() const;
|
Status check_limits() const;
|
||||||
|
|
||||||
static string get_emoji_by_icon_name(const string &icon_name);
|
static string get_emoji_by_icon_name(const string &icon_name);
|
||||||
|
@ -34443,23 +34443,8 @@ vector<DialogListId> MessagesManager::get_dialog_lists_to_add_dialog(DialogId di
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &dialog_filter : dialog_filters_) {
|
for (const auto &dialog_filter : dialog_filters_) {
|
||||||
auto dialog_filter_id = dialog_filter->dialog_filter_id;
|
if (dialog_filter->can_include_dialog(dialog_id)) {
|
||||||
if (!InputDialogId::contains(dialog_filter->included_dialog_ids, dialog_id) &&
|
result.push_back(DialogListId(dialog_filter->get_dialog_filter_id()));
|
||||||
!InputDialogId::contains(dialog_filter->pinned_dialog_ids, dialog_id)) {
|
|
||||||
// the dialog isn't added yet to the dialog list
|
|
||||||
// check that it can be actually added
|
|
||||||
if (dialog_filter->included_dialog_ids.size() + dialog_filter->pinned_dialog_ids.size() <
|
|
||||||
narrow_cast<size_t>(DialogFilter::get_max_filter_dialogs())) {
|
|
||||||
// fast path
|
|
||||||
result.push_back(DialogListId(dialog_filter_id));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto new_dialog_filter = make_unique<DialogFilter>(*dialog_filter);
|
|
||||||
new_dialog_filter->include_dialog(get_input_dialog_id(dialog_id));
|
|
||||||
if (new_dialog_filter->check_limits().is_ok()) {
|
|
||||||
result.push_back(DialogListId(dialog_filter_id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user