From 37893749514b842b257fe231287dea9caf53f95f Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Fri, 17 Apr 2026 10:45:26 +0200 Subject: [PATCH] refactor(sdk): move search related functions to a message_search module --- crates/matrix-sdk/src/lib.rs | 3 +++ crates/matrix-sdk/src/message_search.rs | 34 +++++++++++++++++++++++++ crates/matrix-sdk/src/room/mod.rs | 20 +-------------- 3 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 crates/matrix-sdk/src/message_search.rs diff --git a/crates/matrix-sdk/src/lib.rs b/crates/matrix-sdk/src/lib.rs index d459ba2d3..950e4ed1c 100644 --- a/crates/matrix-sdk/src/lib.rs +++ b/crates/matrix-sdk/src/lib.rs @@ -63,6 +63,9 @@ pub mod sync; #[cfg(feature = "experimental-widgets")] pub mod widget; +#[cfg(feature = "experimental-search")] +mod message_search;; + pub use account::Account; pub use authentication::{AuthApi, AuthSession, SessionTokens}; pub use client::homeserver_capabilities::HomeserverCapabilities; diff --git a/crates/matrix-sdk/src/message_search.rs b/crates/matrix-sdk/src/message_search.rs new file mode 100644 index 000000000..e43ecd339 --- /dev/null +++ b/crates/matrix-sdk/src/message_search.rs @@ -0,0 +1,34 @@ +// Copyright 2026 The Matrix.org Foundation C.I.C. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use matrix_sdk_search::error::IndexError; +#[cfg(doc)] +use matrix_sdk_search::index::RoomIndex; +use ruma::OwnedEventId; + +use crate::Room; + +impl Room { + /// Search this room's [`RoomIndex`] for query and return at most + /// max_number_of_results results. + pub async fn search( + &self, + query: &str, + max_number_of_results: usize, + pagination_offset: Option, + ) -> Result, IndexError> { + let mut search_index_guard = self.client.search_index().lock().await; + search_index_guard.search(query, max_number_of_results, pagination_offset, self.room_id()) + } +} diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index d4389effc..c8d7c7e80 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -58,14 +58,9 @@ use matrix_sdk_common::{ executor::{JoinHandle, spawn}, timeout::timeout, }; -#[cfg(feature = "experimental-search")] -use matrix_sdk_search::error::IndexError; -#[cfg(feature = "experimental-search")] -#[cfg(doc)] -use matrix_sdk_search::index::RoomIndex; use mime::Mime; use reply::Reply; -#[cfg(any(feature = "experimental-search", feature = "e2e-encryption"))] +#[cfg(feature = "e2e-encryption")] use ruma::events::AnySyncMessageLikeEvent; #[cfg(feature = "experimental-encrypted-state-events")] use ruma::events::AnySyncStateEvent; @@ -4285,19 +4280,6 @@ impl Room { relations } - /// Search this room's [`RoomIndex`] for query and return at most - /// max_number_of_results results. - #[cfg(feature = "experimental-search")] - pub async fn search( - &self, - query: &str, - max_number_of_results: usize, - pagination_offset: Option, - ) -> Result, IndexError> { - let mut search_index_guard = self.client.search_index().lock().await; - search_index_guard.search(query, max_number_of_results, pagination_offset, self.room_id()) - } - /// Subscribe to a given thread in this room. /// /// This will subscribe the user to the thread, so that they will receive