Skip to content

Commit 2f3ddcb

Browse files
authored
Drop conversion of DecryptedRoomEvent into TimelineEvent (#243)
matrix-org/matrix-rust-sdk@5a1909a removes the implicit conversion from DecryptedRoomEvent to TimelineEvent that we'd been relying on since d7eca6f (which in turn was due to matrix-org/matrix-rust-sdk@1d1863d). It turns out we don't really need to go via TimelineEvent. We can strip out the conversion, and then strip out some redundant Options.
2 parents 80b7749 + 65dd03b commit 2f3ddcb

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
the same event successfully decrypted.
2121
([#236](https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/236))
2222

23+
- A number of the properties and methods on `DecryptedRoomEvent` no longer return `undefined`
24+
([#243](https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/243))
25+
2326
# matrix-sdk-crypto-wasm v14.2.1
2427

2528
Update matrix-sdk-crypto to `0.11.1`, which includes:

src/machine.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ use std::{
1010

1111
use futures_util::{pin_mut, Stream, StreamExt};
1212
use js_sys::{Array, Function, JsString, Map, Promise, Set};
13-
use matrix_sdk_common::{
14-
deserialized_responses::TimelineEvent,
15-
ruma::{
16-
self, events::secret::request::SecretName, serde::Raw, OneTimeKeyAlgorithm, OwnedDeviceId,
17-
OwnedTransactionId, OwnedUserId, UInt,
18-
},
13+
use matrix_sdk_common::ruma::{
14+
self, events::secret::request::SecretName, serde::Raw, OneTimeKeyAlgorithm, OwnedDeviceId,
15+
OwnedTransactionId, OwnedUserId, UInt,
1916
};
2017
use matrix_sdk_crypto::{
2118
backups::MegolmV1BackupKey,
@@ -505,13 +502,12 @@ impl OlmMachine {
505502
responses::DecryptedRoomEvent,
506503
MegolmDecryptionError,
507504
>(async move {
508-
let room_event: TimelineEvent = me
505+
let decrypted = me
509506
.decrypt_room_event(&event, room_id.as_ref(), &decryption_settings)
510507
.await
511-
.map_err(MegolmDecryptionError::from)?
512-
.into();
508+
.map_err(MegolmDecryptionError::from)?;
513509

514-
responses::DecryptedRoomEvent::try_from(room_event).map_err(
510+
responses::DecryptedRoomEvent::try_from(decrypted).map_err(
515511
|e: UnsupportedAlgorithmError| {
516512
// This happens if we somehow encounter a room event whose encryption info we
517513
// don't understand (e.g., it is encrypted with Olm rather than

src/responses.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,38 +158,38 @@ pub struct DecryptedRoomEvent {
158158
#[wasm_bindgen(readonly)]
159159
pub event: JsString,
160160

161-
encryption_info: Option<EncryptionInfo>,
161+
encryption_info: EncryptionInfo,
162162
}
163163

164164
#[wasm_bindgen]
165165
impl DecryptedRoomEvent {
166166
/// The user ID of the event sender, note this is untrusted data
167167
/// unless the `verification_state` is as well trusted.
168168
#[wasm_bindgen(getter)]
169-
pub fn sender(&self) -> Option<identifiers::UserId> {
170-
Some(self.encryption_info.as_ref()?.sender.clone())
169+
pub fn sender(&self) -> identifiers::UserId {
170+
self.encryption_info.sender.clone()
171171
}
172172

173173
/// The device ID of the device that sent us the event, note this
174174
/// is untrusted data unless `verification_state` is as well
175175
/// trusted.
176176
#[wasm_bindgen(getter, js_name = "senderDevice")]
177177
pub fn sender_device(&self) -> Option<identifiers::DeviceId> {
178-
self.encryption_info.as_ref()?.sender_device.clone()
178+
self.encryption_info.sender_device.clone()
179179
}
180180

181181
/// The Curve25519 key of the device that created the megolm
182182
/// decryption key originally.
183183
#[wasm_bindgen(getter, js_name = "senderCurve25519Key")]
184-
pub fn sender_curve25519_key(&self) -> Option<JsString> {
185-
Some(self.encryption_info.as_ref()?.sender_curve25519_key_base64.as_str().into())
184+
pub fn sender_curve25519_key(&self) -> String {
185+
self.encryption_info.sender_curve25519_key_base64.as_str().to_owned()
186186
}
187187

188188
/// The signing Ed25519 key that have created the megolm key that
189189
/// was used to decrypt this session.
190190
#[wasm_bindgen(getter, js_name = "senderClaimedEd25519Key")]
191191
pub fn sender_claimed_ed25519_key(&self) -> Option<JsString> {
192-
Some(self.encryption_info.as_ref()?.sender_claimed_ed25519_key.as_ref()?.as_str().into())
192+
Some(self.encryption_info.sender_claimed_ed25519_key.as_ref()?.as_str().into())
193193
}
194194

195195
/// Returns an empty array
@@ -210,23 +210,19 @@ impl DecryptedRoomEvent {
210210
/// decryption. It may change in the future if a device gets
211211
/// verified or deleted.
212212
#[wasm_bindgen(js_name = "shieldState")]
213-
pub fn shield_state(&self, strict: bool) -> Option<encryption::ShieldState> {
214-
Some(self.encryption_info.as_ref()?.shield_state(strict))
213+
pub fn shield_state(&self, strict: bool) -> encryption::ShieldState {
214+
self.encryption_info.shield_state(strict)
215215
}
216216
}
217217

218-
impl TryFrom<matrix_sdk_common::deserialized_responses::TimelineEvent> for DecryptedRoomEvent {
218+
impl TryFrom<matrix_sdk_common::deserialized_responses::DecryptedRoomEvent> for DecryptedRoomEvent {
219219
type Error = UnsupportedAlgorithmError;
220220

221221
fn try_from(
222-
value: matrix_sdk_common::deserialized_responses::TimelineEvent,
222+
value: matrix_sdk_common::deserialized_responses::DecryptedRoomEvent,
223223
) -> Result<Self, Self::Error> {
224-
let encryption_info = match value.encryption_info() {
225-
None => None,
226-
Some(encryption_info) => Some(encryption_info.clone().try_into()?),
227-
};
228-
229-
Ok(Self { event: value.raw().json().get().to_owned().into(), encryption_info })
224+
let encryption_info = value.encryption_info.clone().try_into()?;
225+
Ok(Self { event: value.event.json().get().into(), encryption_info })
230226
}
231227
}
232228

0 commit comments

Comments
 (0)