mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-19 06:04:31 -04:00
ffi: add EventTimelineItemDebugInfoProvider to lazily retrieve an event's debug info
This commit is contained in:
committed by
Jorge Martin Espinosa
parent
281a79ffc6
commit
0082fbc0b4
@@ -703,7 +703,7 @@ impl RoomListItem {
|
||||
}
|
||||
|
||||
async fn latest_event(&self) -> Option<EventTimelineItem> {
|
||||
self.inner.latest_event().await.map(|e| e.into())
|
||||
self.inner.latest_event().await.map(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1032,7 +1032,7 @@ pub struct EventTimelineItem {
|
||||
content: TimelineItemContent,
|
||||
timestamp: u64,
|
||||
reactions: Vec<Reaction>,
|
||||
debug_info: EventTimelineItemDebugInfo,
|
||||
debug_info_provider: Arc<EventTimelineItemDebugInfoProvider>,
|
||||
local_send_state: Option<EventSendState>,
|
||||
read_receipts: HashMap<String, Receipt>,
|
||||
origin: Option<EventItemOrigin>,
|
||||
@@ -1056,11 +1056,7 @@ impl From<matrix_sdk_ui::timeline::EventTimelineItem> for EventTimelineItem {
|
||||
.collect(),
|
||||
})
|
||||
.collect();
|
||||
let debug_info = EventTimelineItemDebugInfo {
|
||||
model: format!("{:#?}", value),
|
||||
original_json: value.original_json().map(|raw| raw.json().get().to_owned()),
|
||||
latest_edit_json: value.latest_edit_json().map(|raw| raw.json().get().to_owned()),
|
||||
};
|
||||
let debug_info_provider = Arc::new(EventTimelineItemDebugInfoProvider(value.clone()));
|
||||
let read_receipts =
|
||||
value.read_receipts().iter().map(|(k, v)| (k.to_string(), v.clone().into())).collect();
|
||||
Self {
|
||||
@@ -1075,7 +1071,7 @@ impl From<matrix_sdk_ui::timeline::EventTimelineItem> for EventTimelineItem {
|
||||
content: value.content().clone().into(),
|
||||
timestamp: value.timestamp().0.into(),
|
||||
reactions,
|
||||
debug_info,
|
||||
debug_info_provider,
|
||||
local_send_state: value.send_state().map(|s| s.into()),
|
||||
read_receipts,
|
||||
origin: value.origin(),
|
||||
@@ -1096,6 +1092,22 @@ impl From<ruma::events::receipt::Receipt> for Receipt {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper to retrieve the debug info lazily instead of immediately
|
||||
/// transforming it for each timeline event.
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct EventTimelineItemDebugInfoProvider(matrix_sdk_ui::timeline::EventTimelineItem);
|
||||
|
||||
#[uniffi::export]
|
||||
impl EventTimelineItemDebugInfoProvider {
|
||||
fn get(&self) -> EventTimelineItemDebugInfo {
|
||||
EventTimelineItemDebugInfo {
|
||||
model: format!("{:#?}", self.0),
|
||||
original_json: self.0.original_json().map(|raw| raw.json().get().to_owned()),
|
||||
latest_edit_json: self.0.latest_edit_json().map(|raw| raw.json().get().to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, uniffi::Record)]
|
||||
pub struct EventTimelineItemDebugInfo {
|
||||
model: String,
|
||||
|
||||
Reference in New Issue
Block a user