Skip to content

Commit 20246ba

Browse files
committed
feat(crypto): Store sender in RoomKeyWithheldEntry::Bundle.
1 parent a98f852 commit 20246ba

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ use crate::{
7777
Session, StaticAccountData,
7878
},
7979
types::{
80-
events::room_key_withheld::MegolmV1AesSha2WithheldContent, BackupSecrets,
81-
CrossSigningSecrets, MegolmBackupV1Curve25519AesSha2Secrets, RoomKeyExport, SecretsBundle,
80+
events::room_key_withheld::{MegolmV1AesSha2WithheldContent, RoomKeyWithheldEntry},
81+
BackupSecrets, CrossSigningSecrets, MegolmBackupV1Curve25519AesSha2Secrets, RoomKeyExport,
82+
SecretsBundle,
8283
},
8384
verification::VerificationMachine,
8485
CrossSigningStatus, OwnUserIdentityData, RoomKeyImportResult,
@@ -1692,11 +1693,13 @@ impl Store {
16921693
| MegolmV1AesSha2WithheldContent::Unavailable(c),
16931694
) = withheld
16941695
{
1695-
changes
1696-
.withheld_session_info
1697-
.entry(c.room_id.to_owned())
1698-
.or_default()
1699-
.insert(c.session_id.to_owned(), withheld.to_owned().into());
1696+
changes.withheld_session_info.entry(c.room_id.to_owned()).or_default().insert(
1697+
c.session_id.to_owned(),
1698+
RoomKeyWithheldEntry::Bundle {
1699+
sender: bundle_info.sender_user.clone(),
1700+
content: withheld.to_owned(),
1701+
},
1702+
);
17001703
}
17011704
}
17021705
self.save_changes(changes).await?;
@@ -2079,9 +2082,12 @@ mod tests {
20792082

20802083
assert_matches!(
20812084
bob.store().get_withheld_info(room_id, sessions[1].session_id()).await.unwrap(),
2082-
Some(RoomKeyWithheldEntry::Bundle(RoomKeyWithheldContent::MegolmV1AesSha2(
2083-
MegolmV1AesSha2WithheldContent::Unauthorised(_)
2084-
)))
2085+
Some(RoomKeyWithheldEntry::Bundle {
2086+
content: RoomKeyWithheldContent::MegolmV1AesSha2(
2087+
MegolmV1AesSha2WithheldContent::Unauthorised(_)
2088+
),
2089+
..
2090+
})
20852091
);
20862092
}
20872093

crates/matrix-sdk-crypto/src/types/events/room_key_withheld.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
use std::collections::BTreeMap;
1818

1919
use matrix_sdk_common::deserialized_responses::WithheldCode;
20-
use ruma::{events::AnyToDeviceEventContent, serde::JsonCastable, OwnedDeviceId, OwnedRoomId};
20+
use ruma::{
21+
events::AnyToDeviceEventContent, serde::JsonCastable, OwnedDeviceId, OwnedRoomId, OwnedUserId,
22+
UserId,
23+
};
2124
use serde::{Deserialize, Serialize};
2225
use serde_json::Value;
2326
use vodozemac::Curve25519PublicKey;
@@ -33,15 +36,28 @@ pub enum RoomKeyWithheldEntry {
3336
/// A to-device event containing withheld room key information.
3437
ToDevice(RoomKeyWithheldEvent),
3538
/// Content held within a room key bundle.
36-
Bundle(RoomKeyWithheldContent),
39+
Bundle {
40+
/// The ID of the user who sent the bundle.
41+
sender: OwnedUserId,
42+
/// The contents of a single withheld entry in the bundle.
43+
content: RoomKeyWithheldContent,
44+
},
3745
}
3846

3947
impl RoomKeyWithheldEntry {
4048
/// Returns a reference to the underlying `RoomKeyWithheldContent`.
4149
pub fn content(&self) -> &RoomKeyWithheldContent {
4250
match self {
4351
RoomKeyWithheldEntry::ToDevice(ev) => &ev.content,
44-
RoomKeyWithheldEntry::Bundle(content) => content,
52+
RoomKeyWithheldEntry::Bundle { content, .. } => content,
53+
}
54+
}
55+
56+
/// Returns the sender's user ID, if available.
57+
pub fn sender(&self) -> &UserId {
58+
match self {
59+
RoomKeyWithheldEntry::ToDevice(ev) => &ev.sender,
60+
RoomKeyWithheldEntry::Bundle { sender, .. } => sender,
4561
}
4662
}
4763
}
@@ -52,12 +68,6 @@ impl From<RoomKeyWithheldEvent> for RoomKeyWithheldEntry {
5268
}
5369
}
5470

55-
impl From<RoomKeyWithheldContent> for RoomKeyWithheldEntry {
56-
fn from(value: RoomKeyWithheldContent) -> Self {
57-
Self::Bundle(value)
58-
}
59-
}
60-
6171
/// The `m.room_key_request` to-device event.
6272
pub type RoomKeyWithheldEvent = ToDeviceEvent<RoomKeyWithheldContent>;
6373

0 commit comments

Comments
 (0)