Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
avdb13 committed Feb 17, 2024
1 parent 1c9df89 commit 09fa39b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 63 deletions.
2 changes: 1 addition & 1 deletion crates/core/src/room/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing::instrument;

use matrix::{
client::resources::room::{
CreateRoomBody, RoomService as MatrixRoomService, RoomCreationContent, RoomPreset,
CreateRoomBody, RoomCreationContent, RoomPreset, RoomService as MatrixRoomService,
},
Client as MatrixAdminClient,
};
Expand Down
19 changes: 11 additions & 8 deletions crates/matrix/src/client/resources/events.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use anyhow::Result;
use ruma_common::{serde::Raw, EventId, OwnedEventId, RoomId, OwnedTransactionId};
use ruma_common::{serde::Raw, EventId, OwnedEventId, OwnedTransactionId, RoomId};

use ruma_events::{
relation::RelationType, AnyStateEvent, AnyStateEventContent,
relation::RelationType, AnyMessageLikeEvent, AnyStateEvent, AnyStateEventContent,
AnyTimelineEvent, MessageLikeEventContent, MessageLikeEventType, StateEventContent,
StateEventType, AnyMessageLikeEvent,
StateEventType,
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tracing::instrument;

use crate::{admin::resources::room::Direction, Client, error::MatrixError};
use crate::{admin::resources::room::Direction, error::MatrixError, Client};

pub struct EventsService;

Expand Down Expand Up @@ -117,10 +117,13 @@ impl EventsService {
tmp.set_token(access_token)?;

let resp = tmp
.get_query(format!(
"/_matrix/client/v3/rooms/{room_id}/messages",
room_id = room_id,
), &query)
.get_query(
format!(
"/_matrix/client/v3/rooms/{room_id}/messages",
room_id = room_id,
),
&query,
)
.await?;

Ok(resp.json().await?)
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix/src/client/resources/session.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use ruma_common::{OwnedUserId};
use ruma_common::OwnedUserId;
use serde::{Deserialize, Serialize};
use tracing::instrument;

Expand Down
49 changes: 21 additions & 28 deletions crates/test/src/matrix/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ mod tests {

assert!(joins.iter().all(Result::is_ok));


future::try_join_all(
sample
.guests()
Expand Down Expand Up @@ -64,17 +63,14 @@ mod tests {
.await
.unwrap();

let expected: Vec<_> = sample.guests()
.map(|(user_id, _)| {
format!(
"hello, **my name is {}**",
user_id
)
})
let expected: Vec<_> = sample
.guests()
.map(|(user_id, _)| format!("hello, **my name is {}**", user_id))
.chain(iter::once(format!(
"and I am the admin of the room, {}",
owner_id
))).collect();
)))
.collect();

let filter = RoomEventFilter {
types: vec![MessageLikeEventType::RoomMessage.into()],
Expand All @@ -83,21 +79,21 @@ mod tests {

let filter = serde_json::to_string(&filter).unwrap();

let found =
EventsService::get_messages(
&client,
owner_token,
&sample.room_id,
GetMessagesQuery {
limit: Some(111),
filter: filter.clone(),
..Default::default()
},
)
let found = EventsService::get_messages(
&client,
owner_token,
&sample.room_id,
GetMessagesQuery {
limit: Some(111),
filter: filter.clone(),
..Default::default()
},
)
.await
.unwrap();

let found: Vec<_> = found.chunk
let found: Vec<_> = found
.chunk
.into_iter()
.map(|e| e.deserialize_as::<OriginalRoomMessageEvent>().unwrap())
.map(|e| e.content.body().to_owned())
Expand All @@ -120,9 +116,7 @@ mod tests {

// first join
let joins = join_helper(&client, sample.guests(), &sample.room_id).await;
assert!(joins
.iter()
.all(Result::is_ok));
assert!(joins.iter().all(Result::is_ok));

let root = EventsService::send_message(
&client,
Expand All @@ -132,7 +126,7 @@ mod tests {
RoomMessageEventContent::text_plain(format!(
"I am at the root of the tree, {}",
owner_id
))
)),
)
.map_ok(|resp| resp.event_id)
.await
Expand All @@ -143,9 +137,8 @@ mod tests {
let mut history = Vec::from([vec![root]]);

for i in 1..n {
let (user_id, access_token) = sample.guests()
.nth(i % sample.user_ids.len()-1)
.unwrap();
let (user_id, access_token) =
sample.guests().nth(i % sample.user_ids.len() - 1).unwrap();

let prev = history.last().unwrap();
let traverse = future::try_join_all((0..prev.len() * 2).map(|j| {
Expand Down
15 changes: 3 additions & 12 deletions crates/test/src/matrix/room_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,15 @@ mod tests {
.unwrap();

let (id, _) = user_id.localpart().rsplit_once("-").unwrap();
assert_eq!(Some(format!("{id}-room",)), resp.name);
assert_eq!(
Some(format!(
"{id}-room",
)),
resp.name
);
assert_eq!(
Some(format!(
"#{id}-room-alias:{server_name}",
)),
Some(format!("#{id}-room-alias:{server_name}",)),
resp.canonical_alias,
);

assert_eq!(Some(user_id.to_string()), resp.creator);
assert_eq!(
Some(format!(
"{id}-room-topic",
)),
Some(format!("{id}-room-topic",)),
resp.details.and_then(|d| d.topic),
);

Expand Down
30 changes: 17 additions & 13 deletions crates/test/src/matrix/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ impl Sample {
self.user_ids.iter().zip(self.access_tokens.iter()).skip(1)
}
pub fn owner(&self) -> (&OwnedUserId, &String) {
self.user_ids.iter().zip(self.access_tokens.iter()).clone().next().unwrap()
self.user_ids
.iter()
.zip(self.access_tokens.iter())
.clone()
.next()
.unwrap()
}
}

Expand Down Expand Up @@ -131,7 +136,7 @@ pub async fn init() -> Test {

let users_per_room = 4;

let seed =rand::thread_rng().gen();
let seed = rand::thread_rng().gen();

let env = Environment::new().await;

Expand All @@ -143,7 +148,8 @@ pub async fn init() -> Test {
remove_rooms(&admin).await;

let accounts = future::join_all(
(0..rooms).map(|room| create_accounts(&admin, server_name.clone(), users_per_room, room, seed),)
(0..rooms)
.map(|room| create_accounts(&admin, server_name.clone(), users_per_room, room, seed)),
)
.await;

Expand All @@ -154,7 +160,7 @@ pub async fn init() -> Test {
.iter()
// make first user in the array the admin
.map(|users| users[0].1.clone())
.collect::<Vec<_>>()
.collect::<Vec<_>>(),
)
.await;

Expand All @@ -181,15 +187,13 @@ pub async fn join_helper(
users: impl Iterator<Item = (&OwnedUserId, &String)>,
room_id: &RoomId,
) -> Vec<Result<JoinRoomResponse>> {
future::join_all(
users
.map(|(_, access_token)| {
RoomService::join(
&client,
access_token.clone(),
room_id.into(),
JoinRoomBody::default(),
)
future::join_all(users.map(|(_, access_token)| {
RoomService::join(
&client,
access_token.clone(),
room_id.into(),
JoinRoomBody::default(),
)
}))
.await
}

0 comments on commit 09fa39b

Please sign in to comment.