Skip to content

Commit

Permalink
Merge pull request #3541 from Hywan/chore-ffi-roominfo-latest-event
Browse files Browse the repository at this point in the history
chore(ffi): Remove `RoomInfo::latest_event`
  • Loading branch information
Hywan authored Jun 13, 2024
2 parents 9b05d0d + 01a36c9 commit de5d805
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
35 changes: 2 additions & 33 deletions bindings/matrix-sdk-ffi/src/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -257,38 +257,7 @@ impl Room {
}

pub async fn room_info(&self) -> Result<RoomInfo, ClientError> {
// 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(
Expand Down
10 changes: 2 additions & 8 deletions bindings/matrix-sdk-ffi/src/room_info.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -25,7 +24,6 @@ pub struct RoomInfo {
canonical_alias: Option<String>,
alternative_aliases: Vec<String>,
membership: Membership,
latest_event: Option<Arc<EventTimelineItem>>,
/// Member who invited the current user to a room that's in the invited
/// state.
///
Expand Down Expand Up @@ -55,10 +53,7 @@ pub struct RoomInfo {
}

impl RoomInfo {
pub(crate) async fn new(
room: &matrix_sdk::Room,
latest_event: Option<Arc<EventTimelineItem>>,
) -> matrix_sdk::Result<Self> {
pub(crate) async fn new(room: &matrix_sdk::Room) -> matrix_sdk::Result<Self> {
let unread_notification_counts = room.unread_notification_counts();

let power_levels_map = room.users_with_power_levels().await;
Expand All @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions bindings/matrix-sdk-ffi/src/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,7 @@ impl RoomListItem {
}

pub async fn room_info(&self) -> Result<RoomInfo, ClientError> {
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.
Expand Down

0 comments on commit de5d805

Please sign in to comment.