diff --git a/crates/matrix-sdk-crypto/src/js/machine.rs b/crates/matrix-sdk-crypto/src/js/machine.rs index 2bf0dced9..f5d00bc94 100644 --- a/crates/matrix-sdk-crypto/src/js/machine.rs +++ b/crates/matrix-sdk-crypto/src/js/machine.rs @@ -33,6 +33,28 @@ impl OlmMachine { }) } + /// The unique user ID that owns this `OlmMachine` instance. + pub fn user_id(&self) -> identifiers::UserId { + identifiers::UserId { inner: self.inner.user_id().to_owned() } + } + + /// The unique device ID that identifies this `OlmMachine`. + pub fn device_id(&self) -> identifiers::DeviceId { + identifiers::DeviceId { inner: self.inner.device_id().to_owned() } + } + + ///// Get the public parts of our Olm identity keys. + //pub fn identity_keys(&self) -> + + /// Get the display name of our own device. + pub fn display_name(&self) -> Promise { + let me = self.inner.clone(); + + future_to_promise(async move { + Ok(JsValue::from(me.display_name().await.map_err(any_error_to_jsvalue)?)) + }) + } + pub fn receive_sync_changes( &self, to_device_events: &str, diff --git a/examples/js/index.js b/examples/js/index.js index faf4aaf70..a9d02b11b 100644 --- a/examples/js/index.js +++ b/examples/js/index.js @@ -6,6 +6,9 @@ async function run_example() { const olm_machine = await new OlmMachine(user_id, device_id); console.log(olm_machine); + console.log('olm_machine.user_id().localpart() =', olm_machine.user_id().localpart()); + console.log('olm_machine.device_id =', olm_machine.device_id()); + console.log('olm_machine.display_name =', await olm_machine.display_name()); const to_device_events = '{}'; const changed_devices = new DeviceLists(); @@ -26,7 +29,7 @@ async function run_example() { const outgoing_requests = await olm_machine.outgoing_requests(); console.log(outgoing_requests); - console.log(JSON.parse(outgoing_requests[0].body)); + //console.log(JSON.parse(outgoing_requests[0].body)); } run_example();