Commit 7ab8c45309
Unsigned
Layout: unified · split
src/room/mod.rs +231 −17
| @@ -77,6 +77,7 @@ use matrix_sdk::{ | ||
| 77 | 77 | RoomMessageEventContent, TextMessageEventContent, |
| 78 | 78 | }, |
| 79 | 79 | redaction::SyncRoomRedactionEvent, |
| 80 | tombstone::RoomTombstoneEventContent, | |
| 80 | 81 | }, |
| 81 | 82 | AnyMessageLikeEventContent, AnySyncMessageLikeEvent, |
| 82 | 83 | AnySyncStateEvent, AnySyncTimelineEvent, AnyTimelineEvent, |
| @@ -163,6 +164,61 @@ fn has_history_page(prev_batch: &Option<PrevBatch>) -> bool { | ||
| 163 | 164 | prev_batch.is_some() |
| 164 | 165 | } |
| 165 | 166 | |
| 167 | fn tombstone_replacement_room_id( | |
| 168 | event: &SyncStateEvent<RoomTombstoneEventContent>, | |
| 169 | ) -> Option<OwnedRoomId> { | |
| 170 | event | |
| 171 | .as_original() | |
| 172 | .map(|event| event.content.replacement_room.clone()) | |
| 173 | } | |
| 174 | ||
| 175 | fn build_room_buffer( | |
| 176 | buffer_name: &str, | |
| 177 | room: MatrixRoom, | |
| 178 | ) -> Result<BufferHandle, ()> { | |
| 179 | BufferBuilderAsync::new(buffer_name) | |
| 180 | .input_callback(room) | |
| 181 | .close_callback(|_weechat: &Weechat, _buffer: &Buffer| { | |
| 182 | // TODO: remove the roombuffer from the server here. | |
| 183 | // TODO: leave the room if the plugin isn't unloading. | |
| 184 | Ok(()) | |
| 185 | }) | |
| 186 | .build() | |
| 187 | } | |
| 188 | ||
| 189 | fn retire_stale_matrix_buffer(buffer_name: &str, room_id: &RoomId) -> bool { | |
| 190 | let Some(buffer) = | |
| 191 | (unsafe { Weechat::weechat() }).buffer_search("==", buffer_name) | |
| 192 | else { | |
| 193 | return false; | |
| 194 | }; | |
| 195 | ||
| 196 | let Some(existing_room_id) = buffer.get_localvar("room_id") else { | |
| 197 | return false; | |
| 198 | }; | |
| 199 | ||
| 200 | if existing_room_id.as_ref() == room_id.as_str() { | |
| 201 | return false; | |
| 202 | } | |
| 203 | ||
| 204 | let suffix = existing_room_id | |
| 205 | .chars() | |
| 206 | .filter(|character| character.is_ascii_alphanumeric()) | |
| 207 | .take(12) | |
| 208 | .collect::<String>(); | |
| 209 | let stale_name = if suffix.is_empty() { | |
| 210 | format!("{buffer_name}.stale") | |
| 211 | } else { | |
| 212 | format!("{buffer_name}.stale.{suffix}") | |
| 213 | }; | |
| 214 | ||
| 215 | buffer.set_full_name(&stale_name); | |
| 216 | buffer.set_short_name(&format!("stale.{}", buffer.short_name())); | |
| 217 | buffer.close(); | |
| 218 | ||
| 219 | true | |
| 220 | } | |
| 221 | ||
| 166 | 222 | fn history_page_marker(result: &HistoryPageResult) -> String { |
| 167 | 223 | match result { |
| 168 | 224 | HistoryPageResult::Page { added, exhausted } => format!( |
| @@ -657,16 +713,17 @@ impl RoomHandle { | ||
| 657 | 713 | server, |
| 658 | 714 | }; |
| 659 | 715 | |
| 660 | let buffer_name = format!("{}.{}", server_name, room_id); | |
| 716 | let room_short_name = room.buffer.calculate_buffer_name(); | |
| 717 | let buffer_name = format!("{server_name}.{room_short_name}"); | |
| 661 | 718 | |
| 662 | let buffer_handle = BufferBuilderAsync::new(&buffer_name) | |
| 663 | .input_callback(room.clone()) | |
| 664 | .close_callback(|_weechat: &Weechat, _buffer: &Buffer| { | |
| 665 | // TODO: remove the roombuffer from the server here. | |
| 666 | // TODO: leave the room if the plugin isn't unloading. | |
| 667 | Ok(()) | |
| 719 | let buffer_handle = build_room_buffer(&buffer_name, room.clone()) | |
| 720 | .or_else(|_| { | |
| 721 | if retire_stale_matrix_buffer(&buffer_name, room_id) { | |
| 722 | build_room_buffer(&buffer_name, room.clone()) | |
| 723 | } else { | |
| 724 | Err(()) | |
| 725 | } | |
| 668 | 726 | }) |
| 669 | .build() | |
| 670 | 727 | .expect("Can't create new room buffer"); |
| 671 | 728 | |
| 672 | 729 | let buffer = buffer_handle |
| @@ -674,6 +731,10 @@ impl RoomHandle { | ||
| 674 | 731 | .expect("Can't upgrade newly created buffer"); |
| 675 | 732 | buffer.set_short_name(&room.buffer.calculate_buffer_name()); |
| 676 | 733 | |
| 734 | if buffer.short_name() != room_short_name { | |
| 735 | buffer.set_short_name(&room_short_name); | |
| 736 | } | |
| 737 | ||
| 677 | 738 | buffer |
| 678 | 739 | .add_nicklist_group( |
| 679 | 740 | "000|o", |
| @@ -771,6 +832,14 @@ impl RoomHandle { | ||
| 771 | 832 | room.buffer.refresh_space_children(); |
| 772 | 833 | } |
| 773 | 834 | |
| 835 | if let Some(successor) = sdk_room.successor_room() { | |
| 836 | let room = room.clone(); | |
| 837 | Weechat::spawn(async move { | |
| 838 | room.follow_successor_room(successor.room_id).await | |
| 839 | }) | |
| 840 | .detach(); | |
| 841 | } | |
| 842 | ||
| 774 | 843 | Self { inner: room } |
| 775 | 844 | } |
| 776 | 845 | |
| @@ -972,6 +1041,46 @@ impl MatrixRoom { | ||
| 972 | 1041 | } |
| 973 | 1042 | } |
| 974 | 1043 | |
| 1044 | async fn follow_successor_room(&self, room_id: OwnedRoomId) { | |
| 1045 | let Some(connection) = self.connection.borrow().clone() else { | |
| 1046 | self.print_error(&format!( | |
| 1047 | "Room was upgraded to {room_id}, but Matrix is not connected." | |
| 1048 | )); | |
| 1049 | return; | |
| 1050 | }; | |
| 1051 | ||
| 1052 | if connection.client().get_room(&room_id).is_some() { | |
| 1053 | return; | |
| 1054 | } | |
| 1055 | ||
| 1056 | self.print_network(&format!("Following room upgrade to {room_id}...")); | |
| 1057 | ||
| 1058 | let client = connection.client().clone(); | |
| 1059 | let target = room_id.clone(); | |
| 1060 | let result = connection | |
| 1061 | .spawn(async move { | |
| 1062 | tokio::time::timeout(SPACE_JOIN_TIMEOUT, async move { | |
| 1063 | client.join_room_by_id(&target).await | |
| 1064 | }) | |
| 1065 | .await | |
| 1066 | }) | |
| 1067 | .await; | |
| 1068 | ||
| 1069 | match result { | |
| 1070 | Ok(Ok(room)) => self.print_network(&format!( | |
| 1071 | "Successfully joined upgraded room {}", | |
| 1072 | room.room_id() | |
| 1073 | )), | |
| 1074 | Ok(Err(error)) => self.print_error(&format!( | |
| 1075 | "Failed to join upgraded room {room_id}: {error}" | |
| 1076 | )), | |
| 1077 | Err(error) => self.print_error(&format!( | |
| 1078 | "Timed out joining upgraded room {room_id} after {} seconds: {error}", | |
| 1079 | SPACE_JOIN_TIMEOUT.as_secs() | |
| 1080 | )), | |
| 1081 | } | |
| 1082 | } | |
| 1083 | ||
| 975 | 1084 | pub fn owns_buffer(&self, buffer: &Buffer) -> bool { |
| 976 | 1085 | self.buffer.owns_buffer(buffer) |
| 977 | 1086 | } |
| @@ -1827,13 +1936,14 @@ impl MatrixRoom { | ||
| 1827 | 1936 | let Some(source_root) = |
| 1828 | 1937 | thread_root_from_content(&content).map(ToOwned::to_owned) |
| 1829 | 1938 | else { |
| 1830 | if let Err(error) = self.send_message_direct(content).await { | |
| 1939 | let room = self.latest_send_room().await; | |
| 1940 | if let Err(error) = self.send_message_direct(room, content).await { | |
| 1831 | 1941 | self.print_error(&error); |
| 1832 | 1942 | } |
| 1833 | 1943 | return; |
| 1834 | 1944 | }; |
| 1835 | 1945 | let Some(server) = self.server() else { |
| 1836 | if let Err(error) = self.send_message_direct(content).await { | |
| 1946 | if let Err(error) = self.send_message_direct(self.room(), content).await { | |
| 1837 | 1947 | self.print_error(&error); |
| 1838 | 1948 | } |
| 1839 | 1949 | return; |
| @@ -1864,7 +1974,7 @@ impl MatrixRoom { | ||
| 1864 | 1974 | self.adopt_thread_buffer(&source_root, &room, &thread_root); |
| 1865 | 1975 | retarget_thread_content(&mut content, thread_root); |
| 1866 | 1976 | } |
| 1867 | if let Err(error) = room.send_message_direct(content).await { | |
| 1977 | if let Err(error) = room.send_message_direct(room.room(), content).await { | |
| 1868 | 1978 | self.print_error(&error); |
| 1869 | 1979 | } |
| 1870 | 1980 | } |
| @@ -1885,7 +1995,7 @@ impl MatrixRoom { | ||
| 1885 | 1995 | // before sending, but the homeserver event and local mapping |
| 1886 | 1996 | // cannot be committed atomically without persisting the full |
| 1887 | 1997 | // arbitrary user payload as a recovery journal. |
| 1888 | match room.send_message_direct(content).await { | |
| 1998 | match room.send_message_direct(room.room(), content).await { | |
| 1889 | 1999 | Ok(target_root) => { |
| 1890 | 2000 | let target_key = |
| 1891 | 2001 | ThreadKey::new(room.room_id(), &target_root); |
| @@ -1911,8 +2021,80 @@ impl MatrixRoom { | ||
| 1911 | 2021 | } |
| 1912 | 2022 | } |
| 1913 | 2023 | |
| 2024 | async fn latest_send_room(&self) -> Room { | |
| 2025 | let mut room = self.room(); | |
| 2026 | let mut seen_room_ids = HashSet::new(); | |
| 2027 | ||
| 2028 | for _ in 0..32 { | |
| 2029 | if !seen_room_ids.insert(room.room_id().to_owned()) { | |
| 2030 | self.print_error(&format!( | |
| 2031 | "Room upgrade cycle detected at {}.", | |
| 2032 | room.room_id() | |
| 2033 | )); | |
| 2034 | return room; | |
| 2035 | } | |
| 2036 | ||
| 2037 | let Some(successor_room_id) = | |
| 2038 | room.successor_room().map(|successor| successor.room_id) | |
| 2039 | else { | |
| 2040 | return room; | |
| 2041 | }; | |
| 2042 | ||
| 2043 | let Some(connection) = self.connection.borrow().clone() else { | |
| 2044 | self.print_error(&format!( | |
| 2045 | "Room was upgraded to {successor_room_id}, but Matrix is not connected." | |
| 2046 | )); | |
| 2047 | return room; | |
| 2048 | }; | |
| 2049 | ||
| 2050 | if let Some(successor_room) = | |
| 2051 | connection.client().get_room(&successor_room_id) | |
| 2052 | { | |
| 2053 | room = successor_room; | |
| 2054 | continue; | |
| 2055 | } | |
| 2056 | ||
| 2057 | self.print_network(&format!( | |
| 2058 | "Following room upgrade to {successor_room_id}..." | |
| 2059 | )); | |
| 2060 | ||
| 2061 | let client = connection.client().clone(); | |
| 2062 | let target = successor_room_id.clone(); | |
| 2063 | match connection | |
| 2064 | .spawn(async move { | |
| 2065 | tokio::time::timeout(SPACE_JOIN_TIMEOUT, async move { | |
| 2066 | client.join_room_by_id(&target).await | |
| 2067 | }) | |
| 2068 | .await | |
| 2069 | }) | |
| 2070 | .await | |
| 2071 | { | |
| 2072 | Ok(Ok(successor_room)) => room = successor_room, | |
| 2073 | Ok(Err(error)) => { | |
| 2074 | self.print_error(&format!( | |
| 2075 | "Failed to join upgraded room {successor_room_id}: {error}" | |
| 2076 | )); | |
| 2077 | return room; | |
| 2078 | } | |
| 2079 | Err(error) => { | |
| 2080 | self.print_error(&format!( | |
| 2081 | "Timed out joining upgraded room {successor_room_id} after {} seconds: {error}", | |
| 2082 | SPACE_JOIN_TIMEOUT.as_secs() | |
| 2083 | )); | |
| 2084 | return room; | |
| 2085 | } | |
| 2086 | } | |
| 2087 | } | |
| 2088 | ||
| 2089 | self.print_error("Room upgrade chain exceeded 32 rooms."); | |
| 2090 | room | |
| 2091 | } | |
| 2092 | ||
| 2093 | // Thread continuation already resolved its room and root together. Do not | |
| 2094 | // independently follow room upgrades after that routing decision. | |
| 1914 | 2095 | async fn send_message_direct( |
| 1915 | 2096 | &self, |
| 2097 | room: Room, | |
| 1916 | 2098 | content: RoomMessageEventContent, |
| 1917 | 2099 | ) -> Result<OwnedEventId, String> { |
| 1918 | 2100 | let transaction_id = TransactionId::new(); |
| @@ -1923,7 +2105,7 @@ impl MatrixRoom { | ||
| 1923 | 2105 | self.queue_outgoing_message(&transaction_id, &content).await; |
| 1924 | 2106 | match c |
| 1925 | 2107 | .send_message( |
| 1926 | self.room(), | |
| 2108 | room, | |
| 1927 | 2109 | AnyMessageLikeEventContent::RoomMessage(content), |
| 1928 | 2110 | Some(transaction_id.clone()), |
| 1929 | 2111 | ) |
| @@ -3194,17 +3376,21 @@ impl MatrixRoom { | ||
| 3194 | 3376 | self.buffer.set_alias(); |
| 3195 | 3377 | self.buffer.update_buffer_name(); |
| 3196 | 3378 | } |
| 3197 | AnySyncStateEvent::RoomTombstone(_) => { | |
| 3379 | AnySyncStateEvent::RoomTombstone(tombstone) => { | |
| 3380 | let replacement_room_id = | |
| 3381 | tombstone_replacement_room_id(tombstone); | |
| 3198 | 3382 | if let Ok(buffer) = self.buffer.buffer_handle().upgrade() { |
| 3199 | 3383 | buffer.set_localvar( |
| 3200 | 3384 | "matrix_replacement_room_id", |
| 3201 | self.room() | |
| 3202 | .successor_room() | |
| 3385 | replacement_room_id | |
| 3203 | 3386 | .as_ref() |
| 3204 | .map(|successor| successor.room_id.as_str()) | |
| 3387 | .map(|room_id| room_id.as_str()) | |
| 3205 | 3388 | .unwrap_or_default(), |
| 3206 | 3389 | ); |
| 3207 | 3390 | } |
| 3391 | if let Some(room_id) = replacement_room_id { | |
| 3392 | self.follow_successor_room(room_id).await; | |
| 3393 | } | |
| 3208 | 3394 | } |
| 3209 | 3395 | AnySyncStateEvent::SpaceParent(_) => { |
| 3210 | 3396 | self.buffer.update_parent_spaces() |
| @@ -3270,6 +3456,34 @@ mod tests { | ||
| 3270 | 3456 | assert_eq!(restored_prev_batch(None), Some(PrevBatch::Backwards(None))); |
| 3271 | 3457 | } |
| 3272 | 3458 | |
| 3459 | #[test] | |
| 3460 | fn tombstone_state_event_exposes_replacement_room_id() { | |
| 3461 | let event: AnySyncStateEvent = | |
| 3462 | serde_json::from_value(serde_json::json!({ | |
| 3463 | "type": "m.room.tombstone", | |
| 3464 | "event_id": "$tombstone:example.org", | |
| 3465 | "sender": "@alice:example.org", | |
| 3466 | "origin_server_ts": 1, | |
| 3467 | "state_key": "", | |
| 3468 | "content": { | |
| 3469 | "body": "This room has been replaced.", | |
| 3470 | "replacement_room": "!new:example.org" | |
| 3471 | } | |
| 3472 | })) | |
| 3473 | .expect("valid tombstone event"); | |
| 3474 | ||
| 3475 | let AnySyncStateEvent::RoomTombstone(tombstone) = event else { | |
| 3476 | panic!("expected tombstone event"); | |
| 3477 | }; | |
| 3478 | ||
| 3479 | assert_eq!( | |
| 3480 | tombstone_replacement_room_id(&tombstone) | |
| 3481 | .as_deref() | |
| 3482 | .map(RoomId::as_str), | |
| 3483 | Some("!new:example.org") | |
| 3484 | ); | |
| 3485 | } | |
| 3486 | ||
| 3273 | 3487 | #[test] |
| 3274 | 3488 | fn history_paging_requires_an_available_cursor() { |
| 3275 | 3489 | assert!(!has_history_page(&None)); |
src/server.rs +141 −1
| @@ -80,7 +80,10 @@ use matrix_sdk::{ | ||
| 80 | 80 | }, |
| 81 | 81 | api::error::ErrorKind, |
| 82 | 82 | events::{ |
| 83 | room::{member::RoomMemberEventContent, MediaSource}, | |
| 83 | room::{ | |
| 84 | member::RoomMemberEventContent, | |
| 85 | tombstone::RoomTombstoneEventContent, MediaSource, | |
| 86 | }, | |
| 84 | 87 | AnySyncStateEvent, AnySyncTimelineEvent, AnyToDeviceEvent, |
| 85 | 88 | SyncStateEvent, |
| 86 | 89 | }, |
| @@ -98,6 +101,7 @@ use weechat::{ | ||
| 98 | 101 | }; |
| 99 | 102 | |
| 100 | 103 | const JOIN_ROOM_TIMEOUT: Duration = Duration::from_secs(120); |
| 104 | const ROOM_UPGRADE_CHAIN_LIMIT: usize = 32; | |
| 101 | 105 | |
| 102 | 106 | use crate::{ |
| 103 | 107 | config::ServerBuffer, |
| @@ -118,6 +122,14 @@ fn secure_set_token_command(name: &str, token: &str) -> Option<String> { | ||
| 118 | 122 | safe.then(|| format!("/secure set {name} {token}")) |
| 119 | 123 | } |
| 120 | 124 | |
| 125 | fn tombstone_replacement_room_id( | |
| 126 | event: &SyncStateEvent<RoomTombstoneEventContent>, | |
| 127 | ) -> Option<OwnedRoomId> { | |
| 128 | event | |
| 129 | .as_original() | |
| 130 | .map(|event| event.content.replacement_room.clone()) | |
| 131 | } | |
| 132 | ||
| 121 | 133 | fn with_entered_runtime_until_final_drop<F>( |
| 122 | 134 | runtime: Rc<tokio::runtime::Runtime>, |
| 123 | 135 | f: F, |
| @@ -1116,6 +1128,123 @@ impl InnerServer { | ||
| 1116 | 1128 | self.restore_room(room).await; |
| 1117 | 1129 | } |
| 1118 | 1130 | |
| 1131 | fn room_buffer_is_current(room: &RoomHandle) -> bool { | |
| 1132 | room.buffer_handle() | |
| 1133 | .upgrade() | |
| 1134 | .map(|buffer| { | |
| 1135 | // Sync callbacks run on WeeChat's main thread, so the global | |
| 1136 | // context is valid for this immediate buffer comparison. | |
| 1137 | buffer == unsafe { Weechat::weechat() }.current_buffer() | |
| 1138 | }) | |
| 1139 | .unwrap_or(false) | |
| 1140 | } | |
| 1141 | ||
| 1142 | async fn successor_room_handle( | |
| 1143 | &self, | |
| 1144 | room_id: OwnedRoomId, | |
| 1145 | ) -> Option<RoomHandle> { | |
| 1146 | if let Some(room) = self.rooms.borrow().get(&room_id).cloned() { | |
| 1147 | return Some(room); | |
| 1148 | } | |
| 1149 | ||
| 1150 | let client_room = if let Some(room) = self | |
| 1151 | .get_client() | |
| 1152 | .and_then(|client| client.get_room(&room_id)) | |
| 1153 | { | |
| 1154 | Some(room) | |
| 1155 | } else { | |
| 1156 | let Some(connection) = self.connection() else { | |
| 1157 | self.print_error(&format!( | |
| 1158 | "Room was upgraded to {room_id}, but Matrix is not connected." | |
| 1159 | )); | |
| 1160 | return None; | |
| 1161 | }; | |
| 1162 | let client = connection.client().clone(); | |
| 1163 | let target = room_id.clone(); | |
| 1164 | match connection | |
| 1165 | .spawn(async move { | |
| 1166 | tokio::time::timeout(JOIN_ROOM_TIMEOUT, async move { | |
| 1167 | client.join_room_by_id(&target).await | |
| 1168 | }) | |
| 1169 | .await | |
| 1170 | }) | |
| 1171 | .await | |
| 1172 | { | |
| 1173 | Ok(Ok(room)) => Some(room), | |
| 1174 | Ok(Err(error)) => { | |
| 1175 | self.print_error(&format!( | |
| 1176 | "Failed to join upgraded room {room_id}: {error}" | |
| 1177 | )); | |
| 1178 | None | |
| 1179 | } | |
| 1180 | Err(error) => { | |
| 1181 | self.print_error(&format!( | |
| 1182 | "Timed out joining upgraded room {room_id} after {} seconds: {error}", | |
| 1183 | JOIN_ROOM_TIMEOUT.as_secs() | |
| 1184 | )); | |
| 1185 | None | |
| 1186 | } | |
| 1187 | } | |
| 1188 | }; | |
| 1189 | ||
| 1190 | if let Some(room) = client_room { | |
| 1191 | self.restore_room(room).await; | |
| 1192 | } | |
| 1193 | ||
| 1194 | self.rooms.borrow().get(&room_id).cloned() | |
| 1195 | } | |
| 1196 | ||
| 1197 | async fn latest_successor_room_handle( | |
| 1198 | &self, | |
| 1199 | room_id: OwnedRoomId, | |
| 1200 | ) -> Option<RoomHandle> { | |
| 1201 | let mut next_room_id = room_id; | |
| 1202 | let mut seen_room_ids = HashSet::new(); | |
| 1203 | ||
| 1204 | for _ in 0..ROOM_UPGRADE_CHAIN_LIMIT { | |
| 1205 | if !seen_room_ids.insert(next_room_id.clone()) { | |
| 1206 | self.print_error(&format!( | |
| 1207 | "Room upgrade cycle detected at {next_room_id}." | |
| 1208 | )); | |
| 1209 | return None; | |
| 1210 | } | |
| 1211 | ||
| 1212 | let room = self.successor_room_handle(next_room_id).await?; | |
| 1213 | let Some(successor_room_id) = room | |
| 1214 | .room() | |
| 1215 | .successor_room() | |
| 1216 | .map(|successor| successor.room_id) | |
| 1217 | else { | |
| 1218 | return Some(room); | |
| 1219 | }; | |
| 1220 | next_room_id = successor_room_id; | |
| 1221 | } | |
| 1222 | ||
| 1223 | self.print_error(&format!( | |
| 1224 | "Room upgrade chain exceeded {ROOM_UPGRADE_CHAIN_LIMIT} rooms." | |
| 1225 | )); | |
| 1226 | None | |
| 1227 | } | |
| 1228 | ||
| 1229 | async fn switch_current_room_to_successor( | |
| 1230 | &self, | |
| 1231 | current_room: &RoomHandle, | |
| 1232 | successor_room_id: OwnedRoomId, | |
| 1233 | ) { | |
| 1234 | if !Self::room_buffer_is_current(current_room) { | |
| 1235 | return; | |
| 1236 | } | |
| 1237 | ||
| 1238 | let Some(successor) = | |
| 1239 | self.latest_successor_room_handle(successor_room_id).await | |
| 1240 | else { | |
| 1241 | return; | |
| 1242 | }; | |
| 1243 | if let Ok(buffer) = successor.buffer_handle().upgrade() { | |
| 1244 | buffer.switch_to(); | |
| 1245 | } | |
| 1246 | } | |
| 1247 | ||
| 1119 | 1248 | pub async fn restore_room(&self, room: Room) { |
| 1120 | 1249 | let homeserver = self |
| 1121 | 1250 | .settings |
| @@ -1522,9 +1651,20 @@ impl InnerServer { | ||
| 1522 | 1651 | ) { |
| 1523 | 1652 | let refresh_parent_spaces = |
| 1524 | 1653 | matches!(&event, AnySyncStateEvent::RoomName(_)); |
| 1654 | let successor_room_id = match &event { | |
| 1655 | AnySyncStateEvent::RoomTombstone(tombstone) => { | |
| 1656 | tombstone_replacement_room_id(tombstone) | |
| 1657 | } | |
| 1658 | _ => None, | |
| 1659 | }; | |
| 1525 | 1660 | let room = self.get_or_create_room(room_id); |
| 1526 | 1661 | room.handle_sync_state_event(&event, true).await; |
| 1527 | 1662 | |
| 1663 | if let Some(successor_room_id) = successor_room_id { | |
| 1664 | self.switch_current_room_to_successor(&room, successor_room_id) | |
| 1665 | .await; | |
| 1666 | } | |
| 1667 | ||
| 1528 | 1668 | if refresh_parent_spaces { |
| 1529 | 1669 | for room in self.rooms() { |
| 1530 | 1670 | room.update_parent_spaces(); |