Commit dab31fa458
Unsigned
Layout: unified · split
src/connection.rs +16
| @@ -22,6 +22,7 @@ use matrix_sdk::{ | ||
| 22 | 22 | ruma::{ |
| 23 | 23 | api::client::{ |
| 24 | 24 | device::{ |
| 25 | delete_device::{self, v3::Response as DeleteDeviceResponse}, | |
| 25 | 26 | delete_devices::v3::Response as DeleteDevicesResponse, |
| 26 | 27 | get_devices::v3::Response as DevicesResponse, |
| 27 | 28 | }, |
| @@ -230,6 +231,21 @@ impl Connection { | ||
| 230 | 231 | .await?) |
| 231 | 232 | } |
| 232 | 233 | |
| 234 | pub async fn delete_device( | |
| 235 | &self, | |
| 236 | device: OwnedDeviceId, | |
| 237 | auth_info: Option<InteractiveAuthInfo>, | |
| 238 | ) -> MatrixResult<DeleteDeviceResponse> { | |
| 239 | let client = self.client().clone(); | |
| 240 | Ok(self | |
| 241 | .spawn(async move { | |
| 242 | let mut request = delete_device::v3::Request::new(device); | |
| 243 | request.auth = auth_info.map(|info| info.as_auth_data()); | |
| 244 | client.send(request).await | |
| 245 | }) | |
| 246 | .await?) | |
| 247 | } | |
| 248 | ||
| 233 | 249 | /// Fetch historical messages for the given room. |
| 234 | 250 | pub async fn room_messages( |
| 235 | 251 | &self, |
src/server.rs +12 −5
| @@ -1279,7 +1279,17 @@ impl InnerServer { | ||
| 1279 | 1279 | }; |
| 1280 | 1280 | |
| 1281 | 1281 | if let Some(c) = self.connection() { |
| 1282 | match c.delete_devices(devices.clone(), None).await { | |
| 1282 | let delete = |auth_info| async { | |
| 1283 | if let [device] = devices.as_slice() { | |
| 1284 | c.delete_device(device.clone(), auth_info).await.map(|_| ()) | |
| 1285 | } else { | |
| 1286 | c.delete_devices(devices.clone(), auth_info) | |
| 1287 | .await | |
| 1288 | .map(|_| ()) | |
| 1289 | } | |
| 1290 | }; | |
| 1291 | ||
| 1292 | match delete(None).await { | |
| 1283 | 1293 | Ok(_) => print_success(), |
| 1284 | 1294 | Err(e) => { |
| 1285 | 1295 | if let Some(info) = e.as_uiaa_response() { |
| @@ -1292,10 +1302,7 @@ impl InnerServer { | ||
| 1292 | 1302 | } |
| 1293 | 1303 | }; |
| 1294 | 1304 | |
| 1295 | if let Err(e) = c | |
| 1296 | .delete_devices(devices.clone(), Some(auth_info)) | |
| 1297 | .await | |
| 1298 | { | |
| 1305 | if let Err(e) = delete(Some(auth_info)).await { | |
| 1299 | 1306 | print_fail(e); |
| 1300 | 1307 | } else { |
| 1301 | 1308 | print_success(); |