Skip to content

Commit e6f2f65

Browse files
authored
Merge pull request #1838 from matrix-org/florianduros/feat/optional-unused-fallback-keys-js-bindings
JS Bindings: make `unused_fallback_keys` as optional in `machine.rs/receive_sync_changes`
2 parents cca8ac7 + 75870dd commit e6f2f65

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

bindings/matrix-sdk-crypto-js/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v0.1.0-alpha.8
2+
3+
- Make `unused_fallback_keys` as optional in `Machine.receive_sync_changes`
4+
15
# v0.1.0-alpha.7
26

37
- Add new accessors `Device.algorithms` and `Device.isSignedByOwner`

bindings/matrix-sdk-crypto-js/src/machine.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl OlmMachine {
222222
to_device_events: &str,
223223
changed_devices: &sync_events::DeviceLists,
224224
one_time_key_counts: &Map,
225-
unused_fallback_keys: &Set,
225+
unused_fallback_keys: Option<Set>,
226226
) -> Result<Promise, JsError> {
227227
let to_device_events = serde_json::from_str(to_device_events)?;
228228
let changed_devices = changed_devices.inner.clone();
@@ -239,13 +239,18 @@ impl OlmMachine {
239239
Some((key, value))
240240
})
241241
.collect();
242-
let unused_fallback_keys: Option<Vec<DeviceKeyAlgorithm>> = Some(
243-
unused_fallback_keys
244-
.values()
245-
.into_iter()
246-
.filter_map(|js_value| Some(DeviceKeyAlgorithm::from(js_value.ok()?.as_string()?)))
247-
.collect(),
248-
);
242+
243+
// Convert the unused_fallback_keys JS Set to a `Vec<DeviceKeyAlgorithm>`
244+
let unused_fallback_keys: Option<Vec<DeviceKeyAlgorithm>> =
245+
unused_fallback_keys.map(|fallback_keys| {
246+
fallback_keys
247+
.values()
248+
.into_iter()
249+
.filter_map(|js_value| {
250+
Some(DeviceKeyAlgorithm::from(js_value.ok()?.as_string()?))
251+
})
252+
.collect()
253+
});
249254

250255
let me = self.inner.clone();
251256

bindings/matrix-sdk-crypto-js/tests/machine.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ describe(OlmMachine.name, () => {
220220
expect(receiveSyncChanges).toEqual([]);
221221
});
222222

223+
test("can receive sync changes with unusedFallbackKeys as undefined", async () => {
224+
const m = await machine();
225+
const toDeviceEvents = JSON.stringify([]);
226+
const changedDevices = new DeviceLists();
227+
const oneTimeKeyCounts = new Map();
228+
229+
const receiveSyncChanges = JSON.parse(
230+
await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, undefined),
231+
);
232+
233+
expect(receiveSyncChanges).toEqual([]);
234+
});
235+
223236
test("can get the outgoing requests that need to be send out", async () => {
224237
const m = await machine();
225238
const toDeviceEvents = JSON.stringify([]);

0 commit comments

Comments
 (0)