mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-05 22:47:02 -04:00
feat(crypto-js): Implement OlmMachine.update_tracked_users.
This commit is contained in:
@@ -83,6 +83,31 @@ impl OlmMachine {
|
||||
set
|
||||
}
|
||||
|
||||
/// Update the tracked users.
|
||||
///
|
||||
/// `users` is an iterator over user IDs that should be marked for
|
||||
/// tracking.
|
||||
///
|
||||
/// This will mark users that weren't seen before for a key query
|
||||
/// and tracking.
|
||||
///
|
||||
/// If the user is already known to the Olm machine, it will not
|
||||
/// be considered for a key query.
|
||||
#[wasm_bindgen(js_name = "updateTrackedUsers")]
|
||||
pub fn update_tracked_users(&self, users: &Array) -> Result<Promise, JsError> {
|
||||
let users = users
|
||||
.iter()
|
||||
.map(|user| Ok(downcast::<identifiers::UserId>(&user, "UserId")?.inner.clone()))
|
||||
.collect::<Result<Vec<ruma::OwnedUserId>, JsError>>()?;
|
||||
|
||||
let me = self.inner.clone();
|
||||
|
||||
Ok(future_to_promise(async move {
|
||||
me.update_tracked_users(users.iter().map(AsRef::as_ref)).await;
|
||||
Ok(JsValue::UNDEFINED)
|
||||
}))
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "receiveSyncChanges")]
|
||||
pub fn receive_sync_changes(
|
||||
&self,
|
||||
|
||||
@@ -65,6 +65,13 @@ test('OlmMachine', async (t) => {
|
||||
assert.equal(tracked_users.size, 0, 'No tracked users by default');
|
||||
});
|
||||
|
||||
await t.test('Update tracked users', async (t) => {
|
||||
const machine = await new OlmMachine(user_id, device_id);
|
||||
const update_tracked_users = await machine.updateTrackedUsers([new UserId('@foo:matrix.org'), new UserId('@bar:matrix.org')]);
|
||||
|
||||
assert.equal(update_tracked_users, undefined, 'Updating tracked users returns nothing');
|
||||
});
|
||||
|
||||
await t.test('Receive sync changes', async (t) => {
|
||||
const machine = await new OlmMachine(user_id, device_id);
|
||||
const to_device_events = JSON.stringify({});
|
||||
|
||||
Reference in New Issue
Block a user