@@ -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 ;
@@ -93,7 +92,7 @@ impl RoomListEntry {
93
92
}
94
93
95
94
pub type AliveRoomTimeline =
96
- Arc < futures_signals:: signal_vec:: MutableVec < Raw < AnySyncTimelineEvent > > > ;
95
+ Arc < futures_signals:: signal_vec:: MutableVec < SyncTimelineEvent > > ;
97
96
98
97
/// Room info as giving by the SlidingSync Feature.
99
98
#[ derive( Debug , Clone ) ]
@@ -106,8 +105,7 @@ pub struct SlidingSyncRoom {
106
105
}
107
106
108
107
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 {
111
109
// we overwrite to only keep one copy
112
110
inner. timeline = vec ! [ ] ;
113
111
Self {
@@ -144,7 +142,7 @@ impl SlidingSyncRoom {
144
142
self . inner . name . as_deref ( )
145
143
}
146
144
147
- fn update ( & mut self , room_data : & v4:: SlidingSyncRoom ) {
145
+ fn update ( & mut self , room_data : & v4:: SlidingSyncRoom , timeline : Vec < SyncTimelineEvent > ) {
148
146
let v4:: SlidingSyncRoom {
149
147
name,
150
148
initial,
@@ -153,7 +151,6 @@ impl SlidingSyncRoom {
153
151
unread_notifications,
154
152
required_state,
155
153
prev_batch,
156
- timeline,
157
154
..
158
155
} = room_data;
159
156
@@ -181,8 +178,8 @@ impl SlidingSyncRoom {
181
178
182
179
if !timeline. is_empty ( ) {
183
180
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) ;
186
183
}
187
184
}
188
185
}
@@ -443,7 +440,7 @@ impl SlidingSync {
443
440
resp : v4:: Response ,
444
441
views : & [ SlidingSyncView ] ,
445
442
) -> anyhow:: Result < UpdateSummary > {
446
- self . client . process_sliding_sync ( resp. clone ( ) ) . await ?;
443
+ let mut processed = self . client . process_sliding_sync ( resp. clone ( ) ) . await ?;
447
444
tracing:: info!( "main client processed." ) ;
448
445
self . pos . replace ( Some ( resp. pos ) ) ;
449
446
let mut updated_views = Vec :: new ( ) ;
@@ -462,17 +459,25 @@ impl SlidingSync {
462
459
463
460
let mut rooms = Vec :: new ( ) ;
464
461
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) ;
468
473
rooms_map. insert_cloned ( id. clone ( ) , r) ;
469
474
rooms. push ( id. clone ( ) ) ;
470
475
} else {
471
476
rooms_map. insert_cloned (
472
477
id. clone ( ) ,
473
- SlidingSyncRoom :: from ( id. clone ( ) , room_data. clone ( ) ) ,
478
+ SlidingSyncRoom :: from ( id. clone ( ) , room_data, timeline ) ,
474
479
) ;
475
- rooms. push ( id. clone ( ) ) ;
480
+ rooms. push ( id) ;
476
481
}
477
482
}
478
483
0 commit comments