Skip to content

Commit

Permalink
feat: Introduce UserId.clone.
Browse files Browse the repository at this point in the history
This can be helpful when the `user_id` is dropped on the Rust side.
  • Loading branch information
Hywan committed Jan 8, 2024
1 parent c556316 commit 59d19ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ impl UserId {
pub fn to_string(&self) -> String {
self.inner.as_str().to_owned()
}

/// Clone this `UserId`.
#[wasm_bindgen(js_name = "clone")]
pub fn clone_me(&self) -> Self {
self.clone()
}
}

/// A Matrix key ID.
Expand Down
8 changes: 5 additions & 3 deletions tests/machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe(OlmMachine.name, () => {
test("can update tracked users", async () => {
const m = await machine();

expect(await m.updateTrackedUsers([new UserId("@alice:example.org")])).toStrictEqual(undefined);
expect(await m.updateTrackedUsers([user.clone()])).toStrictEqual(undefined);
});

test("can receive sync changes", async () => {
Expand Down Expand Up @@ -509,7 +509,9 @@ describe(OlmMachine.name, () => {
});

test("can share a room key", async () => {
const requests = await m.shareRoomKey(room, [new UserId("@example:localhost")], new EncryptionSettings());
const other_user_id = new UserId("@example:localhost");

const requests = await m.shareRoomKey(room, [other_user_id.clone()], new EncryptionSettings());

expect(requests).toHaveLength(1);
expect(requests[0]).toBeInstanceOf(ToDeviceRequest);
Expand All @@ -523,7 +525,7 @@ describe(OlmMachine.name, () => {

await m.markRequestAsSent(requests[0].id, RequestType.ToDevice, "{}");

const requestsAfterMarkedAsSent = await m.shareRoomKey(room, [new UserId("@example:localhost")], new EncryptionSettings());
const requestsAfterMarkedAsSent = await m.shareRoomKey(room, [other_user_id.clone()], new EncryptionSettings());
expect(requestsAfterMarkedAsSent).toHaveLength(0);
});

Expand Down

0 comments on commit 59d19ff

Please sign in to comment.