Never add duplicate dialogs to filter.

GitOrigin-RevId: d708e60b6712610e27eff66c58a0574aa2cf5442
This commit is contained in:
levlam 2020-05-19 01:23:13 +03:00
parent d2b53fc023
commit 7970c9356a
3 changed files with 16 additions and 6 deletions

View File

@ -49,12 +49,17 @@ InputDialogId::InputDialogId(const tl_object_ptr<telegram_api::InputPeer> &input
} }
vector<InputDialogId> InputDialogId::get_input_dialog_ids( vector<InputDialogId> InputDialogId::get_input_dialog_ids(
const vector<tl_object_ptr<telegram_api::InputPeer>> &input_peers) { const vector<tl_object_ptr<telegram_api::InputPeer>> &input_peers,
std::unordered_set<DialogId, DialogIdHash> *added_dialog_ids) {
std::unordered_set<DialogId, DialogIdHash> temp_added_dialog_ids;
if (added_dialog_ids == nullptr) {
added_dialog_ids = &temp_added_dialog_ids;
}
vector<InputDialogId> result; vector<InputDialogId> result;
result.reserve(input_peers.size()); result.reserve(input_peers.size());
for (auto &input_peer : input_peers) { for (auto &input_peer : input_peers) {
InputDialogId input_dialog_id(input_peer); InputDialogId input_dialog_id(input_peer);
if (input_dialog_id.is_valid()) { if (input_dialog_id.is_valid() && added_dialog_ids->insert(input_dialog_id.get_dialog_id()).second) {
result.push_back(input_dialog_id); result.push_back(input_dialog_id);
} }
} }

View File

@ -12,6 +12,8 @@
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/StringBuilder.h" #include "td/utils/StringBuilder.h"
#include <unordered_set>
namespace td { namespace td {
class InputDialogId { class InputDialogId {
@ -26,7 +28,9 @@ class InputDialogId {
explicit InputDialogId(const tl_object_ptr<telegram_api::InputPeer> &input_peer); explicit InputDialogId(const tl_object_ptr<telegram_api::InputPeer> &input_peer);
static vector<InputDialogId> get_input_dialog_ids(const vector<tl_object_ptr<telegram_api::InputPeer>> &input_peers); static vector<InputDialogId> get_input_dialog_ids(
const vector<tl_object_ptr<telegram_api::InputPeer>> &input_peers,
std::unordered_set<DialogId, DialogIdHash> *added_dialog_ids = nullptr);
static vector<telegram_api::object_ptr<telegram_api::InputDialogPeer>> get_input_dialog_peers( static vector<telegram_api::object_ptr<telegram_api::InputDialogPeer>> get_input_dialog_peers(
const vector<InputDialogId> &input_dialog_ids); const vector<InputDialogId> &input_dialog_ids);

View File

@ -4813,9 +4813,10 @@ struct MessagesManager::DialogFilter {
dialog_filter->dialog_filter_id = dialog_filter_id; dialog_filter->dialog_filter_id = dialog_filter_id;
dialog_filter->title = std::move(filter->title_); dialog_filter->title = std::move(filter->title_);
dialog_filter->emoji = std::move(filter->emoticon_); dialog_filter->emoji = std::move(filter->emoticon_);
dialog_filter->pinned_dialog_ids = InputDialogId::get_input_dialog_ids(filter->pinned_peers_); std::unordered_set<DialogId, DialogIdHash> added_dialog_ids;
dialog_filter->included_dialog_ids = InputDialogId::get_input_dialog_ids(filter->include_peers_); dialog_filter->pinned_dialog_ids = InputDialogId::get_input_dialog_ids(filter->pinned_peers_, &added_dialog_ids);
dialog_filter->excluded_dialog_ids = InputDialogId::get_input_dialog_ids(filter->exclude_peers_); dialog_filter->included_dialog_ids = InputDialogId::get_input_dialog_ids(filter->include_peers_, &added_dialog_ids);
dialog_filter->excluded_dialog_ids = InputDialogId::get_input_dialog_ids(filter->exclude_peers_, &added_dialog_ids);
auto flags = filter->flags_; auto flags = filter->flags_;
dialog_filter->exclude_muted = (flags & telegram_api::dialogFilter::EXCLUDE_MUTED_MASK) != 0; dialog_filter->exclude_muted = (flags & telegram_api::dialogFilter::EXCLUDE_MUTED_MASK) != 0;
dialog_filter->exclude_read = (flags & telegram_api::dialogFilter::EXCLUDE_READ_MASK) != 0; dialog_filter->exclude_read = (flags & telegram_api::dialogFilter::EXCLUDE_READ_MASK) != 0;