events: Added shared_history flag to room key events

Signed-off-by: Michael Hollister <michael@futo.org>
Co-authored-by: Kévin Commaille <76261501+zecakeh@users.noreply.github.com>
This commit is contained in:
Michael Hollister 2023-10-06 02:37:29 -05:00 committed by GitHub
parent d665a7b571
commit 7b898bf376
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 1 deletions

View file

@ -22,6 +22,7 @@ unstable-exhaustive-types = []
unstable-msc1767 = []
unstable-msc2448 = []
unstable-msc2747 = []
unstable-msc3061 = []
unstable-msc3245 = ["unstable-msc3246"]
# Support the m.room.message fallback fields from the first version of MSC3245,
# implemented in Element Web and documented at

View file

@ -43,6 +43,17 @@ pub struct ToDeviceForwardedRoomKeyEventContent {
/// key is forwarded from A to B to C, this field is empty between A and B, and contains
/// A's Curve25519 key between B and C.
pub forwarding_curve25519_key_chain: Vec<String>,
/// Used to mark key if allowed for shared history.
///
/// Defaults to `false`.
#[cfg(feature = "unstable-msc3061")]
#[serde(
default,
rename = "org.matrix.msc3061.shared_history",
skip_serializing_if = "ruma_common::serde::is_default"
)]
pub shared_history: bool,
}
/// Initial set of fields of `ToDeviceForwardedRoomKeyEventContent`.
@ -93,6 +104,8 @@ impl From<ToDeviceForwardedRoomKeyEventContentInit> for ToDeviceForwardedRoomKey
session_key: init.session_key,
sender_claimed_ed25519_key: init.sender_claimed_ed25519_key,
forwarding_curve25519_key_chain: init.forwarding_curve25519_key_chain,
#[cfg(feature = "unstable-msc3061")]
shared_history: false,
}
}
}

View file

@ -26,6 +26,17 @@ pub struct ToDeviceRoomKeyEventContent {
/// The key to be exchanged.
pub session_key: String,
/// Used to mark key if allowed for shared history.
///
/// Defaults to `false`.
#[cfg(feature = "unstable-msc3061")]
#[serde(
default,
rename = "org.matrix.msc3061.shared_history",
skip_serializing_if = "ruma_common::serde::is_default"
)]
pub shared_history: bool,
}
impl ToDeviceRoomKeyEventContent {
@ -37,7 +48,14 @@ impl ToDeviceRoomKeyEventContent {
session_id: String,
session_key: String,
) -> Self {
Self { algorithm, room_id, session_id, session_key }
Self {
algorithm,
room_id,
session_id,
session_key,
#[cfg(feature = "unstable-msc3061")]
shared_history: false,
}
}
}
@ -56,8 +74,11 @@ mod tests {
room_id: owned_room_id!("!testroomid:example.org"),
session_id: "SessId".into(),
session_key: "SessKey".into(),
#[cfg(feature = "unstable-msc3061")]
shared_history: true,
};
#[cfg(not(feature = "unstable-msc3061"))]
assert_eq!(
to_json_value(content).unwrap(),
json!({
@ -67,5 +88,17 @@ mod tests {
"session_key": "SessKey",
})
);
#[cfg(feature = "unstable-msc3061")]
assert_eq!(
to_json_value(content).unwrap(),
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!testroomid:example.org",
"session_id": "SessId",
"session_key": "SessKey",
"org.matrix.msc3061.shared_history": true,
})
);
}
}

View file

@ -186,6 +186,7 @@ unstable-msc2747 = ["ruma-events?/unstable-msc2747"]
unstable-msc2870 = ["ruma-common/unstable-msc2870"]
unstable-msc2965 = ["ruma-client-api?/unstable-msc2965"]
unstable-msc2967 = ["ruma-client-api?/unstable-msc2967"]
unstable-msc3061 = ["ruma-events?/unstable-msc3061"]
unstable-msc3202 = ["ruma-appservice-api?/unstable-msc3202"]
unstable-msc3245 = ["ruma-events?/unstable-msc3245"]
# Support the m.room.message fallback fields from the first version of MSC3245,
@ -232,6 +233,7 @@ __ci = [
"unstable-msc2870",
"unstable-msc2965",
"unstable-msc2967",
"unstable-msc3061",
"unstable-msc3202",
"unstable-msc3245",
"unstable-msc3245-v1-compat",