Replace search_among_users with search_among_dialogs.
This commit is contained in:
parent
b349696e7f
commit
ffc847dbf5
@ -11506,12 +11506,12 @@ const DialogParticipant *ContactsManager::get_chat_participant(ChatId chat_id, U
|
|||||||
if (chat_full == nullptr) {
|
if (chat_full == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return get_chat_full_participant(chat_full, user_id);
|
return get_chat_full_participant(chat_full, DialogId(user_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
const DialogParticipant *ContactsManager::get_chat_full_participant(const ChatFull *chat_full, UserId user_id) {
|
const DialogParticipant *ContactsManager::get_chat_full_participant(const ChatFull *chat_full, DialogId dialog_id) {
|
||||||
for (const auto &dialog_participant : chat_full->participants) {
|
for (const auto &dialog_participant : chat_full->participants) {
|
||||||
if (dialog_participant.dialog_id == DialogId(user_id)) {
|
if (dialog_participant.dialog_id == dialog_id) {
|
||||||
return &dialog_participant;
|
return &dialog_participant;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11738,21 +11738,17 @@ void ContactsManager::on_get_channel_participants(
|
|||||||
|
|
||||||
if (!additional_query.empty()) {
|
if (!additional_query.empty()) {
|
||||||
auto dialog_ids = transform(result, [](const DialogParticipant &participant) { return participant.dialog_id; });
|
auto dialog_ids = transform(result, [](const DialogParticipant &participant) { return participant.dialog_id; });
|
||||||
td::remove_if(dialog_ids, [](DialogId dialog_id) { return dialog_id.get_type() != DialogType::User; });
|
std::pair<int32, vector<DialogId>> result_dialog_ids =
|
||||||
auto user_ids = transform(dialog_ids, [](DialogId dialog_id) { return dialog_id.get_user_id(); });
|
search_among_dialogs(dialog_ids, additional_query, additional_limit);
|
||||||
std::pair<int32, vector<UserId>> result_user_ids = search_among_users(user_ids, additional_query, additional_limit);
|
|
||||||
|
|
||||||
total_count = result_user_ids.first;
|
total_count = result_dialog_ids.first;
|
||||||
std::unordered_set<UserId, UserIdHash> result_user_ids_set(result_user_ids.second.begin(),
|
std::unordered_set<DialogId, DialogIdHash> result_dialog_ids_set(result_dialog_ids.second.begin(),
|
||||||
result_user_ids.second.end());
|
result_dialog_ids.second.end());
|
||||||
auto all_participants = std::move(result);
|
auto all_participants = std::move(result);
|
||||||
result.clear();
|
result.clear();
|
||||||
for (auto &participant : all_participants) {
|
for (auto &participant : all_participants) {
|
||||||
if (participant.dialog_id.get_type() != DialogType::User) {
|
if (result_dialog_ids_set.count(participant.dialog_id)) {
|
||||||
continue;
|
result_dialog_ids_set.erase(participant.dialog_id);
|
||||||
}
|
|
||||||
if (result_user_ids_set.count(participant.dialog_id.get_user_id())) {
|
|
||||||
result_user_ids_set.erase(participant.dialog_id.get_user_id());
|
|
||||||
result.push_back(std::move(participant));
|
result.push_back(std::move(participant));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -14420,26 +14416,39 @@ void ContactsManager::on_update_secret_chat(SecretChatId secret_chat_id, int64 a
|
|||||||
update_secret_chat(secret_chat, secret_chat_id);
|
update_secret_chat(secret_chat, secret_chat_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int32, vector<UserId>> ContactsManager::search_among_users(const vector<UserId> &user_ids,
|
std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const vector<DialogId> &dialog_ids,
|
||||||
const string &query, int32 limit) const {
|
const string &query, int32 limit) const {
|
||||||
Hints hints; // TODO cache Hints
|
Hints hints; // TODO cache Hints
|
||||||
|
|
||||||
for (auto user_id : user_ids) {
|
for (auto dialog_id : dialog_ids) {
|
||||||
|
int64 rating = 0;
|
||||||
|
if (dialog_id.get_type() == DialogType::User) {
|
||||||
|
auto user_id = dialog_id.get_user_id();
|
||||||
auto u = get_user(user_id);
|
auto u = get_user(user_id);
|
||||||
if (u == nullptr) {
|
if (u == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (query.empty()) {
|
if (query.empty()) {
|
||||||
hints.add(user_id.get(), Slice(" "));
|
hints.add(dialog_id.get(), Slice(" "));
|
||||||
} else {
|
} else {
|
||||||
hints.add(user_id.get(), PSLICE() << u->first_name << ' ' << u->last_name << ' ' << u->username);
|
hints.add(dialog_id.get(), PSLICE() << u->first_name << ' ' << u->last_name << ' ' << u->username);
|
||||||
}
|
}
|
||||||
hints.set_rating(user_id.get(), -get_user_was_online(u, user_id));
|
rating = -get_user_was_online(u, user_id);
|
||||||
|
} else {
|
||||||
|
if (!td_->messages_manager_->have_dialog_info(dialog_id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (query.empty()) {
|
||||||
|
hints.add(dialog_id.get(), Slice(" "));
|
||||||
|
} else {
|
||||||
|
hints.add(dialog_id.get(), td_->messages_manager_->get_dialog_title(dialog_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hints.set_rating(dialog_id.get(), rating);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = hints.search(query, limit, true);
|
auto result = hints.search(query, limit, true);
|
||||||
return {narrow_cast<int32>(result.first),
|
return {narrow_cast<int32>(result.first), transform(result.second, [](int64 key) { return DialogId(key); })};
|
||||||
transform(result.second, [](int64 key) { return UserId(narrow_cast<int32>(key)); })};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
|
void ContactsManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
|
||||||
@ -14614,20 +14623,20 @@ DialogParticipant ContactsManager::get_dialog_participant(DialogId dialog_id,
|
|||||||
DialogParticipants ContactsManager::search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
|
DialogParticipants ContactsManager::search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
|
||||||
const string &query, int32 limit,
|
const string &query, int32 limit,
|
||||||
DialogParticipantsFilter filter) const {
|
DialogParticipantsFilter filter) const {
|
||||||
vector<UserId> user_ids;
|
vector<DialogId> dialog_ids;
|
||||||
switch (filter.type) {
|
switch (filter.type) {
|
||||||
case DialogParticipantsFilter::Type::Contacts:
|
case DialogParticipantsFilter::Type::Contacts:
|
||||||
if (peer_user_id.is_valid() && is_user_contact(peer_user_id)) {
|
if (peer_user_id.is_valid() && is_user_contact(peer_user_id)) {
|
||||||
user_ids.push_back(peer_user_id);
|
dialog_ids.push_back(DialogId(peer_user_id));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DialogParticipantsFilter::Type::Administrators:
|
case DialogParticipantsFilter::Type::Administrators:
|
||||||
break;
|
break;
|
||||||
case DialogParticipantsFilter::Type::Members:
|
case DialogParticipantsFilter::Type::Members:
|
||||||
case DialogParticipantsFilter::Type::Mention:
|
case DialogParticipantsFilter::Type::Mention:
|
||||||
user_ids.push_back(my_user_id);
|
dialog_ids.push_back(DialogId(my_user_id));
|
||||||
if (peer_user_id.is_valid() && peer_user_id != my_user_id) {
|
if (peer_user_id.is_valid() && peer_user_id != my_user_id) {
|
||||||
user_ids.push_back(peer_user_id);
|
dialog_ids.push_back(DialogId(peer_user_id));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DialogParticipantsFilter::Type::Restricted:
|
case DialogParticipantsFilter::Type::Restricted:
|
||||||
@ -14636,20 +14645,20 @@ DialogParticipants ContactsManager::search_private_chat_participants(UserId my_u
|
|||||||
break;
|
break;
|
||||||
case DialogParticipantsFilter::Type::Bots:
|
case DialogParticipantsFilter::Type::Bots:
|
||||||
if (td_->auth_manager_->is_bot()) {
|
if (td_->auth_manager_->is_bot()) {
|
||||||
user_ids.push_back(my_user_id);
|
dialog_ids.push_back(DialogId(my_user_id));
|
||||||
}
|
}
|
||||||
if (peer_user_id.is_valid() && is_user_bot(peer_user_id) && peer_user_id != my_user_id) {
|
if (peer_user_id.is_valid() && is_user_bot(peer_user_id) && peer_user_id != my_user_id) {
|
||||||
user_ids.push_back(peer_user_id);
|
dialog_ids.push_back(DialogId(peer_user_id));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = search_among_users(user_ids, query, limit);
|
auto result = search_among_dialogs(dialog_ids, query, limit);
|
||||||
return {result.first, transform(result.second, [&](UserId user_id) {
|
return {result.first, transform(result.second, [&](DialogId dialog_id) {
|
||||||
return DialogParticipant(DialogId(user_id),
|
return DialogParticipant(
|
||||||
user_id == my_user_id && peer_user_id.is_valid() ? peer_user_id : my_user_id, 0,
|
dialog_id, dialog_id == DialogId(my_user_id) && peer_user_id.is_valid() ? peer_user_id : my_user_id, 0,
|
||||||
DialogParticipantStatus::Member());
|
DialogParticipantStatus::Member());
|
||||||
})};
|
})};
|
||||||
}
|
}
|
||||||
@ -14785,12 +14794,10 @@ void ContactsManager::do_search_chat_participants(ChatId chat_id, const string &
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto is_dialog_participant_suitable = [this, filter](const DialogParticipant &participant) {
|
auto is_dialog_participant_suitable = [this, filter](const DialogParticipant &participant) {
|
||||||
if (participant.dialog_id.get_type() != DialogType::User) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
switch (filter.type) {
|
switch (filter.type) {
|
||||||
case DialogParticipantsFilter::Type::Contacts:
|
case DialogParticipantsFilter::Type::Contacts:
|
||||||
return is_user_contact(participant.dialog_id.get_user_id());
|
return participant.dialog_id.get_type() == DialogType::User &&
|
||||||
|
is_user_contact(participant.dialog_id.get_user_id());
|
||||||
case DialogParticipantsFilter::Type::Administrators:
|
case DialogParticipantsFilter::Type::Administrators:
|
||||||
return participant.status.is_administrator();
|
return participant.status.is_administrator();
|
||||||
case DialogParticipantsFilter::Type::Members:
|
case DialogParticipantsFilter::Type::Members:
|
||||||
@ -14802,24 +14809,24 @@ void ContactsManager::do_search_chat_participants(ChatId chat_id, const string &
|
|||||||
case DialogParticipantsFilter::Type::Mention:
|
case DialogParticipantsFilter::Type::Mention:
|
||||||
return true;
|
return true;
|
||||||
case DialogParticipantsFilter::Type::Bots:
|
case DialogParticipantsFilter::Type::Bots:
|
||||||
return is_user_bot(participant.dialog_id.get_user_id());
|
return participant.dialog_id.get_type() == DialogType::User && is_user_bot(participant.dialog_id.get_user_id());
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
vector<UserId> user_ids;
|
vector<DialogId> dialog_ids;
|
||||||
for (const auto &participant : chat_full->participants) {
|
for (const auto &participant : chat_full->participants) {
|
||||||
if (is_dialog_participant_suitable(participant)) {
|
if (is_dialog_participant_suitable(participant)) {
|
||||||
user_ids.push_back(participant.dialog_id.get_user_id());
|
dialog_ids.push_back(participant.dialog_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 total_count;
|
int32 total_count;
|
||||||
std::tie(total_count, user_ids) = search_among_users(user_ids, query, limit);
|
std::tie(total_count, dialog_ids) = search_among_dialogs(dialog_ids, query, limit);
|
||||||
promise.set_value(DialogParticipants{total_count, transform(user_ids, [chat_full](UserId user_id) {
|
promise.set_value(DialogParticipants{total_count, transform(dialog_ids, [chat_full](DialogId dialog_id) {
|
||||||
return *ContactsManager::get_chat_full_participant(chat_full, user_id);
|
return *ContactsManager::get_chat_full_participant(chat_full, dialog_id);
|
||||||
})});
|
})});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1416,9 +1416,9 @@ class ContactsManager : public Actor {
|
|||||||
|
|
||||||
const DialogParticipant *get_chat_participant(ChatId chat_id, UserId user_id) const;
|
const DialogParticipant *get_chat_participant(ChatId chat_id, UserId user_id) const;
|
||||||
|
|
||||||
static const DialogParticipant *get_chat_full_participant(const ChatFull *chat_full, UserId user_id);
|
static const DialogParticipant *get_chat_full_participant(const ChatFull *chat_full, DialogId dialog_id);
|
||||||
|
|
||||||
std::pair<int32, vector<UserId>> search_among_users(const vector<UserId> &user_ids, const string &query,
|
std::pair<int32, vector<DialogId>> search_among_dialogs(const vector<DialogId> &dialog_ids, const string &query,
|
||||||
int32 limit) const;
|
int32 limit) const;
|
||||||
|
|
||||||
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
|
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
|
||||||
|
@ -495,6 +495,8 @@ class MessagesManager : public Actor {
|
|||||||
|
|
||||||
tl_object_ptr<td_api::chatEvents> get_chat_events_object(int64 random_id);
|
tl_object_ptr<td_api::chatEvents> get_chat_events_object(int64 random_id);
|
||||||
|
|
||||||
|
string get_dialog_title(DialogId dialog_id) const;
|
||||||
|
|
||||||
bool have_dialog(DialogId dialog_id) const;
|
bool have_dialog(DialogId dialog_id) const;
|
||||||
bool have_dialog_force(DialogId dialog_id, const char *source = "have_dialog_force");
|
bool have_dialog_force(DialogId dialog_id, const char *source = "have_dialog_force");
|
||||||
|
|
||||||
@ -2693,8 +2695,6 @@ class MessagesManager : public Actor {
|
|||||||
|
|
||||||
const DialogPhoto *get_dialog_photo(DialogId dialog_id) const;
|
const DialogPhoto *get_dialog_photo(DialogId dialog_id) const;
|
||||||
|
|
||||||
string get_dialog_title(DialogId dialog_id) const;
|
|
||||||
|
|
||||||
string get_dialog_username(DialogId dialog_id) const;
|
string get_dialog_username(DialogId dialog_id) const;
|
||||||
|
|
||||||
RestrictedRights get_dialog_permissions(DialogId dialog_id) const;
|
RestrictedRights get_dialog_permissions(DialogId dialog_id) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user