diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index a692b6b6a27..f7dfccd7c75 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -620,7 +620,10 @@ impl BaseClient { /// decrypted event if we found one, along with its index in the /// latest_encrypted_events list, or None if we didn't find one. #[cfg(all(feature = "e2e-encryption", feature = "experimental-sliding-sync"))] - async fn decrypt_latest_suitable_event(&self, room: &Room) -> Option<(LatestEvent, usize)> { + async fn decrypt_latest_suitable_event( + &self, + room: &Room, + ) -> Option<(Box, usize)> { let enc_events = room.latest_encrypted_events(); // Walk backwards through the encrypted events, looking for one we can decrypt @@ -633,7 +636,7 @@ impl BaseClient { is_suitable_for_latest_event(&any_sync_event) { // The event is the right type for us to use as latest_event - return Some((LatestEvent::new(decrypted), i)); + return Some((Box::new(LatestEvent::new(decrypted)), i)); } } } diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index cc2aef31c06..b6d20592a89 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -403,12 +403,12 @@ impl Room { /// sliding sync. #[cfg(feature = "experimental-sliding-sync")] pub fn latest_event(&self) -> Option { - self.inner.read().latest_event.clone() + self.inner.read().latest_event.as_deref().cloned() } /// Update the last event in the room #[cfg(all(feature = "e2e-encryption", feature = "experimental-sliding-sync"))] - pub(crate) fn set_latest_event(&self, latest_event: Option) { + pub(crate) fn set_latest_event(&self, latest_event: Option>) { self.inner.update(|info| info.latest_event = latest_event); } @@ -429,7 +429,7 @@ impl Room { /// Panics if index is not a valid index in the latest_encrypted_events /// list. #[cfg(all(feature = "e2e-encryption", feature = "experimental-sliding-sync"))] - pub(crate) fn on_latest_event_decrypted(&self, latest_event: LatestEvent, index: usize) { + pub(crate) fn on_latest_event_decrypted(&self, latest_event: Box, index: usize) { self.set_latest_event(Some(latest_event)); self.latest_encrypted_events.write().unwrap().drain(0..=index); } @@ -732,10 +732,10 @@ pub struct RoomInfo { pub(crate) encryption_state_synced: bool, /// The last event send by sliding sync #[cfg(feature = "experimental-sliding-sync")] - pub(crate) latest_event: Option, + pub(crate) latest_event: Option>, /// Base room info which holds some basic event contents important for the /// room state. - pub(crate) base_info: BaseRoomInfo, + pub(crate) base_info: Box, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] @@ -769,7 +769,7 @@ impl RoomInfo { encryption_state_synced: false, #[cfg(feature = "experimental-sliding-sync")] latest_event: None, - base_info: BaseRoomInfo::new(), + base_info: Box::new(BaseRoomInfo::new()), } } @@ -1246,10 +1246,10 @@ mod tests { last_prev_batch: Some("pb".to_owned()), sync_info: SyncInfo::FullySynced, encryption_state_synced: true, - latest_event: Some(LatestEvent::new( + latest_event: Some(Box::new(LatestEvent::new( Raw::from_json_string(json!({"sender": "@u:i.uk"}).to_string()).unwrap().into(), - )), - base_info: BaseRoomInfo::new(), + ))), + base_info: Box::new(BaseRoomInfo::new()), }; let info_json = json!({ @@ -1698,10 +1698,10 @@ mod tests { } #[cfg(feature = "experimental-sliding-sync")] - fn make_latest_event(event_id: &str) -> LatestEvent { - LatestEvent::new(SyncTimelineEvent::new( + fn make_latest_event(event_id: &str) -> Box { + Box::new(LatestEvent::new(SyncTimelineEvent::new( Raw::from_json_string(json!({ "event_id": event_id }).to_string()).unwrap(), - )) + ))) } fn timestamp(minutes_ago: u32) -> MilliSecondsSinceUnixEpoch { diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 5df9aedaea0..1887b494a1f 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -524,11 +524,11 @@ async fn cache_latest_events( } } - let latest_event = LatestEvent::new_with_sender_details( + let latest_event = Box::new(LatestEvent::new_with_sender_details( event.clone(), sender_profile, sender_name_is_ambiguous, - ); + )); // Store it in the return RoomInfo, and in the Room, to make sure they are // consistent diff --git a/crates/matrix-sdk-base/src/store/migration_helpers.rs b/crates/matrix-sdk-base/src/store/migration_helpers.rs index f04e4179025..58134876c7e 100644 --- a/crates/matrix-sdk-base/src/store/migration_helpers.rs +++ b/crates/matrix-sdk-base/src/store/migration_helpers.rs @@ -117,7 +117,7 @@ impl RoomInfoV1 { sync_info, encryption_state_synced, #[cfg(feature = "experimental-sliding-sync")] - latest_event: latest_event.map(LatestEvent::new), + latest_event: latest_event.map(|ev| Box::new(LatestEvent::new(ev))), base_info: base_info.migrate(create), } } @@ -157,7 +157,10 @@ struct BaseRoomInfoV1 { impl BaseRoomInfoV1 { /// Migrate this to a [`BaseRoomInfo`]. - fn migrate(self, create: Option<&SyncOrStrippedState>) -> BaseRoomInfo { + fn migrate( + self, + create: Option<&SyncOrStrippedState>, + ) -> Box { let BaseRoomInfoV1 { avatar, canonical_alias, @@ -186,7 +189,7 @@ impl BaseRoomInfoV1 { MinimalStateEvent::Redacted(ev) => MinimalStateEvent::Redacted(ev), }); - BaseRoomInfo { + Box::new(BaseRoomInfo { avatar, canonical_alias, create, @@ -200,7 +203,7 @@ impl BaseRoomInfoV1 { tombstone, topic, rtc_member: BTreeMap::new(), - } + }) } }