Skip to content

Commit

Permalink
Merge pull request #1838 from matrix-org/florianduros/feat/optional-u…
Browse files Browse the repository at this point in the history
…nused-fallback-keys-js-bindings

JS Bindings: make `unused_fallback_keys` as optional in `machine.rs/receive_sync_changes`
  • Loading branch information
poljar authored Apr 28, 2023
2 parents cca8ac7 + 75870dd commit e6f2f65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
4 changes: 4 additions & 0 deletions bindings/matrix-sdk-crypto-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.1.0-alpha.8

- Make `unused_fallback_keys` as optional in `Machine.receive_sync_changes`

# v0.1.0-alpha.7

- Add new accessors `Device.algorithms` and `Device.isSignedByOwner`
Expand Down
21 changes: 13 additions & 8 deletions bindings/matrix-sdk-crypto-js/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl OlmMachine {
to_device_events: &str,
changed_devices: &sync_events::DeviceLists,
one_time_key_counts: &Map,
unused_fallback_keys: &Set,
unused_fallback_keys: Option<Set>,
) -> Result<Promise, JsError> {
let to_device_events = serde_json::from_str(to_device_events)?;
let changed_devices = changed_devices.inner.clone();
Expand All @@ -239,13 +239,18 @@ impl OlmMachine {
Some((key, value))
})
.collect();
let unused_fallback_keys: Option<Vec<DeviceKeyAlgorithm>> = Some(
unused_fallback_keys
.values()
.into_iter()
.filter_map(|js_value| Some(DeviceKeyAlgorithm::from(js_value.ok()?.as_string()?)))
.collect(),
);

// Convert the unused_fallback_keys JS Set to a `Vec<DeviceKeyAlgorithm>`
let unused_fallback_keys: Option<Vec<DeviceKeyAlgorithm>> =
unused_fallback_keys.map(|fallback_keys| {
fallback_keys
.values()
.into_iter()
.filter_map(|js_value| {
Some(DeviceKeyAlgorithm::from(js_value.ok()?.as_string()?))
})
.collect()
});

let me = self.inner.clone();

Expand Down
13 changes: 13 additions & 0 deletions bindings/matrix-sdk-crypto-js/tests/machine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ describe(OlmMachine.name, () => {
expect(receiveSyncChanges).toEqual([]);
});

test("can receive sync changes with unusedFallbackKeys as undefined", async () => {
const m = await machine();
const toDeviceEvents = JSON.stringify([]);
const changedDevices = new DeviceLists();
const oneTimeKeyCounts = new Map();

const receiveSyncChanges = JSON.parse(
await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, undefined),
);

expect(receiveSyncChanges).toEqual([]);
});

test("can get the outgoing requests that need to be send out", async () => {
const m = await machine();
const toDeviceEvents = JSON.stringify([]);
Expand Down

0 comments on commit e6f2f65

Please sign in to comment.