Commit cf4168417d
Unsigned
Layout: unified · split
src/connection.rs +5 −5
| @@ -82,12 +82,12 @@ pub enum ClientMessage { | ||
| 82 | 82 | /// |
| 83 | 83 | /// While this struct is alive a sync loop will be going on. To cancel the sync |
| 84 | 84 | /// loop drop the object. |
| 85 | #[derive(Debug, Clone)] | |
| 85 | 86 | pub struct Connection { |
| 86 | 87 | #[used] |
| 87 | receiver_task: Task<()>, | |
| 88 | receiver_task: Rc<Task<()>>, | |
| 88 | 89 | client: Client, |
| 89 | #[used] | |
| 90 | runtime: Runtime, | |
| 90 | pub runtime: Rc<Runtime>, | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | impl Connection { |
| @@ -129,8 +129,8 @@ impl Connection { | ||
| 129 | 129 | |
| 130 | 130 | Self { |
| 131 | 131 | client: client.clone(), |
| 132 | runtime, | |
| 133 | receiver_task, | |
| 132 | runtime: Rc::new(runtime), | |
| 133 | receiver_task: Rc::new(receiver_task), | |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
src/server.rs +7 −9
| @@ -180,12 +180,11 @@ impl MatrixServer { | ||
| 180 | 180 | Rc::downgrade(&self.inner) |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | pub fn connection(&self) -> Rc<RefCell<Option<Connection>>> { | |
| 184 | self.inner().connection.clone() | |
| 183 | pub fn connection(&self) -> Option<Connection> { | |
| 184 | self.inner().connection.borrow().clone() | |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | pub async fn delete_devices(&self, devices: Vec<DeviceIdBox>) { |
| 188 | let connection = self.connection(); | |
| 189 | 188 | let formatted = devices |
| 190 | 189 | .iter() |
| 191 | 190 | .map(|d| d.to_string()) |
| @@ -193,7 +192,7 @@ impl MatrixServer { | ||
| 193 | 192 | .join(", "); |
| 194 | 193 | |
| 195 | 194 | let print_success = || { |
| 196 | self.print(&format!( | |
| 195 | self.print_network(&format!( | |
| 197 | 196 | "Successfully deleted device(s) {}", |
| 198 | 197 | formatted |
| 199 | 198 | )); |
| @@ -206,7 +205,7 @@ impl MatrixServer { | ||
| 206 | 205 | )); |
| 207 | 206 | }; |
| 208 | 207 | |
| 209 | if let Some(c) = &*connection.borrow() { | |
| 208 | if let Some(c) = self.connection() { | |
| 210 | 209 | match c.delete_devices(devices.clone(), None).await { |
| 211 | 210 | Ok(_) => print_success(), |
| 212 | 211 | Err(e) => { |
| @@ -234,9 +233,8 @@ impl MatrixServer { | ||
| 234 | 233 | } |
| 235 | 234 | |
| 236 | 235 | pub async fn devices(&self) { |
| 237 | let connection = self.connection(); | |
| 238 | 236 | |
| 239 | if let Some(c) = &*connection.borrow() { | |
| 237 | if let Some(c) = self.connection() { | |
| 240 | 238 | let response = match c.devices().await { |
| 241 | 239 | Ok(r) => r, |
| 242 | 240 | Err(e) => { |
| @@ -475,7 +473,7 @@ impl MatrixServer { | ||
| 475 | 473 | return Ok(()); |
| 476 | 474 | } |
| 477 | 475 | |
| 478 | let client = self.inner.borrow_mut().get_or_creaet_client()?; | |
| 476 | let client = self.inner.borrow_mut().get_or_create_client()?; | |
| 479 | 477 | let connection = Connection::new(&self, &client); |
| 480 | 478 | |
| 481 | 479 | *self.inner.borrow_mut().connection.borrow_mut() = Some(connection); |
| @@ -677,7 +675,7 @@ impl InnerServer { | ||
| 677 | 675 | buffer_handle |
| 678 | 676 | } |
| 679 | 677 | |
| 680 | fn get_or_creaet_client(&mut self) -> Result<Client, ServerError> { | |
| 678 | fn get_or_create_client(&mut self) -> Result<Client, ServerError> { | |
| 681 | 679 | let client = if let Some(c) = self.client.as_ref() { |
| 682 | 680 | c.clone() |
| 683 | 681 | } else { |