Skip to content

Commit a3d3973

Browse files
committed
feat: Handle decrypted and deserialized timeline events in sliding sync
1 parent 9616653 commit a3d3973

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

bindings/matrix-sdk-ffi/src/sliding_sync.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ impl SlidingSyncRoom {
137137
for ev in lock.iter().rev() {
138138
if let Ok(AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
139139
SyncRoomMessageEvent::Original(o),
140-
))) = ev.deserialize()
140+
))) = ev.event.deserialize()
141141
{
142-
let inner = matrix_sdk::room::timeline::EventTimelineItem::_new(o, ev.clone());
142+
let inner =
143+
matrix_sdk::room::timeline::EventTimelineItem::_new(o, ev.event.clone());
143144
return Some(Arc::new(EventTimelineItem(inner)));
144145
}
145146
}

crates/matrix-sdk/src/sliding_sync.rs

+25-17
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ use std::{fmt::Debug, sync::Arc};
1818
use anyhow::{bail, Context};
1919
use futures_core::stream::Stream;
2020
use futures_signals::signal::Mutable;
21-
use matrix_sdk_base::deserialized_responses::SyncResponse;
21+
use matrix_sdk_base::deserialized_responses::{SyncResponse, SyncTimelineEvent};
2222
use ruma::{
2323
api::client::sync::sync_events::v4::{
2424
self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ToDeviceConfig,
2525
},
2626
assign,
27-
events::{AnySyncTimelineEvent, RoomEventType},
28-
serde::Raw,
27+
events::RoomEventType,
2928
OwnedRoomId, RoomId, UInt,
3029
};
3130
use url::Url;
@@ -92,8 +91,7 @@ impl RoomListEntry {
9291
}
9392
}
9493

95-
pub type AliveRoomTimeline =
96-
Arc<futures_signals::signal_vec::MutableVec<Raw<AnySyncTimelineEvent>>>;
94+
pub type AliveRoomTimeline = Arc<futures_signals::signal_vec::MutableVec<SyncTimelineEvent>>;
9795

9896
/// Room info as giving by the SlidingSync Feature.
9997
#[derive(Debug, Clone)]
@@ -106,8 +104,11 @@ pub struct SlidingSyncRoom {
106104
}
107105

108106
impl SlidingSyncRoom {
109-
fn from(room_id: OwnedRoomId, mut inner: v4::SlidingSyncRoom) -> Self {
110-
let v4::SlidingSyncRoom { timeline, .. } = inner;
107+
fn from(
108+
room_id: OwnedRoomId,
109+
mut inner: v4::SlidingSyncRoom,
110+
timeline: Vec<SyncTimelineEvent>,
111+
) -> Self {
111112
// we overwrite to only keep one copy
112113
inner.timeline = vec![];
113114
Self {
@@ -144,7 +145,7 @@ impl SlidingSyncRoom {
144145
self.inner.name.as_deref()
145146
}
146147

147-
fn update(&mut self, room_data: &v4::SlidingSyncRoom) {
148+
fn update(&mut self, room_data: &v4::SlidingSyncRoom, timeline: Vec<SyncTimelineEvent>) {
148149
let v4::SlidingSyncRoom {
149150
name,
150151
initial,
@@ -153,7 +154,6 @@ impl SlidingSyncRoom {
153154
unread_notifications,
154155
required_state,
155156
prev_batch,
156-
timeline,
157157
..
158158
} = room_data;
159159

@@ -181,8 +181,8 @@ impl SlidingSyncRoom {
181181

182182
if !timeline.is_empty() {
183183
let mut ref_timeline = self.timeline.lock_mut();
184-
for e in timeline {
185-
ref_timeline.push_cloned(e.clone());
184+
for e in timeline.into_iter() {
185+
ref_timeline.push_cloned(e);
186186
}
187187
}
188188
}
@@ -443,7 +443,7 @@ impl SlidingSync {
443443
resp: v4::Response,
444444
views: &[SlidingSyncView],
445445
) -> anyhow::Result<UpdateSummary> {
446-
self.client.process_sliding_sync(resp.clone()).await?;
446+
let mut processed = self.client.process_sliding_sync(resp.clone()).await?;
447447
tracing::info!("main client processed.");
448448
self.pos.replace(Some(resp.pos));
449449
let mut updated_views = Vec::new();
@@ -462,17 +462,25 @@ impl SlidingSync {
462462

463463
let mut rooms = Vec::new();
464464
let mut rooms_map = self.rooms.lock_mut();
465-
for (id, room_data) in resp.rooms.iter() {
466-
if let Some(mut r) = rooms_map.remove(id) {
467-
r.update(room_data);
465+
for (id, mut room_data) in resp.rooms.into_iter() {
466+
let timeline = if let Some(joined_room) = processed.rooms.join.remove(&id) {
467+
joined_room.timeline.events
468+
} else {
469+
let events = room_data.timeline.into_iter().map(Into::into).collect();
470+
room_data.timeline = vec![];
471+
events
472+
};
473+
474+
if let Some(mut r) = rooms_map.remove(&id) {
475+
r.update(&room_data, timeline);
468476
rooms_map.insert_cloned(id.clone(), r);
469477
rooms.push(id.clone());
470478
} else {
471479
rooms_map.insert_cloned(
472480
id.clone(),
473-
SlidingSyncRoom::from(id.clone(), room_data.clone()),
481+
SlidingSyncRoom::from(id.clone(), room_data, timeline),
474482
);
475-
rooms.push(id.clone());
483+
rooms.push(id);
476484
}
477485
}
478486

labs/jack-in/src/components/details.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Details {
7979
.timeline()
8080
.lock_ref()
8181
.iter()
82-
.filter_map(|d| d.deserialize().ok())
82+
.filter_map(|d| d.event.deserialize().ok())
8383
.map(|e| e.into_full_event(room_id.clone()))
8484
.collect();
8585
timeline.reverse();

0 commit comments

Comments
 (0)