| @@ -10,7 +10,11 @@ use weechat::{ |
| 10 | 10 | Args, Prefix, Weechat, |
| 11 | 11 | }; |
| 12 | 12 | |
| 13 | | use super::{parse_and_run, verification::VerificationCommand}; |
| 13 | use super::{ |
| 14 | join::{print_no_join_server_error, JoinCommand}, |
| 15 | parse_and_run, |
| 16 | verification::VerificationCommand, |
| 17 | }; |
| 14 | 18 | use crate::{ |
| 15 | 19 | commands::{DevicesCommand, KeysCommand, MediaCommand}, |
| 16 | 20 | config::ConfigHandle, |
| @@ -32,7 +36,7 @@ impl MatrixCommand { |
| 32 | 36 | .add_argument("server add <server-name> <hostname>[:<port>]") |
| 33 | 37 | .add_argument("server delete|list|listfull <server-name>") |
| 34 | 38 | .add_argument("connect <server-name>") |
| 35 | | .add_argument("join <server-name> <room-id-or-alias>") |
| 39 | .add_argument("join <room-id-or-alias>") |
| 36 | 40 | .add_argument("devices delete|list|set-name") |
| 37 | 41 | .add_argument("keys import|export <file> <passphrase>") |
| 38 | 42 | .add_argument("media download <mxc-uri> [file]") |
| @@ -44,7 +48,7 @@ impl MatrixCommand { |
| 44 | 48 | connect: Connect to Matrix servers. |
| 45 | 49 | disconnect: Disconnect from one or all Matrix servers. |
| 46 | 50 | reconnect: Reconnect to server(s). |
| 47 | | join: Join a Matrix room by ID or alias (e.g. #room:matrix.org). |
| 51 | join: Join a Matrix room by ID or alias. |
| 48 | 52 | devices: {} |
| 49 | 53 | keys: {} |
| 50 | 54 | media: {} |
| @@ -67,7 +71,6 @@ Use /matrix [command] help to find out more.\n", |
| 67 | 71 | .add_completion("connect %(matrix_servers)") |
| 68 | 72 | .add_completion("disconnect %(matrix_servers)") |
| 69 | 73 | .add_completion("reconnect %(matrix_servers)") |
| 70 | | .add_completion("join %(matrix_servers)") |
| 71 | 74 | .add_completion( |
| 72 | 75 | "help server|connect|disconnect|reconnect|join|keys|devices|media", |
| 73 | 76 | ); |
| @@ -226,23 +229,19 @@ Use /matrix [command] help to find out more.\n", |
| 226 | 229 | } |
| 227 | 230 | } |
| 228 | 231 | |
| 229 | | fn join_command(&self, args: &ArgMatches) { |
| 230 | | let server_name = args |
| 231 | | .value_of("server") |
| 232 | | .expect("Server name not set but was required"); |
| 232 | fn join_command(&self, buffer: &Buffer, args: &ArgMatches) { |
| 233 | 233 | let room_id_or_alias = args |
| 234 | 234 | .value_of("room") |
| 235 | 235 | .expect("Room not set but was required") |
| 236 | | .to_string(); |
| 237 | | |
| 238 | | if let Some(s) = self.servers.get(server_name) { |
| 239 | | let server = s.clone(); |
| 240 | | Weechat::spawn(async move { |
| 241 | | server.join_room(room_id_or_alias).await; |
| 242 | | }) |
| 243 | | .detach(); |
| 244 | | } else { |
| 245 | | self.server_not_found(server_name) |
| 236 | .to_owned(); |
| 237 | |
| 238 | if !JoinCommand::join_room( |
| 239 | &self.servers, |
| 240 | buffer, |
| 241 | room_id_or_alias, |
| 242 | true, |
| 243 | ) { |
| 244 | print_no_join_server_error(); |
| 246 | 245 | } |
| 247 | 246 | } |
| 248 | 247 | |
| @@ -250,7 +249,7 @@ Use /matrix [command] help to find out more.\n", |
| 250 | 249 | match args.subcommand() { |
| 251 | 250 | ("connect", Some(subargs)) => self.connect_command(subargs), |
| 252 | 251 | ("disconnect", Some(subargs)) => self.disconnect_command(subargs), |
| 253 | | ("join", Some(subargs)) => self.join_command(subargs), |
| 252 | ("join", Some(subargs)) => self.join_command(buffer, subargs), |
| 254 | 253 | ("server", Some(subargs)) => self.server_command(subargs), |
| 255 | 254 | ("devices", Some(subargs)) => { |
| 256 | 255 | DevicesCommand::run(buffer, &self.servers, subargs) |
| @@ -363,18 +362,11 @@ impl CommandCallback for MatrixCommand { |
| 363 | 362 | ) |
| 364 | 363 | .subcommand( |
| 365 | 364 | SubCommand::with_name("join") |
| 366 | | .about("Join a Matrix room by ID or alias.") |
| 367 | | .arg( |
| 368 | | Arg::with_name("server") |
| 369 | | .value_name("server-name") |
| 370 | | .required(true) |
| 371 | | .index(1), |
| 372 | | ) |
| 365 | .about("Join a Matrix room by ID or alias") |
| 373 | 366 | .arg( |
| 374 | 367 | Arg::with_name("room") |
| 375 | 368 | .value_name("room-id-or-alias") |
| 376 | | .required(true) |
| 377 | | .index(2), |
| 369 | .required(true), |
| 378 | 370 | ), |
| 379 | 371 | ); |
| 380 | 372 | |