Skip to content

Commit 9bf3639

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

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

crates/matrix-sdk/src/sliding_sync.rs

Lines changed: 21 additions & 16 deletions
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;
@@ -93,7 +92,7 @@ impl RoomListEntry {
9392
}
9493

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

9897
/// Room info as giving by the SlidingSync Feature.
9998
#[derive(Debug, Clone)]
@@ -106,8 +105,7 @@ pub struct SlidingSyncRoom {
106105
}
107106

108107
impl SlidingSyncRoom {
109-
fn from(room_id: OwnedRoomId, mut inner: v4::SlidingSyncRoom) -> Self {
110-
let v4::SlidingSyncRoom { timeline, .. } = inner;
108+
fn from(room_id: OwnedRoomId, mut inner: v4::SlidingSyncRoom, timeline: Vec<SyncTimelineEvent>) -> Self {
111109
// we overwrite to only keep one copy
112110
inner.timeline = vec![];
113111
Self {
@@ -144,7 +142,7 @@ impl SlidingSyncRoom {
144142
self.inner.name.as_deref()
145143
}
146144

147-
fn update(&mut self, room_data: &v4::SlidingSyncRoom) {
145+
fn update(&mut self, room_data: &v4::SlidingSyncRoom, timeline: Vec<SyncTimelineEvent>) {
148146
let v4::SlidingSyncRoom {
149147
name,
150148
initial,
@@ -153,7 +151,6 @@ impl SlidingSyncRoom {
153151
unread_notifications,
154152
required_state,
155153
prev_batch,
156-
timeline,
157154
..
158155
} = room_data;
159156

@@ -181,8 +178,8 @@ impl SlidingSyncRoom {
181178

182179
if !timeline.is_empty() {
183180
let mut ref_timeline = self.timeline.lock_mut();
184-
for e in timeline {
185-
ref_timeline.push_cloned(e.clone());
181+
for e in timeline.into_iter() {
182+
ref_timeline.push_cloned(e);
186183
}
187184
}
188185
}
@@ -443,7 +440,7 @@ impl SlidingSync {
443440
resp: v4::Response,
444441
views: &[SlidingSyncView],
445442
) -> anyhow::Result<UpdateSummary> {
446-
self.client.process_sliding_sync(resp.clone()).await?;
443+
let mut processed = self.client.process_sliding_sync(resp.clone()).await?;
447444
tracing::info!("main client processed.");
448445
self.pos.replace(Some(resp.pos));
449446
let mut updated_views = Vec::new();
@@ -462,17 +459,25 @@ impl SlidingSync {
462459

463460
let mut rooms = Vec::new();
464461
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);
462+
for (id, mut room_data) in resp.rooms.into_iter() {
463+
let timeline = if let Some(joined_room) = processed.rooms.join.remove(&id) {
464+
joined_room.timeline.events
465+
} else {
466+
let events = room_data.timeline.into_iter().map(Into::into).collect();
467+
room_data.timeline = vec![];
468+
events
469+
};
470+
471+
if let Some(mut r) = rooms_map.remove(&id) {
472+
r.update(&room_data, timeline);
468473
rooms_map.insert_cloned(id.clone(), r);
469474
rooms.push(id.clone());
470475
} else {
471476
rooms_map.insert_cloned(
472477
id.clone(),
473-
SlidingSyncRoom::from(id.clone(), room_data.clone()),
478+
SlidingSyncRoom::from(id.clone(), room_data, timeline),
474479
);
475-
rooms.push(id.clone());
480+
rooms.push(id);
476481
}
477482
}
478483

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

Lines changed: 1 addition & 1 deletion
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)