@@ -18,14 +18,13 @@ use std::{fmt::Debug, sync::Arc};
18
18
use anyhow:: { bail, Context } ;
19
19
use futures_core:: stream:: Stream ;
20
20
use futures_signals:: signal:: Mutable ;
21
- use matrix_sdk_base:: deserialized_responses:: SyncResponse ;
21
+ use matrix_sdk_base:: deserialized_responses:: { SyncResponse , SyncTimelineEvent } ;
22
22
use ruma:: {
23
23
api:: client:: sync:: sync_events:: v4:: {
24
24
self , AccountDataConfig , E2EEConfig , ExtensionsConfig , ToDeviceConfig ,
25
25
} ,
26
26
assign,
27
- events:: { AnySyncTimelineEvent , RoomEventType } ,
28
- serde:: Raw ,
27
+ events:: RoomEventType ,
29
28
OwnedRoomId , RoomId , UInt ,
30
29
} ;
31
30
use url:: Url ;
@@ -92,8 +91,7 @@ impl RoomListEntry {
92
91
}
93
92
}
94
93
95
- pub type AliveRoomTimeline =
96
- Arc < futures_signals:: signal_vec:: MutableVec < Raw < AnySyncTimelineEvent > > > ;
94
+ pub type AliveRoomTimeline = Arc < futures_signals:: signal_vec:: MutableVec < SyncTimelineEvent > > ;
97
95
98
96
/// Room info as giving by the SlidingSync Feature.
99
97
#[ derive( Debug , Clone ) ]
@@ -106,8 +104,11 @@ pub struct SlidingSyncRoom {
106
104
}
107
105
108
106
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 {
111
112
// we overwrite to only keep one copy
112
113
inner. timeline = vec ! [ ] ;
113
114
Self {
@@ -144,7 +145,7 @@ impl SlidingSyncRoom {
144
145
self . inner . name . as_deref ( )
145
146
}
146
147
147
- fn update ( & mut self , room_data : & v4:: SlidingSyncRoom ) {
148
+ fn update ( & mut self , room_data : & v4:: SlidingSyncRoom , timeline : Vec < SyncTimelineEvent > ) {
148
149
let v4:: SlidingSyncRoom {
149
150
name,
150
151
initial,
@@ -153,7 +154,6 @@ impl SlidingSyncRoom {
153
154
unread_notifications,
154
155
required_state,
155
156
prev_batch,
156
- timeline,
157
157
..
158
158
} = room_data;
159
159
@@ -181,8 +181,8 @@ impl SlidingSyncRoom {
181
181
182
182
if !timeline. is_empty ( ) {
183
183
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) ;
186
186
}
187
187
}
188
188
}
@@ -443,7 +443,7 @@ impl SlidingSync {
443
443
resp : v4:: Response ,
444
444
views : & [ SlidingSyncView ] ,
445
445
) -> anyhow:: Result < UpdateSummary > {
446
- self . client . process_sliding_sync ( resp. clone ( ) ) . await ?;
446
+ let mut processed = self . client . process_sliding_sync ( resp. clone ( ) ) . await ?;
447
447
tracing:: info!( "main client processed." ) ;
448
448
self . pos . replace ( Some ( resp. pos ) ) ;
449
449
let mut updated_views = Vec :: new ( ) ;
@@ -462,17 +462,25 @@ impl SlidingSync {
462
462
463
463
let mut rooms = Vec :: new ( ) ;
464
464
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) ;
468
476
rooms_map. insert_cloned ( id. clone ( ) , r) ;
469
477
rooms. push ( id. clone ( ) ) ;
470
478
} else {
471
479
rooms_map. insert_cloned (
472
480
id. clone ( ) ,
473
- SlidingSyncRoom :: from ( id. clone ( ) , room_data. clone ( ) ) ,
481
+ SlidingSyncRoom :: from ( id. clone ( ) , room_data, timeline ) ,
474
482
) ;
475
- rooms. push ( id. clone ( ) ) ;
483
+ rooms. push ( id) ;
476
484
}
477
485
}
478
486
0 commit comments