Commit a98bbd97be

a98bbd97be3f766b0f93308798a79cdb452af491

parent: 82645c8828

Unregistered key

Ulyssa <git@ulyssa.dev> · 2024-03-31 07:12 UTC

Support marking a room as a direct message room (#92)

Layout: unified · split

src/base.rs +3
@@ -389,6 +389,9 @@ pub enum RoomAction {
389 /// Open the members window. 389 /// Open the members window.
390 Members(Box<CommandContext>), 390 Members(Box<CommandContext>),
391 391
392 /// Set whether a room is a direct message.
393 SetDirect(bool),
394
392 /// Set a room property. 395 /// Set a room property.
393 Set(RoomField, String), 396 Set(RoomField, String),
394 397
src/commands.rs +34
@@ -422,6 +422,14 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
422 } 422 }
423 423
424 let act: IambAction = match (field.as_str(), action.as_str(), args.pop()) { 424 let act: IambAction = match (field.as_str(), action.as_str(), args.pop()) {
425 // :room dm set
426 ("dm", "set", None) => RoomAction::SetDirect(true).into(),
427 ("dm", "set", Some(_)) => return Result::Err(CommandError::InvalidArgument),
428
429 // :room dm set
430 ("dm", "unset", None) => RoomAction::SetDirect(false).into(),
431 ("dm", "unset", Some(_)) => return Result::Err(CommandError::InvalidArgument),
432
425 // :room name set <room-name> 433 // :room name set <room-name>
426 ("name", "set", Some(s)) => RoomAction::Set(RoomField::Name, s).into(), 434 ("name", "set", Some(s)) => RoomAction::Set(RoomField::Name, s).into(),
427 ("name", "set", None) => return Result::Err(CommandError::InvalidArgument), 435 ("name", "set", None) => return Result::Err(CommandError::InvalidArgument),
@@ -789,6 +797,32 @@ mod tests {
789 assert_eq!(res, Err(CommandError::InvalidArgument)); 797 assert_eq!(res, Err(CommandError::InvalidArgument));
790 } 798 }
791 799
800 #[test]
801 fn test_cmd_room_dm_set() {
802 let mut cmds = setup_commands();
803 let ctx = EditContext::default();
804
805 let res = cmds.input_cmd("room dm set", ctx.clone()).unwrap();
806 let act = RoomAction::SetDirect(true);
807 assert_eq!(res, vec![(act.into(), ctx.clone())]);
808
809 let res = cmds.input_cmd("room dm set true", ctx.clone());
810 assert_eq!(res, Err(CommandError::InvalidArgument));
811 }
812
813 #[test]
814 fn test_cmd_room_dm_unset() {
815 let mut cmds = setup_commands();
816 let ctx = EditContext::default();
817
818 let res = cmds.input_cmd("room dm unset", ctx.clone()).unwrap();
819 let act = RoomAction::SetDirect(false);
820 assert_eq!(res, vec![(act.into(), ctx.clone())]);
821
822 let res = cmds.input_cmd("room dm unset true", ctx.clone());
823 assert_eq!(res, Err(CommandError::InvalidArgument));
824 }
825
792 #[test] 826 #[test]
793 fn test_cmd_room_tag_set() { 827 fn test_cmd_room_tag_set() {
794 let mut cmds = setup_commands(); 828 let mut cmds = setup_commands();
src/windows/room/mod.rs +10
@@ -249,6 +249,16 @@ impl RoomState {
249 249
250 Ok(vec![(act, cmd.context.clone())]) 250 Ok(vec![(act, cmd.context.clone())])
251 }, 251 },
252 RoomAction::SetDirect(is_direct) => {
253 let room = store
254 .application
255 .get_joined_room(self.id())
256 .ok_or(UIError::Application(IambError::NotJoined))?;
257
258 room.set_is_direct(is_direct).await.map_err(IambError::from)?;
259
260 Ok(vec![])
261 },
252 RoomAction::Set(field, value) => { 262 RoomAction::Set(field, value) => {
253 let room = store 263 let room = store
254 .application 264 .application