From 0da8e56a68e2cc88447859c82637c62727690601 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Thu, 20 Apr 2023 08:58:26 +0100 Subject: [PATCH] crypto-js: wait for device updates in `getUserDevices` (#1790) Wait for up to a second for any in-flight device list updates to complete. --- bindings/matrix-sdk-crypto-js/CHANGELOG.md | 5 +++++ bindings/matrix-sdk-crypto-js/src/machine.rs | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bindings/matrix-sdk-crypto-js/CHANGELOG.md b/bindings/matrix-sdk-crypto-js/CHANGELOG.md index 7e0703be2..ef6a4be1b 100644 --- a/bindings/matrix-sdk-crypto-js/CHANGELOG.md +++ b/bindings/matrix-sdk-crypto-js/CHANGELOG.md @@ -1,3 +1,8 @@ +# v0.1.0-alpha.7 + +- In `OlmMachine.getUserDevices`, wait a limited time for any in-flight + device-list updates to complete. + # v0.1.0-alpha.6 - Add new accessor `InboundGroupSession.senderKey`. diff --git a/bindings/matrix-sdk-crypto-js/src/machine.rs b/bindings/matrix-sdk-crypto-js/src/machine.rs index 99fb0b3d7..1a3163647 100644 --- a/bindings/matrix-sdk-crypto-js/src/machine.rs +++ b/bindings/matrix-sdk-crypto-js/src/machine.rs @@ -1,6 +1,6 @@ //! The crypto specific Olm objects. -use std::{collections::BTreeMap, ops::Deref}; +use std::{collections::BTreeMap, ops::Deref, time::Duration}; use futures_util::StreamExt; use js_sys::{Array, Function, Map, Promise, Set}; @@ -582,7 +582,10 @@ impl OlmMachine { let me = self.inner.clone(); future_to_promise::<_, device::UserDevices>(async move { - Ok(me.get_user_devices(&user_id, None).await.map(Into::into)?) + // wait for up to a second for any in-flight device list requests to complete. + // The reason for this isn't so much to avoid races (some level of raciness is + // inevitable for this method) but to make testing easier. + Ok(me.get_user_devices(&user_id, Some(Duration::from_secs(1))).await.map(Into::into)?) }) }