crypto: Store the history visibility with inbound group sessions
This can be useful to share the room history with new room members.
This commit is contained in:
parent
9e83eaf2f5
commit
1799721a5f
7 changed files with 20 additions and 1 deletions
|
@ -597,6 +597,7 @@ impl OlmMachine {
|
|||
signing_key,
|
||||
&event.content.room_id,
|
||||
session_key,
|
||||
None,
|
||||
)?;
|
||||
let event = AnyToDeviceEvent::RoomKey(event.clone());
|
||||
Ok((Some(event), Some(session)))
|
||||
|
|
|
@ -991,6 +991,8 @@ impl ReadOnlyAccount {
|
|||
return Err(());
|
||||
}
|
||||
|
||||
let visiblity = settings.history_visibility.clone();
|
||||
|
||||
let outbound = OutboundGroupSession::new(
|
||||
self.device_id.clone(),
|
||||
self.identity_keys.clone(),
|
||||
|
@ -1007,6 +1009,7 @@ impl ReadOnlyAccount {
|
|||
signing_key,
|
||||
&room_id,
|
||||
outbound.session_key().await,
|
||||
Some(visiblity),
|
||||
)
|
||||
.expect("Can't create inbound group session from a newly created outbound group session");
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ pub use olm_rs::{
|
|||
use matrix_sdk_common::{
|
||||
events::{
|
||||
forwarded_room_key::ForwardedRoomKeyToDeviceEventContent,
|
||||
room::encrypted::EncryptedEventContent, AnySyncRoomEvent, SyncMessageEvent,
|
||||
room::{encrypted::EncryptedEventContent, history_visibility::HistoryVisibility},
|
||||
AnySyncRoomEvent, SyncMessageEvent,
|
||||
},
|
||||
identifiers::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, RoomId},
|
||||
locks::Mutex,
|
||||
|
@ -56,6 +57,7 @@ use crate::error::{EventError, MegolmResult};
|
|||
#[derive(Clone)]
|
||||
pub struct InboundGroupSession {
|
||||
inner: Arc<Mutex<OlmInboundGroupSession>>,
|
||||
history_visibility: Arc<Option<HistoryVisibility>>,
|
||||
session_id: Arc<str>,
|
||||
first_known_index: u32,
|
||||
pub(crate) sender_key: Arc<str>,
|
||||
|
@ -87,6 +89,7 @@ impl InboundGroupSession {
|
|||
signing_key: &str,
|
||||
room_id: &RoomId,
|
||||
session_key: GroupSessionKey,
|
||||
history_visibility: Option<HistoryVisibility>,
|
||||
) -> Result<Self, OlmGroupSessionError> {
|
||||
let session = OlmInboundGroupSession::new(&session_key.0)?;
|
||||
let session_id = session.session_id();
|
||||
|
@ -98,6 +101,7 @@ impl InboundGroupSession {
|
|||
Ok(InboundGroupSession {
|
||||
inner: Arc::new(Mutex::new(session)),
|
||||
session_id: session_id.into(),
|
||||
history_visibility: history_visibility.into(),
|
||||
sender_key: sender_key.to_owned().into(),
|
||||
first_known_index,
|
||||
signing_key: Arc::new(keys),
|
||||
|
@ -152,6 +156,7 @@ impl InboundGroupSession {
|
|||
session_id: content.session_id.as_str().into(),
|
||||
sender_key: content.sender_key.as_str().into(),
|
||||
first_known_index,
|
||||
history_visibility: None.into(),
|
||||
signing_key: Arc::new(sender_claimed_key),
|
||||
room_id: Arc::new(content.room_id.clone()),
|
||||
forwarding_chains: Arc::new(Mutex::new(Some(forwarding_chains))),
|
||||
|
@ -175,6 +180,7 @@ impl InboundGroupSession {
|
|||
room_id: (&*self.room_id).clone(),
|
||||
forwarding_chains: self.forwarding_chains.lock().await.clone(),
|
||||
imported: *self.imported,
|
||||
history_visibility: self.history_visibility.as_ref().clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -243,6 +249,7 @@ impl InboundGroupSession {
|
|||
inner: Arc::new(Mutex::new(session)),
|
||||
session_id: session_id.into(),
|
||||
sender_key: pickle.sender_key.into(),
|
||||
history_visibility: pickle.history_visibility.into(),
|
||||
first_known_index,
|
||||
signing_key: Arc::new(pickle.signing_key),
|
||||
room_id: Arc::new(pickle.room_id),
|
||||
|
@ -376,6 +383,8 @@ pub struct PickledInboundGroupSession {
|
|||
/// Flag remembering if the session was dirrectly sent to us by the sender
|
||||
/// or if it was imported.
|
||||
pub imported: bool,
|
||||
/// History visiblity of the room when the session was created.
|
||||
pub history_visibility: Option<HistoryVisibility>,
|
||||
}
|
||||
|
||||
/// The typed representation of a base64 encoded string of the GroupSession pickle.
|
||||
|
@ -412,6 +421,7 @@ impl TryFrom<ExportedRoomKey> for InboundGroupSession {
|
|||
inner: Arc::new(Mutex::new(session)),
|
||||
session_id: key.session_id.into(),
|
||||
sender_key: key.sender_key.into(),
|
||||
history_visibility: None.into(),
|
||||
first_known_index,
|
||||
signing_key: Arc::new(key.sender_claimed_keys),
|
||||
room_id: Arc::new(key.room_id),
|
||||
|
|
|
@ -233,6 +233,7 @@ pub(crate) mod test {
|
|||
"test_key",
|
||||
&room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -254,6 +254,7 @@ mod test {
|
|||
"test_key",
|
||||
&room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -286,6 +286,7 @@ mod test {
|
|||
"test_key",
|
||||
&room_id,
|
||||
outbound.session_key().await,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -857,6 +857,7 @@ mod test {
|
|||
identity_keys.ed25519(),
|
||||
&room_id!("!test:localhost"),
|
||||
GroupSessionKey(outbound_session.session_key()),
|
||||
None,
|
||||
)
|
||||
.expect("Can't create session");
|
||||
|
||||
|
@ -882,6 +883,7 @@ mod test {
|
|||
identity_keys.ed25519(),
|
||||
&room_id!("!test:localhost"),
|
||||
GroupSessionKey(outbound_session.session_key()),
|
||||
None,
|
||||
)
|
||||
.expect("Can't create session");
|
||||
|
||||
|
|
Loading…
Reference in a new issue