@@ -29,6 +29,8 @@ import { DeviceTrustLevel, UserTrustLevel } from "../crypto/CrossSigning";
29
29
import { RoomEncryptor } from "./RoomEncryptor" ;
30
30
import { OutgoingRequest , OutgoingRequestProcessor } from "./OutgoingRequestProcessor" ;
31
31
import { KeyClaimManager } from "./KeyClaimManager" ;
32
+ import { ISyncResponse } from "../sync-accumulator" ;
33
+ import { ISyncStateData } from "../sync" ;
32
34
import { MapWithDefault } from "../utils" ;
33
35
34
36
/**
@@ -176,20 +178,23 @@ export class RustCrypto implements CryptoBackend {
176
178
* @param events - the received to-device messages
177
179
* @param oneTimeKeysCounts - the received one time key counts
178
180
* @param unusedFallbackKeys - the received unused fallback keys
181
+ * @param devices - the received devices
179
182
* @returns A list of preprocessed to-device messages.
180
183
*/
181
184
private async receiveSyncChanges ( {
182
185
events,
183
186
oneTimeKeysCounts = new Map < string , number > ( ) ,
184
187
unusedFallbackKeys = new Set < string > ( ) ,
188
+ devices = new RustSdkCryptoJs . DeviceLists ( ) ,
185
189
} : {
186
190
events ?: IToDeviceEvent [ ] ;
187
191
oneTimeKeysCounts ?: Map < string , number > ;
188
192
unusedFallbackKeys ?: Set < string > ;
193
+ devices ?: RustSdkCryptoJs . DeviceLists ;
189
194
} ) : Promise < IToDeviceEvent [ ] > {
190
195
const result = await this . olmMachine . receiveSyncChanges (
191
196
events ? JSON . stringify ( events ) : "[]" ,
192
- new RustSdkCryptoJs . DeviceLists ( ) ,
197
+ devices ,
193
198
oneTimeKeysCounts ,
194
199
unusedFallbackKeys ,
195
200
) ;
@@ -229,6 +234,23 @@ export class RustCrypto implements CryptoBackend {
229
234
}
230
235
}
231
236
237
+ /** called by the sync loop to process
238
+ *
239
+ * @param syncData - Object containing sync tokens associated with this sync
240
+ * @param deviceLists - device_lists field from /sync, or response from
241
+ */
242
+ public async processDeviceLists (
243
+ syncData : ISyncStateData ,
244
+ deviceLists : Required < ISyncResponse > [ "device_lists" ] ,
245
+ ) : Promise < void > {
246
+ // Initial syncs don't have device change lists. We'll either get the complete list
247
+ // of changes for the interval or will have invalidated everything in willProcessSync
248
+ if ( ! syncData . oldSyncToken || ! deviceLists ) return ;
249
+
250
+ const devices = new RustSdkCryptoJs . DeviceLists ( deviceLists . changed , deviceLists . left ) ;
251
+ await this . receiveSyncChanges ( { devices } ) ;
252
+ }
253
+
232
254
/** called by the sync loop on m.room.encrypted events
233
255
*
234
256
* @param room - in which the event was received
0 commit comments