From c8e459bc55e45b404b89ef0ad9a90d95caa37a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 15 Sep 2020 18:07:00 +0200 Subject: [PATCH] matrix-sdk: Fix the encryption feature. --- matrix_sdk/src/client.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index 88412894..f9e4edbf 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -1057,7 +1057,11 @@ impl Client { content: impl Into, txn_id: Option, ) -> Result { - 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?; AnyMessageEventContent::RoomEncrypted(self.base_client.encrypt(room_id, content).await?) } else { @@ -1139,15 +1143,19 @@ impl Client { reader: &mut R, txn_id: Option, ) -> Result { - let (new_content_type, reader, keys) = - if cfg!(feature = "encryption") && self.is_room_encrypted(room_id).await { + let (new_content_type, reader, keys) = if self.is_room_encrypted(room_id).await { + #[cfg(feature = "encryption")] + { let encryptor = AttachmentEncryptor::new(reader); let keys = encryptor.finish(); ("application/octet-stream", reader, Some(keys)) - } else { - (content_type, reader, None) - }; + } + #[cfg(not(feature = "encryption"))] + (content_type, reader, None) + } else { + (content_type, reader, None) + }; let upload = self.upload(new_content_type, reader).await?;