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