Add ContactsManager::get_dialog_search_text.

This commit is contained in:
levlam 2022-10-11 20:35:35 +03:00
parent 62403aac3c
commit 9b16702674
4 changed files with 55 additions and 32 deletions

View File

@ -5071,6 +5071,49 @@ string ContactsManager::get_dialog_about(DialogId dialog_id) {
return string();
}
string ContactsManager::get_dialog_search_text(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
return get_user_search_text(dialog_id.get_user_id());
case DialogType::Chat:
return get_chat_title(dialog_id.get_chat_id());
case DialogType::Channel:
return get_channel_search_text(dialog_id.get_channel_id());
case DialogType::SecretChat:
return get_user_search_text(get_secret_chat_user_id(dialog_id.get_secret_chat_id()));
case DialogType::None:
default:
UNREACHABLE();
}
return string();
}
string ContactsManager::get_user_search_text(UserId user_id) const {
auto u = get_user(user_id);
if (u == nullptr) {
return string();
}
return get_user_search_text(u);
}
string ContactsManager::get_user_search_text(const User *u) {
CHECK(u != nullptr);
return PSTRING() << u->first_name << ' ' << u->last_name << ' ' << u->username;
}
string ContactsManager::get_channel_search_text(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
return get_channel_title(channel_id);
}
return get_channel_search_text(c);
}
string ContactsManager::get_channel_search_text(const Channel *c) {
CHECK(c != nullptr);
return PSTRING() << c->title << ' ' << c->username;
}
int32 ContactsManager::get_secret_chat_date(SecretChatId secret_chat_id) const {
auto c = get_secret_chat(secret_chat_id);
if (c == nullptr) {
@ -5099,14 +5142,6 @@ string ContactsManager::get_user_username(UserId user_id) const {
return u->username;
}
string ContactsManager::get_secret_chat_username(SecretChatId secret_chat_id) const {
auto c = get_secret_chat(secret_chat_id);
if (c == nullptr) {
return string();
}
return get_user_username(c->user_id);
}
string ContactsManager::get_channel_username(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
@ -14515,7 +14550,7 @@ void ContactsManager::update_contacts_hints(const User *u, UserId user_id, bool
int64 key = user_id.get();
string old_value = contacts_hints_.key_to_string(key);
string new_value = is_contact ? (PSTRING() << u->first_name << ' ' << u->last_name << ' ' << u->username) : string();
string new_value = is_contact ? get_user_search_text(u) : string();
if (new_value != old_value) {
if (is_contact) {
@ -15616,7 +15651,7 @@ std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const v
if (query.empty()) {
hints.add(dialog_id.get(), Slice(" "));
} else {
hints.add(dialog_id.get(), PSLICE() << u->first_name << ' ' << u->last_name << ' ' << u->username);
hints.add(dialog_id.get(), get_user_search_text(u));
}
rating = -get_user_was_online(u, user_id);
} else {
@ -15626,7 +15661,7 @@ std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const v
if (query.empty()) {
hints.add(dialog_id.get(), Slice(" "));
} else {
hints.add(dialog_id.get(), td_->messages_manager_->get_dialog_title(dialog_id));
hints.add(dialog_id.get(), get_dialog_search_text(dialog_id));
}
}
hints.set_rating(dialog_id.get(), rating);

View File

@ -127,11 +127,12 @@ class ContactsManager final : public Actor {
string get_dialog_about(DialogId dialog_id);
string get_dialog_search_text(DialogId dialog_id) const;
void for_each_secret_chat_with_user(UserId user_id, const std::function<void(SecretChatId)> &f);
string get_user_username(UserId user_id) const;
string get_channel_username(ChannelId channel_id) const;
string get_secret_chat_username(SecretChatId secret_chat_id) const;
int32 get_secret_chat_date(SecretChatId secret_chat_id) const;
int32 get_secret_chat_ttl(SecretChatId secret_chat_id) const;
@ -1237,6 +1238,9 @@ class ContactsManager final : public Actor {
SecretChat *add_secret_chat(SecretChatId secret_chat_id);
string get_user_search_text(UserId user_id) const;
static string get_user_search_text(const User *u);
static DialogParticipantStatus get_chat_status(const Chat *c);
DialogParticipantStatus get_chat_permissions(const Chat *c) const;
@ -1249,6 +1253,9 @@ class ContactsManager final : public Actor {
static bool get_channel_join_to_send(const Channel *c);
static bool get_channel_join_request(const Channel *c);
string get_channel_search_text(ChannelId channel_id) const;
static string get_channel_search_text(const Channel *c);
void set_my_id(UserId my_id);
static bool is_valid_username(const string &username);

View File

@ -33561,23 +33561,6 @@ string MessagesManager::get_dialog_title(DialogId dialog_id) const {
}
}
string MessagesManager::get_dialog_username(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
return td_->contacts_manager_->get_user_username(dialog_id.get_user_id());
case DialogType::Chat:
return string();
case DialogType::Channel:
return td_->contacts_manager_->get_channel_username(dialog_id.get_channel_id());
case DialogType::SecretChat:
return td_->contacts_manager_->get_secret_chat_username(dialog_id.get_secret_chat_id());
case DialogType::None:
default:
UNREACHABLE();
return string();
}
}
RestrictedRights MessagesManager::get_dialog_default_permissions(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
@ -37535,7 +37518,7 @@ bool MessagesManager::add_dialog_last_database_message(Dialog *d, unique_ptr<Mes
void MessagesManager::update_dialogs_hints(const Dialog *d) {
if (!td_->auth_manager_->is_bot() && d->order != DEFAULT_ORDER) {
dialogs_hints_.add(-d->dialog_id.get(), get_dialog_title(d->dialog_id) + ' ' + get_dialog_username(d->dialog_id));
dialogs_hints_.add(-d->dialog_id.get(), td_->contacts_manager_->get_dialog_search_text(d->dialog_id));
}
}

View File

@ -3073,8 +3073,6 @@ class MessagesManager final : public Actor {
const DialogPhoto *get_dialog_photo(DialogId dialog_id) const;
string get_dialog_username(DialogId dialog_id) const;
RestrictedRights get_dialog_default_permissions(DialogId dialog_id) const;
bool get_dialog_has_protected_content(DialogId dialog_id) const;