Commit cf277acd77
Unsigned
Layout: unified · split
src/commands.rs +31 −5
| @@ -216,11 +216,22 @@ Use /matrix [command] help to find out more.\n", | ||
| 216 | 216 | .subcommand(server_command) |
| 217 | 217 | .subcommand( |
| 218 | 218 | SubCommand::with_name("connect") |
| 219 | .about("Connect to Matrix servers."), | |
| 219 | .about("Connect to Matrix servers.") | |
| 220 | .arg( | |
| 221 | Arg::with_name("name") | |
| 222 | .value_name("server-name") | |
| 223 | .required(true) | |
| 224 | .multiple(true), | |
| 225 | ), | |
| 220 | 226 | ) |
| 221 | 227 | .subcommand( |
| 222 | 228 | SubCommand::with_name("disconnect") |
| 223 | .about("Disconnect from one or all Matrix servers"), | |
| 229 | .about("Disconnect from one or all Matrix servers") | |
| 230 | .arg( | |
| 231 | Arg::with_name("name") | |
| 232 | .value_name("server-name") | |
| 233 | .required(true), | |
| 234 | ), | |
| 224 | 235 | ); |
| 225 | 236 | |
| 226 | 237 | let matches = match argparse.get_matches_from_safe(args) { |
| @@ -246,10 +257,25 @@ Use /matrix [command] help to find out more.\n", | ||
| 246 | 257 | } |
| 247 | 258 | } |
| 248 | 259 | ("disconnect", Some(subargs)) => { |
| 249 | weechat.print("Disconnecting"); | |
| 250 | 260 | let mut servers = servers.borrow_mut(); |
| 251 | for server in servers.values_mut() { | |
| 252 | server.disconnect(); | |
| 261 | ||
| 262 | let server_name = subargs | |
| 263 | .value_of("name") | |
| 264 | .expect("Server name not set but was required"); | |
| 265 | ||
| 266 | let server = servers.get_mut(server_name); | |
| 267 | ||
| 268 | if let Some(s) = server { | |
| 269 | s.disconnect(); | |
| 270 | } else { | |
| 271 | weechat.print(&format!( | |
| 272 | "{}{}: Server \"{}{}{}\" not found.", | |
| 273 | weechat.prefix("error"), | |
| 274 | PLUGIN_NAME, | |
| 275 | weechat.color("chat_server"), | |
| 276 | server_name, | |
| 277 | weechat.color("reset") | |
| 278 | )); | |
| 253 | 279 | } |
| 254 | 280 | } |
| 255 | 281 | ("server", Some(subargs)) => { |
src/server.rs +9
| @@ -27,6 +27,7 @@ use weechat::Weechat; | ||
| 27 | 27 | use crate::executor::spawn_weechat; |
| 28 | 28 | use crate::room_buffer::RoomBuffer; |
| 29 | 29 | use crate::Config; |
| 30 | use crate::PLUGIN_NAME; | |
| 30 | 31 | |
| 31 | 32 | const DEFAULT_SYNC_TIMEOUT: i32 = 30000; |
| 32 | 33 | |
| @@ -280,6 +281,10 @@ impl InnerServer { | ||
| 280 | 281 | |
| 281 | 282 | impl MatrixServer { |
| 282 | 283 | pub fn connect(&self) -> Result<(), ServerError> { |
| 284 | if self.connected() { | |
| 285 | return Ok(()); | |
| 286 | } | |
| 287 | ||
| 283 | 288 | let runtime = Runtime::new().unwrap(); |
| 284 | 289 | let mut server = self.inner.borrow_mut(); |
| 285 | 290 | |
| @@ -323,6 +328,8 @@ impl MatrixServer { | ||
| 323 | 328 | } |
| 324 | 329 | |
| 325 | 330 | pub fn disconnect(&self) { |
| 331 | let weechat = unsafe { Weechat::weechat() }; | |
| 332 | ||
| 326 | 333 | let server = self.inner.borrow_mut(); |
| 327 | 334 | let mut connected_state = server.connected_state.borrow_mut(); |
| 328 | 335 | let state = connected_state.take(); |
| @@ -330,6 +337,8 @@ impl MatrixServer { | ||
| 330 | 337 | if let Some(s) = state { |
| 331 | 338 | s.response_receiver.cancel(); |
| 332 | 339 | } |
| 340 | ||
| 341 | weechat.print(&format!("{}: Disconnected from server.", PLUGIN_NAME)); | |
| 333 | 342 | } |
| 334 | 343 | |
| 335 | 344 | /// Main client sync loop. |