Skip to content

Commit

Permalink
Include a room alias when creating a room
Browse files Browse the repository at this point in the history
To be able to forward messages to the applicatio service even if the bot is not in the room
  • Loading branch information
exul committed May 13, 2017
1 parent 26c1a4e commit 2a436cc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/matrix-rocketchat/api/matrix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod r0;
/// Matrix REST API
pub trait MatrixApi: Send + Sync + MatrixApiClone {
/// Create a room.
fn create_room(&self, room_name: String) -> Result<RoomId>;
fn create_room(&self, room_name: String, room_alias_name: Option<String>) -> Result<RoomId>;
/// Forget a room.
fn forget_room(&self, matrix_room_id: RoomId) -> Result<()>;
/// Get the list of members for this room.
Expand Down
4 changes: 2 additions & 2 deletions src/matrix-rocketchat/api/matrix/r0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ impl MatrixApi {
}

impl super::MatrixApi for MatrixApi {
fn create_room(&self, room_name: String) -> Result<RoomId> {
fn create_room(&self, room_name: String, room_alias_name: Option<String>) -> Result<RoomId> {
let endpoint = self.base_url.clone() + &CreateRoomEndpoint::request_path(());
let body_params = create_room::BodyParams {
creation_content: None,
invite: vec![],
name: Some(room_name),
preset: Some(RoomPreset::PrivateChat),
room_alias_name: None,
room_alias_name: room_alias_name,
topic: None,
visibility: Some("private".to_string()),
};
Expand Down
3 changes: 2 additions & 1 deletion src/matrix-rocketchat/handlers/events/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ impl<'a> CommandHandler<'a> {

fn create_room(&self, channel: &Channel, rocketchat_server_id: String, user_id: UserId) -> Result<Room> {
let bot_matrix_user_id = self.config.matrix_bot_user_id()?;
let matrix_room_id = self.matrix_api.create_room(channel.name.clone())?;
let room_alias_name = format!("{}_{}_{}", self.config.sender_localpart, rocketchat_server_id, channel.id);
let matrix_room_id = self.matrix_api.create_room(channel.name.clone(), Some(room_alias_name))?;
self.matrix_api.set_default_powerlevels(matrix_room_id.clone(), bot_matrix_user_id.clone())?;
self.matrix_api.invite(matrix_room_id.clone(), user_id.clone())?;
let new_room = NewRoom {
Expand Down
4 changes: 4 additions & 0 deletions tests/admin_commands_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ fn successfully_bridge_a_rocketchat_room() {
UserId::try_from("@spec_user:localhost").unwrap(),
"bridge joined_channel".to_string());

let create_room_message = create_room_receiver.recv_timeout(default_timeout()).unwrap();
assert!(create_room_message.contains("\"name\":\"joined_channel\""));
assert!(create_room_message.contains("\"room_alias_name\":\"rocketchat_rc_id_joined_channel_id\""));

let invite_spec_user = invite_receiver.recv_timeout(default_timeout()).unwrap();
assert!(invite_spec_user.contains("@spec_user:localhost"));
let invite_virtual_spec_user = invite_receiver.recv_timeout(default_timeout()).unwrap();
Expand Down

0 comments on commit 2a436cc

Please sign in to comment.