matrix-sdk: Fix the encryption feature.

master
Damir Jelić 2020-09-15 18:07:00 +02:00
parent 4d431b7c9e
commit c8e459bc55
1 changed files with 14 additions and 6 deletions

View File

@ -1057,7 +1057,11 @@ impl Client {
content: impl Into<AnyMessageEventContent>, content: impl Into<AnyMessageEventContent>,
txn_id: Option<Uuid>, txn_id: Option<Uuid>,
) -> Result<send_message_event::Response> { ) -> Result<send_message_event::Response> {
let content = if cfg!(feature = "encryption") && self.is_room_encrypted(room_id).await { #[cfg(not(feature = "encryption"))]
let content: AnyMessageEventContent = content.into();
#[cfg(feature = "encryption")]
let content = if self.is_room_encrypted(room_id).await {
self.preshare_group_session(room_id).await?; self.preshare_group_session(room_id).await?;
AnyMessageEventContent::RoomEncrypted(self.base_client.encrypt(room_id, content).await?) AnyMessageEventContent::RoomEncrypted(self.base_client.encrypt(room_id, content).await?)
} else { } else {
@ -1139,12 +1143,16 @@ impl Client {
reader: &mut R, reader: &mut R,
txn_id: Option<Uuid>, txn_id: Option<Uuid>,
) -> Result<send_message_event::Response> { ) -> Result<send_message_event::Response> {
let (new_content_type, reader, keys) = let (new_content_type, reader, keys) = if self.is_room_encrypted(room_id).await {
if cfg!(feature = "encryption") && self.is_room_encrypted(room_id).await { #[cfg(feature = "encryption")]
{
let encryptor = AttachmentEncryptor::new(reader); let encryptor = AttachmentEncryptor::new(reader);
let keys = encryptor.finish(); let keys = encryptor.finish();
("application/octet-stream", reader, Some(keys)) ("application/octet-stream", reader, Some(keys))
}
#[cfg(not(feature = "encryption"))]
(content_type, reader, None)
} else { } else {
(content_type, reader, None) (content_type, reader, None)
}; };