@@ -756,7 +756,7 @@ impl SlidingSync {
756
756
Ok ( self . inner . internal_channel_send ( SlidingSyncInternalMessage :: SyncLoopStop ) ?)
757
757
}
758
758
759
- /// Expire the current Sliding Sync session.
759
+ /// Expire the current Sliding Sync session on the client-side .
760
760
///
761
761
/// Expiring a Sliding Sync session means: resetting `pos`. It also resets
762
762
/// sticky parameters.
@@ -783,7 +783,14 @@ impl SlidingSync {
783
783
}
784
784
785
785
// Force invalidation of all the sticky parameters.
786
- let _ = self . inner . sticky . write ( ) . unwrap ( ) . data_mut ( ) ;
786
+ {
787
+ let mut sticky = self . inner . sticky . write ( ) . unwrap ( ) ;
788
+ let data = sticky. data_mut ( ) ;
789
+
790
+ // Clear all room subscriptions: we don't want to resend all room subscriptions
791
+ // when the session will restart.
792
+ data. room_subscriptions . clear ( ) ;
793
+ }
787
794
788
795
self . inner . lists . read ( ) . await . values ( ) . for_each ( |list| list. invalidate_sticky_data ( ) ) ;
789
796
}
@@ -1151,6 +1158,65 @@ mod tests {
1151
1158
Ok ( ( ) )
1152
1159
}
1153
1160
1161
+ #[ async_test]
1162
+ async fn test_room_subscriptions_are_reset_when_session_expires ( ) -> Result < ( ) > {
1163
+ let ( _server, sliding_sync) = new_sliding_sync ( vec ! [ SlidingSyncList :: builder( "foo" )
1164
+ . sync_mode( SlidingSyncMode :: new_selective( ) . add_range( 0 ..=10 ) ) ] )
1165
+ . await ?;
1166
+
1167
+ let room_id_0 = room_id ! ( "!r0:bar.org" ) ;
1168
+ let room_id_1 = room_id ! ( "!r1:bar.org" ) ;
1169
+ let room_id_2 = room_id ! ( "!r2:bar.org" ) ;
1170
+
1171
+ // Subscribe to two rooms.
1172
+ sliding_sync. subscribe_to_rooms ( & [ room_id_0, room_id_1] , None ) ;
1173
+
1174
+ {
1175
+ let sticky = sliding_sync. inner . sticky . read ( ) . unwrap ( ) ;
1176
+ let room_subscriptions = & sticky. data ( ) . room_subscriptions ;
1177
+
1178
+ assert ! ( room_subscriptions. contains_key( & room_id_0. to_owned( ) ) ) ;
1179
+ assert ! ( room_subscriptions. contains_key( & room_id_1. to_owned( ) ) ) ;
1180
+ assert ! ( room_subscriptions. contains_key( & room_id_2. to_owned( ) ) . not( ) ) ;
1181
+ }
1182
+
1183
+ // Subscribe to one more room.
1184
+ sliding_sync. subscribe_to_rooms ( & [ room_id_2] , None ) ;
1185
+
1186
+ {
1187
+ let sticky = sliding_sync. inner . sticky . read ( ) . unwrap ( ) ;
1188
+ let room_subscriptions = & sticky. data ( ) . room_subscriptions ;
1189
+
1190
+ assert ! ( room_subscriptions. contains_key( & room_id_0. to_owned( ) ) ) ;
1191
+ assert ! ( room_subscriptions. contains_key( & room_id_1. to_owned( ) ) ) ;
1192
+ assert ! ( room_subscriptions. contains_key( & room_id_2. to_owned( ) ) ) ;
1193
+ }
1194
+
1195
+ // Suddenly, the session expires!
1196
+ sliding_sync. expire_session ( ) . await ;
1197
+
1198
+ {
1199
+ let sticky = sliding_sync. inner . sticky . read ( ) . unwrap ( ) ;
1200
+ let room_subscriptions = & sticky. data ( ) . room_subscriptions ;
1201
+
1202
+ assert ! ( room_subscriptions. is_empty( ) ) ;
1203
+ }
1204
+
1205
+ // Subscribe to one room again.
1206
+ sliding_sync. subscribe_to_rooms ( & [ room_id_2] , None ) ;
1207
+
1208
+ {
1209
+ let sticky = sliding_sync. inner . sticky . read ( ) . unwrap ( ) ;
1210
+ let room_subscriptions = & sticky. data ( ) . room_subscriptions ;
1211
+
1212
+ assert ! ( room_subscriptions. contains_key( & room_id_0. to_owned( ) ) . not( ) ) ;
1213
+ assert ! ( room_subscriptions. contains_key( & room_id_1. to_owned( ) ) . not( ) ) ;
1214
+ assert ! ( room_subscriptions. contains_key( & room_id_2. to_owned( ) ) ) ;
1215
+ }
1216
+
1217
+ Ok ( ( ) )
1218
+ }
1219
+
1154
1220
#[ async_test]
1155
1221
async fn test_to_device_token_properly_cached ( ) -> Result < ( ) > {
1156
1222
let ( _server, sliding_sync) = new_sliding_sync ( vec ! [ SlidingSyncList :: builder( "foo" )
0 commit comments