| @@ -6,7 +6,6 @@ use std::{convert::TryFrom, str::FromStr as _}; |
| 6 | |
6 | |
| 7 | use matrix_sdk::ruma::{ |
7 | use matrix_sdk::ruma::{ |
| 8 | OwnedMxcUri, |
8 | OwnedMxcUri, |
| 9 | OwnedRoomId, |
| |
| 10 | OwnedRoomOrAliasId, |
9 | OwnedRoomOrAliasId, |
| 11 | OwnedUserId, |
10 | OwnedUserId, |
| 12 | RoomVersionId, |
11 | RoomVersionId, |
| @@ -732,15 +731,15 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 732 | }, |
731 | }, |
| 733 | ("version", "upgrade", None) => return Result::Err(CommandError::InvalidArgument), |
732 | ("version", "upgrade", None) => return Result::Err(CommandError::InvalidArgument), |
| 734 | |
733 | |
| 735 | // :room aliases show |
734 | // :room alias show |
| 736 | ("alias", "show", None) => RoomAction::Show(RoomField::Aliases).into(), |
735 | ("alias", "show", None) => RoomAction::Show(RoomField::Aliases).into(), |
| 737 | ("alias", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), |
736 | ("alias", "show", Some(_)) => return Result::Err(CommandError::InvalidArgument), |
| 738 | |
737 | |
| 739 | // :room aliases unset <alias> |
738 | // :room alias unset <alias> |
| 740 | ("alias", "unset", Some(s)) => RoomAction::Unset(RoomField::Alias(s)).into(), |
739 | ("alias", "unset", Some(s)) => RoomAction::Unset(RoomField::Alias(s)).into(), |
| 741 | ("alias", "unset", None) => return Result::Err(CommandError::InvalidArgument), |
740 | ("alias", "unset", None) => return Result::Err(CommandError::InvalidArgument), |
| 742 | |
741 | |
| 743 | // :room aliases set <alias> |
742 | // :room alias set <alias> |
| 744 | ("alias", "set", Some(s)) => RoomAction::Set(RoomField::Alias(s), "".into()).into(), |
743 | ("alias", "set", Some(s)) => RoomAction::Set(RoomField::Alias(s), "".into()).into(), |
| 745 | ("alias", "set", None) => return Result::Err(CommandError::InvalidArgument), |
744 | ("alias", "set", None) => return Result::Err(CommandError::InvalidArgument), |
| 746 | |
745 | |
| @@ -882,15 +881,12 @@ fn iamb_space(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 882 | } |
881 | } |
| 883 | } |
882 | } |
| 884 | |
883 | |
| 885 | let child = if let Some(child) = raw_child { |
884 | let Some(child) = raw_child else { |
| 886 | OwnedRoomId::from_str(&child) |
| |
| 887 | .map_err(|_| CommandError::Error("Invalid room id specified".into()))? |
| |
| 888 | } else { |
| |
| 889 | let msg = "Must specify a room to add"; |
885 | let msg = "Must specify a room to add"; |
| 890 | return Err(CommandError::Error(msg.into())); |
886 | return Err(CommandError::Error(msg.into())); |
| 891 | }; |
887 | }; |
| 892 | |
888 | |
| 893 | SpaceAction::SetChild(child, order, suggested).into() |
889 | SpaceAction::SetChild { child, order, suggested }.into() |
| 894 | }, |
890 | }, |
| 895 | _ => return Result::Err(CommandError::InvalidArgument), |
891 | _ => return Result::Err(CommandError::InvalidArgument), |
| 896 | }; |
892 | }; |
| @@ -1113,7 +1109,7 @@ pub fn setup_commands() -> ProgramCommands { |
| 1113 | #[cfg(test)] |
1109 | #[cfg(test)] |
| 1114 | mod tests { |
1110 | mod tests { |
| 1115 | use super::*; |
1111 | use super::*; |
| 1116 | use matrix_sdk::ruma::{room_id, user_id}; |
1112 | use matrix_sdk::ruma::user_id; |
| 1117 | use modalkit::actions::WindowAction; |
1113 | use modalkit::actions::WindowAction; |
| 1118 | use modalkit::editing::context::EditContext; |
1114 | use modalkit::editing::context::EditContext; |
| 1119 | |
1115 | |
| @@ -1493,16 +1489,20 @@ mod tests { |
| 1493 | |
1489 | |
| 1494 | let cmd = "space child set !roomid:example.org"; |
1490 | let cmd = "space child set !roomid:example.org"; |
| 1495 | let res = cmds.input_cmd(cmd, ctx.clone()).unwrap(); |
1491 | let res = cmds.input_cmd(cmd, ctx.clone()).unwrap(); |
| 1496 | let act = SpaceAction::SetChild(room_id!("!roomid:example.org").to_owned(), None, false); |
1492 | let act = SpaceAction::SetChild { |
| |
1493 | child: "!roomid:example.org".to_owned(), |
| |
1494 | order: None, |
| |
1495 | suggested: false, |
| |
1496 | }; |
| 1497 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
1497 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 1498 | |
1498 | |
| 1499 | let cmd = "space child set ++order=abcd ++suggested !roomid:example.org"; |
1499 | let cmd = "space child set ++order=abcd ++suggested !roomid:example.org"; |
| 1500 | let res = cmds.input_cmd(cmd, ctx.clone()).unwrap(); |
1500 | let res = cmds.input_cmd(cmd, ctx.clone()).unwrap(); |
| 1501 | let act = SpaceAction::SetChild( |
1501 | let act = SpaceAction::SetChild { |
| 1502 | room_id!("!roomid:example.org").to_owned(), |
1502 | child: "!roomid:example.org".to_owned(), |
| 1503 | Some("abcd".into()), |
1503 | order: Some("abcd".into()), |
| 1504 | true, |
1504 | suggested: true, |
| 1505 | ); |
1505 | }; |
| 1506 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
1506 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 1507 | |
1507 | |
| 1508 | let cmd = "space child set ++order=abcd ++order=1234 !roomid:example.org"; |
1508 | let cmd = "space child set ++order=abcd ++order=1234 !roomid:example.org"; |
| @@ -1528,10 +1528,6 @@ mod tests { |
| 1528 | let res = cmds.input_cmd(cmd, ctx.clone()); |
1528 | let res = cmds.input_cmd(cmd, ctx.clone()); |
| 1529 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
1529 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 1530 | |
1530 | |
| 1531 | let cmd = "space child set foo"; |
| |
| 1532 | let res = cmds.input_cmd(cmd, ctx.clone()); |
| |
| 1533 | assert_eq!(res, Err(CommandError::Error("Invalid room id specified".into()))); |
| |
| 1534 | |
| |
| 1535 | let cmd = "space child set"; |
1531 | let cmd = "space child set"; |
| 1536 | let res = cmds.input_cmd(cmd, ctx.clone()); |
1532 | let res = cmds.input_cmd(cmd, ctx.clone()); |
| 1537 | assert_eq!(res, Err(CommandError::Error("Must specify a room to add".into()))); |
1533 | assert_eq!(res, Err(CommandError::Error("Must specify a room to add".into()))); |