Skip to content

Commit da657b8

Browse files
committed
Allow custom events in OlmMachine::encrypt
1 parent c79e62d commit da657b8

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

crates/matrix-sdk-base/src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use ruma::{
4545
api::client::r0::keys::claim_keys::Request as KeysClaimRequest,
4646
events::{
4747
room::{encrypted::RoomEncryptedEventContent, history_visibility::HistoryVisibility},
48-
AnyMessageEventContent, AnySyncMessageEvent,
48+
AnySyncMessageEvent, MessageEventContent,
4949
},
5050
DeviceId,
5151
};
@@ -1111,12 +1111,12 @@ impl BaseClient {
11111111
pub async fn encrypt(
11121112
&self,
11131113
room_id: &RoomId,
1114-
content: impl Into<AnyMessageEventContent>,
1114+
content: impl MessageEventContent,
11151115
) -> Result<RoomEncryptedEventContent> {
11161116
let olm = self.olm.lock().await;
11171117

11181118
match &*olm {
1119-
Some(o) => Ok(o.encrypt(room_id, content.into()).await?),
1119+
Some(o) => Ok(o.encrypt(room_id, content).await?),
11201120
None => panic!("Olm machine wasn't started"),
11211121
}
11221122
}

crates/matrix-sdk-crypto/src/machine.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use ruma::{
4444
},
4545
room_key::ToDeviceRoomKeyEvent,
4646
secret::request::SecretName,
47-
AnyMessageEventContent, AnyRoomEvent, AnyToDeviceEvent, EventContent,
47+
AnyRoomEvent, AnyToDeviceEvent, MessageEventContent,
4848
},
4949
serde::Raw,
5050
DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventEncryptionAlgorithm, RoomId, UInt, UserId,
@@ -695,9 +695,6 @@ impl OlmMachine {
695695
/// [`should_share_group_session`] method if a new group session needs to
696696
/// be shared.
697697
///
698-
/// **Note**: This method doesn't support encrypting custom events, see the
699-
/// [`encrypt_raw()`] method to do so.
700-
///
701698
/// # Arguments
702699
///
703700
/// * `room_id` - The id of the room for which the message should be
@@ -712,11 +709,10 @@ impl OlmMachine {
712709
///
713710
/// [`should_share_group_session`]: #method.should_share_group_session
714711
/// [`share_group_session`]: #method.share_group_session
715-
/// [`encrypt_raw()`]: #method.encrypt_raw
716712
pub async fn encrypt(
717713
&self,
718714
room_id: &RoomId,
719-
content: AnyMessageEventContent,
715+
content: impl MessageEventContent,
720716
) -> MegolmResult<RoomEncryptedEventContent> {
721717
let event_type = content.event_type().to_owned();
722718
let content = serde_json::to_value(content)?;
@@ -726,8 +722,8 @@ impl OlmMachine {
726722

727723
/// Encrypt a json [`Value`] content for the given room.
728724
///
729-
/// This method is equivalent to the [`encrypt()`] method but allows custom
730-
/// events to be encrypted.
725+
/// This method is equivalent to the [`encrypt()`] method but operates on an
726+
/// arbitrary JSON value instead of strongly-typed event content struct.
731727
///
732728
/// # Arguments
733729
///

0 commit comments

Comments
 (0)