Add searchMessages.only_in_channels.

This commit is contained in:
levlam 2024-04-22 16:38:30 +03:00
parent 6194fb4aa1
commit b359b32080
5 changed files with 27 additions and 18 deletions

View File

@ -7802,13 +7802,14 @@ searchChatMessages chat_id:int53 query:string sender_id:MessageSender from_messa
//@description Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)). //@description Searches for messages in all chats except secret chats. Returns the results in reverse chronological order (i.e., in order of decreasing (date, chat_id, message_id)).
//-For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit //-For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
//@chat_list Chat list in which to search messages; pass null to search in all chats regardless of their chat list. Only Main and Archive chat lists are supported //@chat_list Chat list in which to search messages; pass null to search in all chats regardless of their chat list. Only Main and Archive chat lists are supported
//@only_in_channels Pass true to search only for messages in channels
//@query Query to search for //@query Query to search for
//@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results //@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results
//@limit The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit //@limit The maximum number of messages to be returned; up to 100. For optimal performance, the number of returned messages is chosen by TDLib and can be smaller than the specified limit
//@filter Additional filter for messages to search; pass null to search for all messages. Filters searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, searchMessagesFilterFailedToSend, and searchMessagesFilterPinned are unsupported in this function //@filter Additional filter for messages to search; pass null to search for all messages. Filters searchMessagesFilterMention, searchMessagesFilterUnreadMention, searchMessagesFilterUnreadReaction, searchMessagesFilterFailedToSend, and searchMessagesFilterPinned are unsupported in this function
//@min_date If not 0, the minimum date of the messages to return //@min_date If not 0, the minimum date of the messages to return
//@max_date If not 0, the maximum date of the messages to return //@max_date If not 0, the maximum date of the messages to return
searchMessages chat_list:ChatList query:string offset:string limit:int32 filter:SearchMessagesFilter min_date:int32 max_date:int32 = FoundMessages; searchMessages chat_list:ChatList only_in_channels:Bool query:string offset:string limit:int32 filter:SearchMessagesFilter min_date:int32 max_date:int32 = FoundMessages;
//@description Searches for messages in secret chats. Returns the results in reverse chronological order. For optimal performance, the number of returned messages is chosen by TDLib //@description Searches for messages in secret chats. Returns the results in reverse chronological order. For optimal performance, the number of returned messages is chosen by TDLib
//@chat_id Identifier of the chat in which to search. Specify 0 to search in all secret chats //@chat_id Identifier of the chat in which to search. Specify 0 to search in all secret chats

View File

