Commit 9c97b478a8
Unsigned
Layout: unified · split
src/connection.rs +15
| @@ -235,6 +235,21 @@ impl Connection { | ||
| 235 | 235 | .map_err(|error| error.to_string()) |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | /// Bound upgrade joins while polling both the timer and SDK on Tokio. | |
| 239 | pub async fn join_room_with_timeout( | |
| 240 | &self, | |
| 241 | room_id: OwnedRoomId, | |
| 242 | timeout: std::time::Duration, | |
| 243 | ) -> Result<Result<Room, matrix_sdk::Error>, tokio::time::error::Elapsed> | |
| 244 | { | |
| 245 | let client = self.client().clone(); | |
| 246 | self.spawn(async move { | |
| 247 | tokio::time::timeout(timeout, client.join_room_by_id(&room_id)) | |
| 248 | .await | |
| 249 | }) | |
| 250 | .await | |
| 251 | } | |
| 252 | ||
| 238 | 253 | pub fn shutdown(&self) { |
| 239 | 254 | let runtime = self.runtime(); |
| 240 | 255 | |
src/room/mod.rs +8 −20
| @@ -57,9 +57,8 @@ use matrix_sdk::{ | ||
| 57 | 57 | }, |
| 58 | 58 | deserialized_responses::AmbiguityChange, |
| 59 | 59 | room::{ |
| 60 | IncludeRelations, RelationsOptions, | |
| 61 | 60 | reply::{EnforceThread, Reply}, |
| 62 | Room, | |
| 61 | IncludeRelations, RelationsOptions, Room, | |
| 63 | 62 | }, |
| 64 | 63 | ruma::{ |
| 65 | 64 | api::Direction, |
| @@ -727,14 +726,14 @@ impl RoomHandle { | ||
| 727 | 726 | |
| 728 | 727 | let buffer_handle = build_room_buffer(&buffer_name, room.clone()) |
| 729 | 728 | .or_else(|_| { |
| 730 | if retire_stale_matrix_buffer(&buffer_name, room_id) { | |
| 729 | if retire_stale_matrix_buffer(&buffer_name, &room_id) { | |
| 731 | 730 | build_room_buffer(&buffer_name, room.clone()) |
| 732 | 731 | } else { |
| 733 | 732 | Err(()) |
| 734 | 733 | } |
| 735 | 734 | }) |
| 736 | 735 | .or_else(|_| { |
| 737 | let suffix = room_id_buffer_suffix(room_id); | |
| 736 | let suffix = room_id_buffer_suffix(&room_id); | |
| 738 | 737 | let fallback_name = if suffix.is_empty() { |
| 739 | 738 | format!("{buffer_name}.room") |
| 740 | 739 | } else { |
| @@ -1084,15 +1083,8 @@ impl MatrixRoom { | ||
| 1084 | 1083 | |
| 1085 | 1084 | self.print_network(&format!("Following room upgrade to {room_id}...")); |
| 1086 | 1085 | |
| 1087 | let client = connection.client().clone(); | |
| 1088 | let target = room_id.clone(); | |
| 1089 | 1086 | let result = connection |
| 1090 | .spawn(async move { | |
| 1091 | tokio::time::timeout(SPACE_JOIN_TIMEOUT, async move { | |
| 1092 | client.join_room_by_id(&target).await | |
| 1093 | }) | |
| 1094 | .await | |
| 1095 | }) | |
| 1087 | .join_room_with_timeout(room_id.clone(), SPACE_JOIN_TIMEOUT) | |
| 1096 | 1088 | .await; |
| 1097 | 1089 | |
| 1098 | 1090 | match result { |
| @@ -2113,15 +2105,11 @@ impl MatrixRoom { | ||
| 2113 | 2105 | "Following room upgrade to {successor_room_id}..." |
| 2114 | 2106 | )); |
| 2115 | 2107 | |
| 2116 | let client = connection.client().clone(); | |
| 2117 | let target = successor_room_id.clone(); | |
| 2118 | 2108 | match connection |
| 2119 | .spawn(async move { | |
| 2120 | tokio::time::timeout(SPACE_JOIN_TIMEOUT, async move { | |
| 2121 | client.join_room_by_id(&target).await | |
| 2122 | }) | |
| 2123 | .await | |
| 2124 | }) | |
| 2109 | .join_room_with_timeout( | |
| 2110 | successor_room_id.clone(), | |
| 2111 | SPACE_JOIN_TIMEOUT, | |
| 2112 | ) | |
| 2125 | 2113 | .await |
| 2126 | 2114 | { |
| 2127 | 2115 | Ok(Ok(successor_room)) => room = successor_room, |