Skip to content

Commit

Permalink
New accessors roomKeyRequestsEnabled and roomKeyForwardingEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Dec 1, 2023
1 parent e4576fd commit a179310
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
[patch.'https://github.com/matrix-org/matrix-rust-sdk']
matrix-sdk-base = { path = "../matrix-rust-sdk/crates/matrix-sdk-base" }
matrix-sdk-common = { path = "../matrix-rust-sdk/crates/matrix-sdk-common" }
matrix-sdk-crypto = { path = "../matrix-rust-sdk/crates/matrix-sdk-crypto" }
matrix-sdk-indexeddb = { path = "../matrix-rust-sdk/crates/matrix-sdk-indexeddb" }
matrix-sdk-qrcode = { path = "../matrix-rust-sdk/crates/matrix-sdk-qrcode" }

[build]
target = "wasm32-unknown-unknown"
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# UNRELEASED

- Add new properties `roomKeyRequestsEnabled` and `roomKeyForwardingEnabled`
to OlmMachine.
([#60](https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/60),
([matrix-rust-sdk#2902](https://github.com/matrix-org/matrix-rust-sdk/pull/2902))

# matrix-sdk-crypto-wasm v3.2.0

- Add `timeout_secs` parameters to `OlmMachine.get_user_devices` and
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,38 @@ impl OlmMachine {
future_to_promise(async move { Ok(me.display_name().await?) })
}

/// Whether automatic transmission of room key requests is enabled.
///
/// Room key requests allow the device to request room keys that it might
/// have missed in the original share using `m.room_key_request`
/// events.
#[wasm_bindgen(getter, js_name = "roomKeyRequestsEnabled")]
pub fn are_room_key_requests_enabled(&self) -> bool {
self.inner.are_room_key_requests_enabled()
}

/// Enable or disable automatic transmission of room key requests.
#[wasm_bindgen(setter, js_name = "roomKeyRequestsEnabled")]
pub fn toggle_room_key_requests(&self, enabled: bool) {
self.inner.toggle_room_key_requests(enabled)
}

/// Whether room key forwarding is enabled.
///
/// If room key forwarding is enabled, we will automatically reply to
/// incoming `m.room_key_request` messages from verified devices by
/// forwarding the requested key (if we have it).
#[wasm_bindgen(getter, js_name = "roomKeyForwardingEnabled")]
pub fn is_room_key_forwarding_enabled(&self) -> bool {
self.inner.is_room_key_forwarding_enabled()
}

/// Enable or disable room key forwarding.
#[wasm_bindgen(setter, js_name = "roomKeyForwardingEnabled")]
pub fn toggle_room_key_forwarding(&self, enabled: bool) {
self.inner.toggle_room_key_forwarding(enabled)
}

/// Get the list of users whose devices we are currently tracking.
///
/// A user can be marked for tracking using the
Expand Down
14 changes: 14 additions & 0 deletions tests/machine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ describe(OlmMachine.name, () => {
expect(await machine().displayName).toBeUndefined();
});

test("can toggle room key requests", async () => {
const m = await machine();
expect(m.roomKeyRequestsEnabled).toBeTruthy();
m.roomKeyRequestsEnabled = false;
expect(m.roomKeyRequestsEnabled).toBeFalsy();
});

test("can toggle room key forwarding", async () => {
const m = await machine();
expect(m.roomKeyForwardingEnabled).toBeTruthy();
m.roomKeyForwardingEnabled = false;
expect(m.roomKeyForwardingEnabled).toBeFalsy();
});

test("can read tracked users", async () => {
const m = await machine();
const trackedUsers = await m.trackedUsers();
Expand Down

0 comments on commit a179310

Please sign in to comment.