Skip to content

Commit

Permalink
feat: room_membership api
Browse files Browse the repository at this point in the history
  • Loading branch information
kilimnik committed Jan 9, 2025
1 parent 0a033da commit 623f490
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod account_validity;
pub mod background_updates;
pub mod experimental_features;
pub mod register_users;
pub mod room_membership;
pub mod rooms;
pub mod users;
pub mod version;
Expand Down
3 changes: 3 additions & 0 deletions src/room_membership.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Endpoints in the `/_synapse/admin/v<x>/join/` scope.
pub mod join_room;
3 changes: 3 additions & 0 deletions src/room_membership/join_room.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Different versions of the endpoint to place users into rooms.
pub mod v1;
62 changes: 62 additions & 0 deletions src/room_membership/join_room/v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! [POST /_synapse/admin/v1/join/:room_id_or_alias](https://github.com/element-hq/synapse/blob/master/docs/admin_api/room_membership.md)
use ruma::{
api::{request, response, Metadata},
metadata, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId,
};

const METADATA: Metadata = metadata! {
method: POST,
rate_limited: false,
authentication: AccessToken,
history: {
unstable => "/_synapse/admin/v1/join/:room_id_or_alias",
}
};

#[request]
pub struct Request {
/// Alias or ID of the room to join.
#[ruma_api(path)]
pub room_id_or_alias: OwnedRoomOrAliasId,

/// User to join the room.
pub user_id: OwnedUserId,
}

#[response]
pub struct Response {
/// Room ID of the joined room.
pub room_id: OwnedRoomId,
}

impl Request {
/// Creates a new `Request` with the given room or alias ID and user id.
pub fn new(room_id_or_alias: OwnedRoomOrAliasId, user_id: OwnedUserId) -> Self {
Self { room_id_or_alias, user_id }
}
}

impl Response {
/// Creates a new `Response` with the given room id
pub fn new(room_id: OwnedRoomId) -> Self {
Self { room_id }
}
}

#[test]
fn test_join_room() {
use ruma::{owned_room_id, owned_user_id, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId};

let room_id: OwnedRoomId = owned_room_id!("!test:example.com");
let user_id: OwnedUserId = owned_user_id!("@carl:example.com");

// Check create request
let request = Request::new(room_id.clone().into(), user_id.clone());
assert_eq!(request.room_id_or_alias, OwnedRoomOrAliasId::from(room_id.clone()));
assert_eq!(request.user_id, user_id);

// Check create response
let response = Response::new(room_id.clone());
assert_eq!(response.room_id, room_id);
}

0 comments on commit 623f490

Please sign in to comment.