mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-19 21:29:52 -07:00
Support marking a room as a direct message room (#92)
This commit is contained in:
parent
82645c8828
commit
a98bbd97be
3 changed files with 47 additions and 0 deletions
|
@ -389,6 +389,9 @@ pub enum RoomAction {
|
||||||
/// Open the members window.
|
/// Open the members window.
|
||||||
Members(Box<CommandContext>),
|
Members(Box<CommandContext>),
|
||||||
|
|
||||||
|
/// Set whether a room is a direct message.
|
||||||
|
SetDirect(bool),
|
||||||
|
|
||||||
/// Set a room property.
|
/// Set a room property.
|
||||||
Set(RoomField, String),
|
Set(RoomField, String),
|
||||||
|
|
||||||
|
|
|
@ -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()) {
|
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 <room-name>
|
// :room name set <room-name>
|
||||||
("name", "set", Some(s)) => RoomAction::Set(RoomField::Name, s).into(),
|
("name", "set", Some(s)) => RoomAction::Set(RoomField::Name, s).into(),
|
||||||
("name", "set", None) => return Result::Err(CommandError::InvalidArgument),
|
("name", "set", None) => return Result::Err(CommandError::InvalidArgument),
|
||||||
|
@ -789,6 +797,32 @@ mod tests {
|
||||||
assert_eq!(res, Err(CommandError::InvalidArgument));
|
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]
|
#[test]
|
||||||
fn test_cmd_room_tag_set() {
|
fn test_cmd_room_tag_set() {
|
||||||
let mut cmds = setup_commands();
|
let mut cmds = setup_commands();
|
||||||
|
|
|
@ -249,6 +249,16 @@ impl RoomState {
|
||||||
|
|
||||||
Ok(vec![(act, cmd.context.clone())])
|
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) => {
|
RoomAction::Set(field, value) => {
|
||||||
let room = store
|
let room = store
|
||||||
.application
|
.application
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue