Skip to content

Commit 7e44fbc

Browse files
committed
crypto: Wire up save_inbound_group_sessions to room_keys_received stream
#3448 added a new method `save_inbound_group_sessions` to `CrytoStore`, but forgot to wire it up to the `room_keys_received` stream.
1 parent dcc32da commit 7e44fbc

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

crates/matrix-sdk-crypto/src/store/crypto_store_wrapper.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use tracing::warn;
1010

1111
use super::{DeviceChanges, IdentityChanges, LockableCryptoStore};
1212
use crate::{
13+
olm::InboundGroupSession,
1314
store,
1415
store::{Changes, DynCryptoStore, IntoCryptoStore, RoomKeyInfo},
1516
GossippedSecret, ReadOnlyOwnUserIdentity,
@@ -95,6 +96,31 @@ impl CryptoStoreWrapper {
9596
Ok(())
9697
}
9798

99+
/// Save a list of inbound group sessions to the store.
100+
///
101+
/// # Arguments
102+
///
103+
/// * `sessions` - The sessions to be saved.
104+
/// * `backed_up_to_version` - If the keys should be marked as having been
105+
/// backed up, the version of the backup.
106+
///
107+
/// Note: some implementations ignore `backup_version` and assume the
108+
/// current backup version, which is normally the same.
109+
pub async fn save_inbound_group_sessions(
110+
&self,
111+
sessions: Vec<InboundGroupSession>,
112+
backed_up_to_version: Option<&str>,
113+
) -> store::Result<()> {
114+
let room_key_updates: Vec<_> = sessions.iter().map(RoomKeyInfo::from).collect();
115+
self.store.save_inbound_group_sessions(sessions, backed_up_to_version).await?;
116+
117+
if !room_key_updates.is_empty() {
118+
// Ignore the result. It can only fail if there are no listeners.
119+
let _ = self.room_keys_received_sender.send(room_key_updates);
120+
}
121+
Ok(())
122+
}
123+
98124
/// Receive notifications of room keys being received as a [`Stream`].
99125
///
100126
/// Each time a room key is updated in any way, an update will be sent to

crates/matrix-sdk-crypto/src/store/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,29 @@ mod tests {
18691869

18701870
use crate::{machine::tests::get_machine_pair, types::EventEncryptionAlgorithm};
18711871

1872+
#[async_test]
1873+
async fn import_room_keys_notifies_stream() {
1874+
use futures_util::FutureExt;
1875+
1876+
let (alice, bob, _) =
1877+
get_machine_pair(user_id!("@a:s.co"), user_id!("@b:s.co"), false).await;
1878+
1879+
let room1_id = room_id!("!room1:localhost");
1880+
alice.create_outbound_group_session_with_defaults_test_helper(room1_id).await.unwrap();
1881+
let exported_sessions = alice.store().export_room_keys(|_| true).await.unwrap();
1882+
1883+
let mut room_keys_received_stream = Box::pin(bob.store().room_keys_received_stream());
1884+
bob.store().import_room_keys(exported_sessions, None, |_, _| {}).await.unwrap();
1885+
1886+
let room_keys = room_keys_received_stream
1887+
.next()
1888+
.now_or_never()
1889+
.flatten()
1890+
.expect("We should have received an update of room key infos");
1891+
assert_eq!(room_keys.len(), 1);
1892+
assert_eq!(room_keys[0].room_id, "!room1:localhost");
1893+
}
1894+
18721895
#[async_test]
18731896
async fn export_room_keys_provides_selected_keys() {
18741897
// Given an OlmMachine with room keys in it

0 commit comments

Comments
 (0)