Skip to content

Commit

Permalink
chore: Move a non-JS method outside a #[wasm_bindgen] impl.
Browse files Browse the repository at this point in the history
This patch moves the `OlmMachine::import_exported_room_keys_helper` to
a `impl` that is not annotated by `#[wasm_bindgen]` because it doesn't
have to live in the JS binding.
  • Loading branch information
Hywan committed Jan 18, 2024
1 parent 6bb1d6a commit 6fb85bd
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,29 +963,6 @@ impl OlmMachine {
}))
}

/// Shared helper for `import_exported_room_keys` and `import_room_keys`.
///
/// Wraps the progress listener in a Rust closure and runs
/// `Store::import_exported_room_keys`
///
/// Items inside `exported_room_keys` are going to be deleted on the JS part
/// after the function returns. Be careful to not used `exported_room_keys`
/// after that.
async fn import_exported_room_keys_helper(
inner: &matrix_sdk_crypto::OlmMachine,
exported_room_keys: Vec<matrix_sdk_crypto::olm::ExportedRoomKey>,
progress_listener: Function,
) -> Result<matrix_sdk_crypto::RoomKeyImportResult, CryptoStoreError> {
inner
.store()
.import_exported_room_keys(exported_room_keys, |progress, total| {
progress_listener
.call2(&JsValue::NULL, &JsValue::from(progress), &JsValue::from(total))
.expect("Progress listener passed to `importExportedRoomKeys` failed");
})
.await
}

/// Import the given room keys into our store.
///
/// # Arguments
Expand Down Expand Up @@ -1410,6 +1387,31 @@ impl OlmMachine {
pub fn close(self) {}
}

impl OlmMachine {
/// Shared helper for `import_exported_room_keys` and `import_room_keys`.
///
/// Wraps the progress listener in a Rust closure and runs
/// `Store::import_exported_room_keys`
///
/// Items inside `exported_room_keys` will be invalidated by this method. Be
/// careful to not used `ExportedRoomKey`s after this method has been
/// called.
async fn import_exported_room_keys_helper(
inner: &matrix_sdk_crypto::OlmMachine,
exported_room_keys: Vec<matrix_sdk_crypto::olm::ExportedRoomKey>,
progress_listener: Function,
) -> Result<matrix_sdk_crypto::RoomKeyImportResult, CryptoStoreError> {
inner
.store()
.import_exported_room_keys(exported_room_keys, |progress, total| {
progress_listener
.call2(&JsValue::NULL, &JsValue::from(progress), &JsValue::from(total))
.expect("Progress listener passed to `importExportedRoomKeys` failed");
})
.await
}
}

// helper for register_room_key_received_callback: wraps the key info
// into our own RoomKeyInfo struct, and passes it into the javascript
// function
Expand Down

0 comments on commit 6fb85bd

Please sign in to comment.