@ -2067,7 +2067,7 @@ class SearchMessagesGlobalQuery final : public Td::ResultHandler {
explicit SearchMessagesGlobalQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit SearchMessagesGlobalQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send(FolderId folder_id, bool ignore_folder_id, const string &query, int32 offset_date, void send(FolderId folder_id, bool ignore_folder_id, bool broadcasts_only, const string &query, int32 offset_date,
DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, MessageSearchFilter filter, DialogId offset_dialog_id, MessageId offset_message_id, int32 limit, MessageSearchFilter filter,
int32 min_date, int32 max_date, int64 random_id) { int32 min_date, int32 max_date, int64 random_id) {
query_ = query; query_ = query;
@ -2087,6 +2087,9 @@ class SearchMessagesGlobalQuery final : public Td::ResultHandler {
if (!ignore_folder_id) { if (!ignore_folder_id) {
flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK; flags |= telegram_api::messages_searchGlobal::FOLDER_ID_MASK;
} }
if (broadcasts_only) {
flags |= telegram_api::messages_searchGlobal::BROADCASTS_ONLY_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_searchGlobal( send_query(G()->net_query_creator().create(telegram_api::messages_searchGlobal(
flags, false /*ignored*/, folder_id.get(), query, get_input_messages_filter(filter), min_date_, max_date_, flags, false /*ignored*/, folder_id.get(), query, get_input_messages_filter(filter), min_date_, max_date_,
offset_date_, std::move(input_peer), offset_message_id.get_server_message_id().get(), limit))); offset_date_, std::move(input_peer), offset_message_id.get_server_message_id().get(), limit)));
@ -21070,7 +21073,8 @@ void MessagesManager::on_message_db_calls_result(Result<MessageDbCallsResult> re
} }
MessagesManager::FoundMessages MessagesManager::search_messages(FolderId folder_id, bool ignore_folder_id, MessagesManager::FoundMessages MessagesManager::search_messages(FolderId folder_id, bool ignore_folder_id,
const string &query, const string &offset, int32 limit, bool broadcasts_only, const string &query,
const string &offset, int32 limit,
MessageSearchFilter filter, int32 min_date, MessageSearchFilter filter, int32 min_date,
int32 max_date, int64 &random_id, int32 max_date, int64 &random_id,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
@ -21147,8 +21151,8 @@ MessagesManager::FoundMessages MessagesManager::search_messages(FolderId folder_
<< offset << " and limit " << limit; << offset << " and limit " << limit;
td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise)) td_->create_handler<SearchMessagesGlobalQuery>(std::move(promise))
->send(folder_id, ignore_folder_id, query, offset_date, offset_dialog_id, offset_message_id, limit, filter, ->send(folder_id, ignore_folder_id, broadcasts_only, query, offset_date, offset_dialog_id, offset_message_id,
min_date, max_date, random_id); limit, filter, min_date, max_date, random_id);
return {}; return {};
} }

View File

@ -734,9 +734,9 @@ class MessagesManager final : public Actor {
FoundMessages offline_search_messages(DialogId dialog_id, const string &query, string offset, int32 limit, FoundMessages offline_search_messages(DialogId dialog_id, const string &query, string offset, int32 limit,
MessageSearchFilter filter, int64 &random_id, Promise<Unit> &&promise); MessageSearchFilter filter, int64 &random_id, Promise<Unit> &&promise);
FoundMessages search_messages(FolderId folder_id, bool ignore_folder_id, const string &query, const string &offset, FoundMessages search_messages(FolderId folder_id, bool ignore_folder_id, bool broadcasts_only, const string &query,
int32 limit, MessageSearchFilter filter, int32 min_date, int32 max_date, const string &offset, int32 limit, MessageSearchFilter filter, int32 min_date,
int64 &random_id, Promise<Unit> &&promise); int32 max_date, int64 &random_id, Promise<Unit> &&promise);
FoundMessages search_call_messages(const string &offset, int32 limit, bool only_missed, int64 &random_id, bool use_db, FoundMessages search_call_messages(const string &offset, int32 limit, bool only_missed, int64 &random_id, bool use_db,
Promise<Unit> &&promise); Promise<Unit> &&promise);

View File

@ -1497,6 +1497,7 @@ class SearchSecretMessagesRequest final : public RequestActor<> {
class SearchMessagesRequest final : public RequestActor<> { class SearchMessagesRequest final : public RequestActor<> {
FolderId folder_id_; FolderId folder_id_;
bool ignore_folder_id_; bool ignore_folder_id_;
bool broadcasts_only_;
string query_; string query_;
string offset_; string offset_;
int32 limit_; int32 limit_;
@ -1508,8 +1509,9 @@ class SearchMessagesRequest final : public RequestActor<> {
MessagesManager::FoundMessages messages_; MessagesManager::FoundMessages messages_;
void do_run(Promise<Unit> &&promise) final { void do_run(Promise<Unit> &&promise) final {
messages_ = td_->messages_manager_->search_messages(folder_id_, ignore_folder_id_, query_, offset_, limit_, filter_, messages_ =
min_date_, max_date_, random_id_, std::move(promise)); td_->messages_manager_->search_messages(folder_id_, ignore_folder_id_, broadcasts_only_, query_, offset_,
limit_, filter_, min_date_, max_date_, random_id_, std::move(promise));
} }
void do_send_result() final { void do_send_result() final {
@ -1525,12 +1527,13 @@ class SearchMessagesRequest final : public RequestActor<> {
} }
public: public:
SearchMessagesRequest(ActorShared<Td> td, uint64 request_id, FolderId folder_id, bool ignore_folder_id, string query, SearchMessagesRequest(ActorShared<Td> td, uint64 request_id, FolderId folder_id, bool ignore_folder_id,
string offset, int32 limit, tl_object_ptr<td_api::SearchMessagesFilter> &&filter, bool broadcasts_only, string query, string offset, int32 limit,
int32 min_date, int32 max_date) tl_object_ptr<td_api::SearchMessagesFilter> &&filter, int32 min_date, int32 max_date)
: RequestActor(std::move(td), request_id) : RequestActor(std::move(td), request_id)
, folder_id_(folder_id) , folder_id_(folder_id)
, ignore_folder_id_(ignore_folder_id) , ignore_folder_id_(ignore_folder_id)
, broadcasts_only_(broadcasts_only)
, query_(std::move(query)) , query_(std::move(query))
, offset_(std::move(offset)) , offset_(std::move(offset))
, limit_(limit) , limit_(limit)
@ -5407,8 +5410,8 @@ void Td::on_request(uint64 id, td_api::searchMessages &request) {
return send_error_raw(id, 400, "Wrong chat list specified"); return send_error_raw(id, 400, "Wrong chat list specified");
} }
CREATE_REQUEST(SearchMessagesRequest, dialog_list_id.get_folder_id(), request.chat_list_ == nullptr, CREATE_REQUEST(SearchMessagesRequest, dialog_list_id.get_folder_id(), request.chat_list_ == nullptr,
std::move(request.query_), std::move(request.offset_), request.limit_, std::move(request.filter_), request.only_in_channels_, std::move(request.query_), std::move(request.offset_), request.limit_,
request.min_date_, request.max_date_); std::move(request.filter_), request.min_date_, request.max_date_);
} }
void Td::on_request(uint64 id, td_api::searchSavedMessages &request) { void Td::on_request(uint64 id, td_api::searchSavedMessages &request) {

View File

@ -2943,7 +2943,7 @@ class CliClient final : public Actor {
search_chat_id_ = as_chat_id(args); search_chat_id_ = as_chat_id(args);
send_request(td_api::make_object<td_api::searchChatMessages>( send_request(td_api::make_object<td_api::searchChatMessages>(
search_chat_id_, "", nullptr, 0, 0, 100, as_search_messages_filter("pvi"), 0, get_saved_messages_topic_id())); search_chat_id_, "", nullptr, 0, 0, 100, as_search_messages_filter("pvi"), 0, get_saved_messages_topic_id()));
} else if (op == "Search" || op == "SearchA" || op == "SearchM") { } else if (op == "Search" || op == "SearchA" || op == "SearchM" || op == "SearchC") {
string query; string query;
string limit; string limit;
string filter; string filter;
@ -2956,8 +2956,9 @@ class CliClient final : public Actor {
if (op == "SearchM") { if (op == "SearchM") {
chat_list = td_api::make_object<td_api::chatListMain>(); chat_list = td_api::make_object<td_api::chatListMain>();
} }
send_request(td_api::make_object<td_api::searchMessages>(std::move(chat_list), query, offset, as_limit(limit), send_request(td_api::make_object<td_api::searchMessages>(std::move(chat_list), op == "SearchC", query, offset,
as_search_messages_filter(filter), 1, 2147483647)); as_limit(limit), as_search_messages_filter(filter), 1,
2147483647));
} else if (op == "SCM") { } else if (op == "SCM") {
ChatId chat_id; ChatId chat_id;
SearchQuery query; SearchQuery query;