diff --git a/crates/matrix/src/admin/resources/mod.rs b/crates/matrix/src/admin/resources/mod.rs index cb201a4..c29990d 100644 --- a/crates/matrix/src/admin/resources/mod.rs +++ b/crates/matrix/src/admin/resources/mod.rs @@ -1,4 +1,3 @@ pub mod room; pub mod token; pub mod user; -pub mod user_id; diff --git a/crates/matrix/src/admin/resources/room.rs b/crates/matrix/src/admin/resources/room.rs index 9936111..9b153c5 100644 --- a/crates/matrix/src/admin/resources/room.rs +++ b/crates/matrix/src/admin/resources/room.rs @@ -30,8 +30,9 @@ pub struct ListRoomQuery { pub search_term: String, } -#[derive(Debug, Serialize)] +#[derive(Debug, Default, Serialize)] pub struct MessagesQuery { + #[serde(skip_serializing_if = "String::is_empty")] pub from: String, #[serde(skip_serializing_if = "String::is_empty")] diff --git a/crates/matrix/src/admin/resources/user_id.rs b/crates/matrix/src/admin/resources/user_id.rs deleted file mode 100644 index b7bc9d1..0000000 --- a/crates/matrix/src/admin/resources/user_id.rs +++ /dev/null @@ -1,38 +0,0 @@ -use std::{borrow::Cow, fmt::Display}; - -use serde::{Deserialize, Serialize}; - -/// A Matrix user ID. -/// -/// # Example -/// -/// ```ignore -/// @user:server.com -/// ``` -/// -/// The `server` value corresponds to the Synapse Server Name and can be -/// found on homeserver.yaml. -/// -/// # Devnotes -/// -/// Perhaps using Ruma's `UserId` would be better? -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] -pub struct UserId(Cow<'static, str>); - -impl UserId { - pub fn new>(name: S, server_name: S) -> Self { - let user_id = format!( - "@{name}:{server_name}", - name = name.as_ref(), - server_name = server_name.as_ref() - ); - - Self(user_id.into()) - } -} - -impl Display for UserId { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} diff --git a/crates/test/src/matrix/room_admin.rs b/crates/test/src/matrix/room_admin.rs index 573d5d1..2c1ef9d 100644 --- a/crates/test/src/matrix/room_admin.rs +++ b/crates/test/src/matrix/room_admin.rs @@ -2,10 +2,11 @@ mod tests { use std::{thread, time::Duration}; - use futures::TryFutureExt; + use futures::{future, TryFutureExt}; use matrix::{ admin::resources::room::{ListRoomQuery, MessagesQuery, RoomService as AdminRoomService}, ruma_common::{RoomId, ServerName}, + ruma_events::{room::name::OriginalRoomNameEvent, AnyTimelineEvent, TimelineEventType}, }; use tokio::sync::OnceCell; @@ -22,15 +23,32 @@ mod tests { admin, } = TEST.get_or_init(util::init).await; - // TODO - thread::sleep(Duration::from_secs(5)); - let resp: Vec<_> = AdminRoomService::get_all(admin, ListRoomQuery::default()) .map_ok(|resp| resp.rooms) .await .unwrap(); - dbg!(samples.iter().map(|s| s.owner()).collect::>()); + while let Some(_) = future::try_join_all(resp.iter().map(|r| { + AdminRoomService::get_room_events(admin, &r.room_id, Default::default()) + .map_ok(|resp| resp.chunk.deserialize().unwrap()) + })) + .await + .map(|ok| { + ok.into_iter().find(|chunk| { + chunk + .iter() + .all(|event| event.event_type() != TimelineEventType::RoomName) + }) + }) + .unwrap() + { + tokio::time::sleep(Duration::from_secs(2)).await; + } + + let resp: Vec<_> = AdminRoomService::get_all(admin, ListRoomQuery::default()) + .map_ok(|resp| resp.rooms) + .await + .unwrap(); assert_eq!( samples