From 3e35f163b7971db79e9b38f573c3902a6a2e9ed2 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Wed, 28 Feb 2024 19:17:58 +0100 Subject: [PATCH] docs: updated documentation and removed code from ffi that will be changed soon --- .../src/room_directory_search.rs | 35 ++++++++++--------- .../matrix-sdk/src/room_directory_search.rs | 15 ++++++++ 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room_directory_search.rs b/bindings/matrix-sdk-ffi/src/room_directory_search.rs index 80e7d30ad..3035165dd 100644 --- a/bindings/matrix-sdk-ffi/src/room_directory_search.rs +++ b/bindings/matrix-sdk-ffi/src/room_directory_search.rs @@ -16,8 +16,8 @@ use std::{fmt::Debug, sync::Arc}; use eyeball_im::VectorDiff; -use futures_util::{pin_mut, StreamExt}; -use matrix_sdk::{room_directory_search::RoomDirectorySearch as SdkRoomDirectorySearch, Client}; +use futures_util::pin_mut; +use matrix_sdk::room_directory_search::RoomDirectorySearch as SdkRoomDirectorySearch; use tokio::sync::RwLock; use super::RUNTIME; @@ -108,21 +108,24 @@ impl RoomDirectorySearch { let entries_stream = self.inner.read().await.results(); RoomDirectorySearchEntriesResult { entries_stream: Arc::new(TaskHandle::new(RUNTIME.spawn(async move { - pin_mut!(entries_stream); + // TODO: This needs to get improved with sensei Ivan + // pin_mut!(entries_stream); - while let Some(diff) = entries_stream.next().await { - match diff { - VectorDiff::Clear => { - listener.on_update(RoomDirectorySearchEntryUpdate::Clear); - } - VectorDiff::Append { values } => { - listener.on_update(RoomDirectorySearchEntryUpdate::Append { - values: values.into_iter().map(|value| value.into()).collect(), - }); - } - _ => {} - } - } + // while let Some(diff) = entries_stream.next().await { + // match diff { + // VectorDiff::Clear => { + // + // listener.on_update(RoomDirectorySearchEntryUpdate::Clear); + // } + // VectorDiff::Append { values } => { + // + // listener.on_update(RoomDirectorySearchEntryUpdate::Append { + // values: values.into_iter().map(|value| + // value.into()).collect(), }); + // } + // _ => {} + // } + // } }))), } } diff --git a/crates/matrix-sdk/src/room_directory_search.rs b/crates/matrix-sdk/src/room_directory_search.rs index 9014d531f..3c7781fe0 100644 --- a/crates/matrix-sdk/src/room_directory_search.rs +++ b/crates/matrix-sdk/src/room_directory_search.rs @@ -72,6 +72,14 @@ impl RoomDirectorySearch { } } + /// Starts a filtered search for the server + /// If the `filter` is not provided it will search for all the rooms + /// You can specify a `batch_size`` to control the number of rooms to fetch + /// per request + /// + /// This method will clear the current search results and start a new one + /// Should never be used concurrently with another `next_page` or a + /// `search`. pub async fn search(&mut self, filter: Option, batch_size: u32) -> Result<()> { self.filter = filter; self.batch_size = batch_size; @@ -81,6 +89,9 @@ impl RoomDirectorySearch { self.next_page().await } + /// Asks the server for the next page of the current search + /// Should never be used concurrently with another `next_page` or a + /// `search`. pub async fn next_page(&mut self) -> Result<()> { if self.is_at_last_page { return Ok(()); @@ -101,12 +112,15 @@ impl RoomDirectorySearch { Ok(()) } + /// Get the initial value of the current stored room descriptions in the + /// search, and a stream of updates for them. pub fn results( &self, ) -> (Vector, impl Stream>>) { self.results.subscribe().into_values_and_batched_stream() } + /// Get the number of pages that have been loaded so far pub fn loaded_pages(&self) -> usize { if self.batch_size == 0 { return 0; @@ -114,6 +128,7 @@ impl RoomDirectorySearch { self.results.len() / self.batch_size as usize } + /// Get whether the search is at the last page pub fn is_at_last_page(&self) -> bool { self.is_at_last_page }