mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-19 14:19:06 -04:00
docs: updated documentation
and removed code from ffi that will be changed soon
This commit is contained in:
@@ -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(), });
|
||||
// }
|
||||
// _ => {}
|
||||
// }
|
||||
// }
|
||||
}))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String>, 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<RoomDescription>, impl Stream<Item = Vec<VectorDiff<RoomDescription>>>) {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user