Commit cefc84e099
Unsigned
Layout: unified · split
src/commands/access.rs +19 −5
| @@ -13,6 +13,8 @@ use crate::Servers; | |||
| 13 | enum AccessAction { | 13 | enum AccessAction { |
| 14 | Public, | 14 | Public, |
| 15 | Invite, | 15 | Invite, |
| 16 | Knock, | ||
| 17 | Private, | ||
| 16 | } | 18 | } |
| 17 | 19 | ||
| 18 | impl AccessAction { | 20 | impl AccessAction { |
| @@ -20,6 +22,8 @@ impl AccessAction { | |||
| 20 | match self { | 22 | match self { |
| 21 | Self::Public => JoinRule::Public, | 23 | Self::Public => JoinRule::Public, |
| 22 | Self::Invite => JoinRule::Invite, | 24 | Self::Invite => JoinRule::Invite, |
| 25 | Self::Knock => JoinRule::Knock, | ||
| 26 | Self::Private => JoinRule::Private, | ||
| 23 | } | 27 | } |
| 24 | } | 28 | } |
| 25 | } | 29 | } |
| @@ -33,14 +37,14 @@ impl RoomAccessCommand { | |||
| 33 | let settings = CommandSettings::new("room") | 37 | let settings = CommandSettings::new("room") |
| 34 | .description("Change access rules for the current Matrix room.") | 38 | .description("Change access rules for the current Matrix room.") |
| 35 | .add_argument("make_public|make_invite_only") | 39 | .add_argument("make_public|make_invite_only") |
| 36 | .add_argument("set_join_rule <public|invite>") | 40 | .add_argument("set_join_rule <public|invite|knock|private>") |
| 37 | .arguments_description( | 41 | .arguments_description( |
| 38 | "make_public: Allow anyone to join the room.\n\ | 42 | "make_public: Allow anyone to join the room.\n\ |
| 39 | make_invite_only: Require an invitation to join.\n\ | 43 | make_invite_only: Require an invitation to join.\n\ |
| 40 | set_join_rule: Set the join rule to public or invite.", | 44 | set_join_rule: Set the join rule to public, invite, knock, or private.", |
| 41 | ) | 45 | ) |
| 42 | .add_completion( | 46 | .add_completion( |
| 43 | "make_public|make_invite_only|set_join_rule public|invite", | 47 | "make_public|make_invite_only|set_join_rule public|invite|knock|private", |
| 44 | ); | 48 | ); |
| 45 | 49 | ||
| 46 | Command::new( | 50 | Command::new( |
| @@ -72,13 +76,15 @@ impl RoomAccessCommand { | |||
| 72 | ("set_join_rule", Some(args)) => match args.value_of("rule") { | 76 | ("set_join_rule", Some(args)) => match args.value_of("rule") { |
| 73 | Some("public") => Ok(AccessAction::Public), | 77 | Some("public") => Ok(AccessAction::Public), |
| 74 | Some("invite") | Some("invite_only") => Ok(AccessAction::Invite), | 78 | Some("invite") | Some("invite_only") => Ok(AccessAction::Invite), |
| 79 | Some("knock") => Ok(AccessAction::Knock), | ||
| 80 | Some("private") => Ok(AccessAction::Private), | ||
| 75 | Some(rule) => Err(format!( | 81 | Some(rule) => Err(format!( |
| 76 | "Unsupported join rule `{}`; use public or invite.", | 82 | "Unsupported join rule `{}`; use public, invite, knock, or private.", |
| 77 | rule | 83 | rule |
| 78 | )), | 84 | )), |
| 79 | None => Err("A join rule is required.".to_owned()), | 85 | None => Err("A join rule is required.".to_owned()), |
| 80 | }, | 86 | }, |
| 81 | _ => Err("Usage: /room make_public|make_invite_only|set_join_rule <public|invite>".to_owned()), | 87 | _ => Err("Usage: /room make_public|make_invite_only|set_join_rule <public|invite|knock|private>".to_owned()), |
| 82 | } | 88 | } |
| 83 | } | 89 | } |
| 84 | 90 | ||
| @@ -141,6 +147,14 @@ mod tests { | |||
| 141 | Ok(AccessAction::Invite), | 147 | Ok(AccessAction::Invite), |
| 142 | parse(&["room", "set_join_rule", "invite"]) | 148 | parse(&["room", "set_join_rule", "invite"]) |
| 143 | ); | 149 | ); |
| 150 | assert_eq!( | ||
| 151 | Ok(AccessAction::Knock), | ||
| 152 | parse(&["room", "set_join_rule", "knock"]) | ||
| 153 | ); | ||
| 154 | assert_eq!( | ||
| 155 | Ok(AccessAction::Private), | ||
| 156 | parse(&["room", "set_join_rule", "private"]) | ||
| 157 | ); | ||
| 144 | } | 158 | } |
| 145 | 159 | ||
| 146 | #[test] | 160 | #[test] |
src/room/mod.rs +2
| @@ -1698,6 +1698,8 @@ impl MatrixRoom { | |||
| 1698 | let description = match join_rule { | 1698 | let description = match join_rule { |
| 1699 | JoinRule::Public => "public", | 1699 | JoinRule::Public => "public", |
| 1700 | JoinRule::Invite => "invite-only", | 1700 | JoinRule::Invite => "invite-only", |
| 1701 | JoinRule::Knock => "knock", | ||
| 1702 | JoinRule::Private => "private", | ||
| 1701 | _ => "requested", | 1703 | _ => "requested", |
| 1702 | }; | 1704 | }; |
| 1703 | 1705 | ||