mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 13:40:55 -04:00
Merge pull request #3541 from Hywan/chore-ffi-roominfo-latest-event
chore(ffi): Remove `RoomInfo::latest_event`
This commit is contained in:
@@ -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<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(
|
||||
|
||||
@@ -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<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.
|
||||
///
|
||||
@@ -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;
|
||||
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user