Add td_api::searchRecentlyFoundChat.

This commit is contained in:
levlam 2023-05-16 21:41:19 +03:00
parent 96da28d4fb
commit 24d012bc73
6 changed files with 62 additions and 3 deletions

View File

@ -5959,7 +5959,7 @@ getSupergroupFullInfo supergroup_id:int53 = SupergroupFullInfo;
//@description Returns information about a secret chat by its identifier. This is an offline request @secret_chat_id Secret chat identifier
getSecretChat secret_chat_id:int32 = SecretChat;
//@description Returns information about a chat by its identifier, this is an offline request if the current user is not a bot @chat_id Chat identifier
//@description Returns information about a chat by its identifier; this is an offline request if the current user is not a bot @chat_id Chat identifier
getChat chat_id:int53 = Chat;
//@description Returns information about a message @chat_id Identifier of the chat the message belongs to @message_id Identifier of the message to get
@ -6018,7 +6018,7 @@ searchPublicChat username:string = Chat;
//@query Query to search for
searchPublicChats query:string = Chats;
//@description Searches for the specified query in the title and username of already known chats, this is an offline request. Returns chats in the order seen in the main chat list
//@description Searches for the specified query in the title and username of already known chats; this is an offline request. Returns chats in the order seen in the main chat list
//@query Query to search for. If the query is empty, returns up to 50 recently found chats
//@limit The maximum number of chats to be returned
searchChats query:string limit:int32 = Chats;
@ -6037,6 +6037,11 @@ getTopChats category:TopChatCategory limit:int32 = Chats;
//@description Removes a chat from the list of frequently used chats. Supported only if the chat info database is enabled @category Category of frequently used chats @chat_id Chat identifier
removeTopChat category:TopChatCategory chat_id:int53 = Ok;
//@description Searches for the specified query in the title and username of up to 50 recently found chats; this is an offline request
//@query Query to search for
//@limit The maximum number of chats to be returned
searchRecentlyFoundChats query:string limit:int32 = Chats;
//@description Adds a chat to the list of recently found chats. The chat is added to the beginning of the list. If the chat is already in the list, it will be removed from the list first @chat_id Identifier of the chat to add
addRecentlyFoundChat chat_id:int53 = Ok;
@ -6046,7 +6051,7 @@ removeRecentlyFoundChat chat_id:int53 = Ok;
//@description Clears the list of recently found chats
clearRecentlyFoundChats = Ok;
//@description Returns recently opened chats, this is an offline request. Returns chats in the order of last opening @limit The maximum number of chats to be returned
//@description Returns recently opened chats; this is an offline request. Returns chats in the order of last opening @limit The maximum number of chats to be returned
getRecentlyOpenedChats limit:int32 = Chats;
//@description Checks whether a username can be set for a chat @chat_id Chat identifier; must be identifier of a supergroup chat, or a channel chat, or a private chat with self, or zero if the chat is being created @username Username to be checked

View File

@ -17321,6 +17321,25 @@ std::pair<int32, vector<DialogId>> MessagesManager::search_dialogs(const string
return {narrow_cast<int32>(result.first), std::move(dialog_ids)};
}
std::pair<int32, vector<DialogId>> MessagesManager::search_recently_found_dialogs(const string &query, int32 limit,
Promise<Unit> &&promise) {
auto result = recently_found_dialogs_.get_dialogs(query.empty() ? limit : 50, std::move(promise));
if (result.first == 0 || query.empty()) {
return result;
}
Hints hints;
int rating = 1;
for (auto dialog_id : result.second) {
hints.add(dialog_id.get(), td_->contacts_manager_->get_dialog_search_text(dialog_id));
hints.set_rating(dialog_id.get(), ++rating);
}
auto hints_result = hints.search(query, limit, false);
return {narrow_cast<int32>(hints_result.first),
transform(hints_result.second, [](int64 key) { return DialogId(key); })};
}
std::pair<int32, vector<DialogId>> MessagesManager::get_recently_opened_dialogs(int32 limit, Promise<Unit> &&promise) {
CHECK(!td_->auth_manager_->is_bot());
return recently_opened_dialogs_.get_dialogs(limit, std::move(promise));

View File

@ -420,6 +420,9 @@ class MessagesManager final : public Actor {
void clear_recently_found_dialogs();
std::pair<int32, vector<DialogId>> search_recently_found_dialogs(const string &query, int32 limit,
Promise<Unit> &&promise);
std::pair<int32, vector<DialogId>> get_recently_opened_dialogs(int32 limit, Promise<Unit> &&promise);
DialogId resolve_dialog_username(const string &username) const;

View File

@ -901,6 +901,26 @@ class GetInactiveSupergroupChatsRequest final : public RequestActor<> {
}
};
class SearchRecentlyFoundChatsRequest final : public RequestActor<> {
string query_;
int32 limit_;
std::pair<int32, vector<DialogId>> dialog_ids_;
void do_run(Promise<Unit> &&promise) final {
dialog_ids_ = td_->messages_manager_->search_recently_found_dialogs(query_, limit_, std::move(promise));
}
void do_send_result() final {
send_result(td_->messages_manager_->get_chats_object(dialog_ids_, "SearchRecentlyFoundChatsRequest"));
}
public:
SearchRecentlyFoundChatsRequest(ActorShared<Td> td, uint64 request_id, string query, int32 limit)
: RequestActor(std::move(td), request_id), query_(std::move(query)), limit_(limit) {
}
};
class GetRecentlyOpenedChatsRequest final : public RequestActor<> {
int32 limit_;
@ -5045,6 +5065,12 @@ void Td::on_request(uint64 id, const td_api::getInactiveSupergroupChats &request
CREATE_NO_ARGS_REQUEST(GetInactiveSupergroupChatsRequest);
}
void Td::on_request(uint64 id, td_api::searchRecentlyFoundChats &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.query_);
CREATE_REQUEST(SearchRecentlyFoundChatsRequest, request.query_, request.limit_);
}
void Td::on_request(uint64 id, const td_api::addRecentlyFoundChat &request) {
CHECK_IS_USER();
answer_ok_query(id, messages_manager_->add_recently_found_dialog(DialogId(request.chat_id_)));

View File

@ -634,6 +634,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::searchChatsNearby &request);
void on_request(uint64 id, td_api::searchRecentlyFoundChats &request);
void on_request(uint64 id, const td_api::addRecentlyFoundChat &request);
void on_request(uint64 id, const td_api::removeRecentlyFoundChat &request);

View File

@ -5120,6 +5120,10 @@ class CliClient final : public Actor {
SearchQuery query;
get_args(args, query);
send_request(td_api::make_object<td_api::searchContacts>(query.query, query.limit));
} else if (op == "srfc") {
SearchQuery query;
get_args(args, query);
send_request(td_api::make_object<td_api::searchRecentlyFoundChats>(query.query, query.limit));
} else if (op == "arfc") {
ChatId chat_id;
get_args(args, chat_id);