diff --git a/src/base.rs b/src/base.rs index fef5b11..49a1312 100644 --- a/src/base.rs +++ b/src/base.rs @@ -389,6 +389,9 @@ pub enum RoomAction { /// Open the members window. Members(Box), + /// Set whether a room is a direct message. + SetDirect(bool), + /// Set a room property. Set(RoomField, String), diff --git a/src/commands.rs b/src/commands.rs index d6db847..6781f1b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -422,6 +422,14 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { } let act: IambAction = match (field.as_str(), action.as_str(), args.pop()) { + // :room dm set + ("dm", "set", None) => RoomAction::SetDirect(true).into(), + ("dm", "set", Some(_)) => return Result::Err(CommandError::InvalidArgument), + + // :room dm set + ("dm", "unset", None) => RoomAction::SetDirect(false).into(), + ("dm", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument), + // :room name set ("name", "set", Some(s)) => RoomAction::Set(RoomField::Name, s).into(), ("name", "set", None) => return Result::Err(CommandError::InvalidArgument), @@ -789,6 +797,32 @@ mod tests { assert_eq!(res, Err(CommandError::InvalidArgument)); } + #[test] + fn test_cmd_room_dm_set() { + let mut cmds = setup_commands(); + let ctx = EditContext::default(); + + let res = cmds.input_cmd("room dm set", ctx.clone()).unwrap(); + let act = RoomAction::SetDirect(true); + assert_eq!(res, vec![(act.into(), ctx.clone())]); + + let res = cmds.input_cmd("room dm set true", ctx.clone()); + assert_eq!(res, Err(CommandError::InvalidArgument)); + } + + #[test] + fn test_cmd_room_dm_unset() { + let mut cmds = setup_commands(); + let ctx = EditContext::default(); + + let res = cmds.input_cmd("room dm unset", ctx.clone()).unwrap(); + let act = RoomAction::SetDirect(false); + assert_eq!(res, vec![(act.into(), ctx.clone())]); + + let res = cmds.input_cmd("room dm unset true", ctx.clone()); + assert_eq!(res, Err(CommandError::InvalidArgument)); + } + #[test] fn test_cmd_room_tag_set() { let mut cmds = setup_commands(); diff --git a/src/windows/room/mod.rs b/src/windows/room/mod.rs index afe4547..56d13f6 100644 --- a/src/windows/room/mod.rs +++ b/src/windows/room/mod.rs @@ -249,6 +249,16 @@ impl RoomState { Ok(vec![(act, cmd.context.clone())]) }, + RoomAction::SetDirect(is_direct) => { + let room = store + .application + .get_joined_room(self.id()) + .ok_or(UIError::Application(IambError::NotJoined))?; + + room.set_is_direct(is_direct).await.map_err(IambError::from)?; + + Ok(vec![]) + }, RoomAction::Set(field, value) => { let room = store .application