| @@ -96,6 +96,15 @@ pub struct RoomHandle { |
| 96 | inner: MatrixRoom, |
96 | inner: MatrixRoom, |
| 97 | } |
97 | } |
| 98 | |
98 | |
| |
99 | pub(super) type SharedRoom = Rc<RefCell<Option<Room>>>; |
| |
100 | |
| |
101 | pub(super) fn active_room(room: &SharedRoom) -> Room { |
| |
102 | room.borrow() |
| |
103 | .as_ref() |
| |
104 | .expect("Matrix room was already shut down") |
| |
105 | .clone() |
| |
106 | } |
| |
107 | |
| 99 | #[derive(Debug, Clone, Eq, PartialEq)] |
108 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 100 | pub enum PrevBatch { |
109 | pub enum PrevBatch { |
| 101 | Forward(String), |
110 | Forward(String), |
| @@ -159,7 +168,7 @@ pub struct MatrixRoom { |
| 159 | homeserver: Rc<Url>, |
168 | homeserver: Rc<Url>, |
| 160 | room_id: Rc<RoomId>, |
169 | room_id: Rc<RoomId>, |
| 161 | own_user_id: Rc<UserId>, |
170 | own_user_id: Rc<UserId>, |
| 162 | room: Room, |
171 | room: SharedRoom, |
| 163 | buffer: RoomBuffer, |
172 | buffer: RoomBuffer, |
| 164 | |
173 | |
| 165 | config: Rc<RefCell<Config>>, |
174 | config: Rc<RefCell<Config>>, |
| @@ -315,6 +324,8 @@ impl RoomHandle { |
| 315 | room_id: &RoomId, |
324 | room_id: &RoomId, |
| 316 | own_user_id: &UserId, |
325 | own_user_id: &UserId, |
| 317 | ) -> Self { |
326 | ) -> Self { |
| |
327 | let room = Rc::new(RefCell::new(Some(room))); |
| |
328 | let sdk_room = active_room(&room); |
| 318 | let buffer = RoomBuffer::new(room.clone(), runtime.clone()); |
329 | let buffer = RoomBuffer::new(room.clone(), runtime.clone()); |
| 319 | let members = Members::new( |
330 | let members = Members::new( |
| 320 | room.clone(), |
331 | room.clone(), |
| @@ -324,7 +335,7 @@ impl RoomHandle { |
| 324 | ); |
335 | ); |
| 325 | |
336 | |
| 326 | let own_nick = runtime |
337 | let own_nick = runtime |
| 327 | .block_on(room.get_member_no_sync(own_user_id)) |
338 | .block_on(sdk_room.get_member_no_sync(own_user_id)) |
| 328 | .ok() |
339 | .ok() |
| 329 | .flatten() |
340 | .flatten() |
| 330 | .map(|m| m.name().to_owned()) |
341 | .map(|m| m.name().to_owned()) |
| @@ -343,7 +354,7 @@ impl RoomHandle { |
| 343 | connection: connection.clone(), |
354 | connection: connection.clone(), |
| 344 | config, |
355 | config, |
| 345 | prev_batch: Rc::new(RefCell::new( |
356 | prev_batch: Rc::new(RefCell::new( |
| 346 | room.last_prev_batch().map(PrevBatch::Backwards), |
357 | sdk_room.last_prev_batch().map(PrevBatch::Backwards), |
| 347 | )), |
358 | )), |
| 348 | latest_event_id: Rc::new(RefCell::new(None)), |
359 | latest_event_id: Rc::new(RefCell::new(None)), |
| 349 | latest_read_event_id: Rc::new(RefCell::new(None)), |
360 | latest_read_event_id: Rc::new(RefCell::new(None)), |
| @@ -511,10 +522,14 @@ impl MatrixRoom { |
| 511 | self.buffer.owns_buffer(buffer) |
522 | self.buffer.owns_buffer(buffer) |
| 512 | } |
523 | } |
| 513 | |
524 | |
| |
525 | pub fn release_sdk_state(&self) { |
| |
526 | self.room.borrow_mut().take(); |
| |
527 | } |
| |
528 | |
| 514 | pub fn is_encrypted(&self) -> bool { |
529 | pub fn is_encrypted(&self) -> bool { |
| 515 | self.members |
530 | self.members |
| 516 | .runtime |
531 | .runtime |
| 517 | .block_on(self.room.latest_encryption_state()) |
532 | .block_on(self.room().latest_encryption_state()) |
| 518 | .map(|s| s.is_encrypted()) |
533 | .map(|s| s.is_encrypted()) |
| 519 | .unwrap_or_default() |
534 | .unwrap_or_default() |
| 520 | } |
535 | } |
| @@ -522,23 +537,23 @@ impl MatrixRoom { |
| 522 | pub fn contains_only_verified_devices(&self) -> bool { |
537 | pub fn contains_only_verified_devices(&self) -> bool { |
| 523 | self.members |
538 | self.members |
| 524 | .runtime |
539 | .runtime |
| 525 | .block_on(self.room.contains_only_verified_devices()) |
540 | .block_on(self.room().contains_only_verified_devices()) |
| 526 | .unwrap_or_default() |
541 | .unwrap_or_default() |
| 527 | } |
542 | } |
| 528 | |
543 | |
| 529 | pub fn is_public(&self) -> bool { |
544 | pub fn is_public(&self) -> bool { |
| 530 | self.room.is_public().unwrap_or_default() |
545 | self.room().is_public().unwrap_or_default() |
| 531 | } |
546 | } |
| 532 | |
547 | |
| 533 | pub fn is_direct(&self) -> bool { |
548 | pub fn is_direct(&self) -> bool { |
| 534 | self.members |
549 | self.members |
| 535 | .runtime |
550 | .runtime |
| 536 | .block_on(self.room.is_direct()) |
551 | .block_on(self.room().is_direct()) |
| 537 | .unwrap_or_default() |
552 | .unwrap_or_default() |
| 538 | } |
553 | } |
| 539 | |
554 | |
| 540 | pub fn alias(&self) -> Option<OwnedRoomAliasId> { |
555 | pub fn alias(&self) -> Option<OwnedRoomAliasId> { |
| 541 | self.room.canonical_alias() |
556 | self.room().canonical_alias() |
| 542 | } |
557 | } |
| 543 | |
558 | |
| 544 | pub fn room_id(&self) -> &RoomId { |
559 | pub fn room_id(&self) -> &RoomId { |
| @@ -950,7 +965,7 @@ impl MatrixRoom { |
| 950 | self.queue_outgoing_message(&transaction_id, &content).await; |
965 | self.queue_outgoing_message(&transaction_id, &content).await; |
| 951 | match c |
966 | match c |
| 952 | .send_message( |
967 | .send_message( |
| 953 | self.room().clone(), |
968 | self.room(), |
| 954 | AnyMessageLikeEventContent::RoomMessage(content), |
969 | AnyMessageLikeEventContent::RoomMessage(content), |
| 955 | Some(transaction_id.clone()), |
970 | Some(transaction_id.clone()), |
| 956 | ) |
971 | ) |
| @@ -1087,7 +1102,7 @@ impl MatrixRoom { |
| 1087 | |
1102 | |
| 1088 | match connection |
1103 | match connection |
| 1089 | .spawn({ |
1104 | .spawn({ |
| 1090 | let room = self.room().clone(); |
1105 | let room = self.room(); |
| 1091 | async move { |
1106 | async move { |
| 1092 | room.send_attachment(filename, &content_type, data, config) |
1107 | room.send_attachment(filename, &content_type, data, config) |
| 1093 | .await |
1108 | .await |
| @@ -1133,7 +1148,7 @@ impl MatrixRoom { |
| 1133 | } |
1148 | } |
| 1134 | |
1149 | |
| 1135 | let connection = self.connection.clone(); |
1150 | let connection = self.connection.clone(); |
| 1136 | let room = self.room().clone(); |
1151 | let room = self.room(); |
| 1137 | |
1152 | |
| 1138 | let send = |typing: bool| async move { |
1153 | let send = |typing: bool| async move { |
| 1139 | let connection = connection.borrow().clone(); |
1154 | let connection = connection.borrow().clone(); |
| @@ -1249,7 +1264,7 @@ impl MatrixRoom { |
| 1249 | Weechat::bar_item_update("matrix_modes"); |
1264 | Weechat::bar_item_update("matrix_modes"); |
| 1250 | |
1265 | |
| 1251 | if let Some(connection) = connection { |
1266 | if let Some(connection) = connection { |
| 1252 | let room = self.room().clone(); |
1267 | let room = self.room(); |
| 1253 | let room_id = room.room_id().to_owned(); |
1268 | let room_id = room.room_id().to_owned(); |
| 1254 | |
1269 | |
| 1255 | if let Ok(r) = connection.room_messages(room, prev_batch).await { |
1270 | if let Ok(r) = connection.room_messages(room, prev_batch).await { |
| @@ -1488,7 +1503,7 @@ impl MatrixRoom { |
| 1488 | if let Ok(buffer) = self.buffer_handle().upgrade() { |
1503 | if let Ok(buffer) = self.buffer_handle().upgrade() { |
| 1489 | if buffer.num_lines() == 0 { |
1504 | if buffer.num_lines() == 0 { |
| 1490 | *self.prev_batch.borrow_mut() = |
1505 | *self.prev_batch.borrow_mut() = |
| 1491 | self.room.last_prev_batch().map(PrevBatch::Backwards); |
1506 | self.room().last_prev_batch().map(PrevBatch::Backwards); |
| 1492 | } |
1507 | } |
| 1493 | } |
1508 | } |
| 1494 | } |
1509 | } |
| @@ -1565,8 +1580,8 @@ impl MatrixRoom { |
| 1565 | } |
1580 | } |
| 1566 | } |
1581 | } |
| 1567 | |
1582 | |
| 1568 | pub fn room(&self) -> &Room { |
1583 | pub fn room(&self) -> Room { |
| 1569 | &self.room |
1584 | active_room(&self.room) |
| 1570 | } |
1585 | } |
| 1571 | |
1586 | |
| 1572 | pub async fn handle_sync_state_event( |
1587 | pub async fn handle_sync_state_event( |