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 {
389389 /// Open the members window.
390390 Members(Box<CommandContext>),
391391
392 /// Set whether a room is a direct message.
393 SetDirect(bool),
394
392395 /// Set a room property.
393396 Set(RoomField, String),
394397
src/commands.rs +34
@@ -422,6 +422,14 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult {
422422 }
423423
424424 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
425433 // :room name set <room-name>
426434 ("name", "set", Some(s)) => RoomAction::Set(RoomField::Name, s).into(),
427435 ("name", "set", None) => return Result::Err(CommandError::InvalidArgument),
@@ -789,6 +797,32 @@ mod tests {
789797 assert_eq!(res, Err(CommandError::InvalidArgument));
790798 }
791799
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
792826 #[test]
793827 fn test_cmd_room_tag_set() {
794828 let mut cmds = setup_commands();
src/windows/room/mod.rs +10
@@ -249,6 +249,16 @@ impl RoomState {
249249
250250 Ok(vec![(act, cmd.context.clone())])
251251 },
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 },
252262 RoomAction::Set(field, value) => {
253263 let room = store
254264 .application