@@ -17,7 +17,7 @@ limitations under the License.
17
17
import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-js" ;
18
18
19
19
import type { IEventDecryptionResult , IMegolmSessionData } from "../@types/crypto" ;
20
- import type { IToDeviceEvent } from "../sync-accumulator" ;
20
+ import type { IDeviceLists , IToDeviceEvent } from "../sync-accumulator" ;
21
21
import type { IEncryptedEventInfo } from "../crypto/api" ;
22
22
import { MatrixEvent } from "../models/event" ;
23
23
import { Room } from "../models/room" ;
@@ -176,20 +176,23 @@ export class RustCrypto implements CryptoBackend {
176
176
* @param events - the received to-device messages
177
177
* @param oneTimeKeysCounts - the received one time key counts
178
178
* @param unusedFallbackKeys - the received unused fallback keys
179
+ * @param devices - the received device list updates
179
180
* @returns A list of preprocessed to-device messages.
180
181
*/
181
182
private async receiveSyncChanges ( {
182
183
events,
183
184
oneTimeKeysCounts = new Map < string , number > ( ) ,
184
185
unusedFallbackKeys = new Set < string > ( ) ,
186
+ devices = new RustSdkCryptoJs . DeviceLists ( ) ,
185
187
} : {
186
188
events ?: IToDeviceEvent [ ] ;
187
189
oneTimeKeysCounts ?: Map < string , number > ;
188
190
unusedFallbackKeys ?: Set < string > ;
191
+ devices ?: RustSdkCryptoJs . DeviceLists ;
189
192
} ) : Promise < IToDeviceEvent [ ] > {
190
193
const result = await this . olmMachine . receiveSyncChanges (
191
194
events ? JSON . stringify ( events ) : "[]" ,
192
- new RustSdkCryptoJs . DeviceLists ( ) ,
195
+ devices ,
193
196
oneTimeKeysCounts ,
194
197
unusedFallbackKeys ,
195
198
) ;
@@ -229,6 +232,16 @@ export class RustCrypto implements CryptoBackend {
229
232
}
230
233
}
231
234
235
+ /** called by the sync loop to process the notification that device lists have
236
+ * been changed.
237
+ *
238
+ * @param deviceLists - device_lists field from /sync
239
+ */
240
+ public async processDeviceLists ( deviceLists : IDeviceLists ) : Promise < void > {
241
+ const devices = new RustSdkCryptoJs . DeviceLists ( deviceLists . changed , deviceLists . left ) ;
242
+ await this . receiveSyncChanges ( { devices } ) ;
243
+ }
244
+
232
245
/** called by the sync loop on m.room.encrypted events
233
246
*
234
247
* @param room - in which the event was received
0 commit comments