Commit 04010126ff

04010126ff8c6c7d5bfcb08b17aac83fb8ee1c06

parent: b7fe34020a

Unregistered key

vaw <git@nlih.de> · 2026-09-04 16:33 UTC
committer: <git@ulyssa.dev>

Support using room aliases and DMs with `:space child set` (#672)

Layout: unified · split

docs/iamb.1 +1 −1
@@ -250,7 +250,7 @@ Show the display name you currently have in this room.
250.El 250.El
251.Sh "SPACE COMMANDS" 251.Sh "SPACE COMMANDS"
252.Bl -tag -width Ds 252.Bl -tag -width Ds
253.It Sy ":space child set [room_id] [arguments]" 253.It Sy ":space child set [room] [arguments]"
254Add a room to the currently focused space. 254Add a room to the currently focused space.
255.Dq ++suggested 255.Dq ++suggested
256marks the room as a suggested child. 256marks the room as a suggested child.
src/base.rs +8 −3
@@ -195,9 +195,14 @@ pub enum MessageAction {
195pub enum SpaceAction { 195pub enum SpaceAction {
196 /// Add a room or update metadata. 196 /// Add a room or update metadata.
197 /// 197 ///
198 /// The [`Option<String>`] argument is the order parameter. 198 SetChild {
199 /// The [`bool`] argument indicates whether the room is suggested. 199 /// The room ID, alias, or a user whose DM room should be added to the space.
200 SetChild(OwnedRoomId, Option<String>, bool), 200 child: String,
201 /// The order parameter to use when sorting children in the space.
202 order: Option<String>,
203 /// Whether the room is suggested.
204 suggested: bool,
205 },
201 206
202 /// Remove the selected room. 207 /// Remove the selected room.
203 RemoveChild, 208 RemoveChild,
src/commands.rs +16 −20
@@ -6,7 +6,6 @@ use std::{convert::TryFrom, str::FromStr as _};
6 6
7use matrix_sdk::ruma::{ 7use 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)]
1114mod tests { 1110mod 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())));
src/windows/room/space.rs +3 −1
@@ -90,7 +90,7 @@ impl SpaceState {
90 store: &mut ProgramStore, 90 store: &mut ProgramStore,
91 ) -> IambResult<EditInfo> { 91 ) -> IambResult<EditInfo> {
92 match act { 92 match act {
93 SpaceAction::SetChild(child_id, order, suggested) => { 93 SpaceAction::SetChild { child, order, suggested } => {
94 if !self 94 if !self
95 .room 95 .room
96 .power_levels() 96 .power_levels()
@@ -105,6 +105,8 @@ impl SpaceState {
105 return Err(IambError::InsufficientPermission.into()); 105 return Err(IambError::InsufficientPermission.into());
106 } 106 }
107 107
108 let child_id = store.application.worker.join_room(child)?;
109
108 let via = self.room.route().await.map_err(IambError::from)?; 110 let via = self.room.route().await.map_err(IambError::from)?;
109 let mut ev = SpaceChildEventContent::new(via); 111 let mut ev = SpaceChildEventContent::new(via);
110 ev.order = order 112 ev.order = order