From 01a36c90c3248c092a148a2ee58f4b33f2ec1a9c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 13 Jun 2024 12:11:45 +0200 Subject: [PATCH] chore(ffi): Remove `RoomInfo::latest_event`. This patch removes `RoomInfo::latest_event`. To get the latest event, one has to use `RoomListItem::latest_event` because it supports local events and remote events. It was supposed to be the case of `Room::room_info` too, but only when the method was called: Once the `RoomInfo` was created, the latest event inside `RoomInfo` was static, not dynamic. Also, this code wasn't tested contrary to `RoomListItem::latest_event` which uses `matrix_sdk_ui::room_list_service::Room::latest_event` which is itself tested. --- bindings/matrix-sdk-ffi/src/room.rs | 35 ++---------------------- bindings/matrix-sdk-ffi/src/room_info.rs | 10 ++----- bindings/matrix-sdk-ffi/src/room_list.rs | 4 +-- 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index 90a4531ed..b946ab515 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -32,7 +32,7 @@ use crate::{ room_info::RoomInfo, room_member::RoomMember, ruma::{ImageInfo, Mentions, NotifyType}, - timeline::{EventTimelineItem, FocusEventError, ReceiptType, Timeline}, + timeline::{FocusEventError, ReceiptType, Timeline}, utils::u64_to_uint, TaskHandle, }; @@ -257,38 +257,7 @@ impl Room { } pub async fn room_info(&self) -> Result { - // Look for a local event in the `Timeline`. - // - // First off, let's see if a `Timeline` exists… - if let Some(timeline) = self.timeline.read().await.clone() { - // If it contains a `latest_event`… - if let Some(timeline_last_event) = timeline.inner.latest_event().await { - // If it's a local echo… - if timeline_last_event.is_local_echo() { - return Ok(RoomInfo::new( - &self.inner, - Some(Arc::new(EventTimelineItem(timeline_last_event))), - ) - .await?); - } - } - } - - // Otherwise, create a synthetic [`EventTimelineItem`] using the classical - // [`Room`] path. - let latest_event = match self.inner.latest_event() { - Some(latest_event) => matrix_sdk_ui::timeline::EventTimelineItem::from_latest_event( - self.inner.client(), - self.inner.room_id(), - latest_event, - ) - .await - .map(EventTimelineItem) - .map(Arc::new), - None => None, - }; - - Ok(RoomInfo::new(&self.inner, latest_event).await?) + Ok(RoomInfo::new(&self.inner).await?) } pub fn subscribe_to_room_info_updates( diff --git a/bindings/matrix-sdk-ffi/src/room_info.rs b/bindings/matrix-sdk-ffi/src/room_info.rs index 6e3797289..03d55e417 100644 --- a/bindings/matrix-sdk-ffi/src/room_info.rs +++ b/bindings/matrix-sdk-ffi/src/room_info.rs @@ -1,10 +1,9 @@ -use std::{collections::HashMap, sync::Arc}; +use std::collections::HashMap; use matrix_sdk::RoomState; use crate::{ notification_settings::RoomNotificationMode, room::Membership, room_member::RoomMember, - timeline::EventTimelineItem, }; #[derive(uniffi::Record)] @@ -25,7 +24,6 @@ pub struct RoomInfo { canonical_alias: Option, alternative_aliases: Vec, membership: Membership, - latest_event: Option>, /// Member who invited the current user to a room that's in the invited /// state. /// @@ -55,10 +53,7 @@ pub struct RoomInfo { } impl RoomInfo { - pub(crate) async fn new( - room: &matrix_sdk::Room, - latest_event: Option>, - ) -> matrix_sdk::Result { + pub(crate) async fn new(room: &matrix_sdk::Room) -> matrix_sdk::Result { let unread_notification_counts = room.unread_notification_counts(); let power_levels_map = room.users_with_power_levels().await; @@ -81,7 +76,6 @@ impl RoomInfo { canonical_alias: room.canonical_alias().map(Into::into), alternative_aliases: room.alt_aliases().into_iter().map(Into::into).collect(), membership: room.state().into(), - latest_event, inviter: match room.state() { RoomState::Invited => room .invite_details() diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index 8a3571a06..acfd70026 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -505,9 +505,7 @@ impl RoomListItem { } pub async fn room_info(&self) -> Result { - let latest_event = self.inner.latest_event().await.map(EventTimelineItem).map(Arc::new); - - Ok(RoomInfo::new(self.inner.inner_room(), latest_event).await?) + Ok(RoomInfo::new(self.inner.inner_room()).await?) } /// Build a full `Room` FFI object, filling its associated timeline.