Skip to content

Commit 87de0b5

Browse files
committed
Return broken messages unchanged from messages()
Without this change, a batch with a message that cannot be deserialized (for whatever reason) means that the batch cannot be processed at all by the caller. Now, those messages are returned unchanged in the batch so that the caller can handle them.
1 parent 5003ed1 commit 87de0b5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

crates/matrix-sdk/src/room/common.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ impl Common {
132132
/// returns a `Messages` struct that contains a chunk of room and state
133133
/// events (`RoomEvent` and `AnyStateEvent`).
134134
///
135+
/// With the encryption feature, messages are decrypted if possible. If
136+
/// decryption fails for an individual message, that message is returned
137+
/// undecrypted.
138+
///
135139
/// # Arguments
136140
///
137141
/// * `request` - The easiest way to create this request is using the
@@ -175,14 +179,19 @@ impl Common {
175179
state: http_response.state,
176180
};
177181

178-
for event in &http_response.chunk {
179-
let event = event.deserialize()?;
180-
182+
for event in http_response.chunk {
181183
#[cfg(feature = "encryption")]
182-
let event = self.client.decrypt_room_event(&event).await?;
184+
let event = match event.deserialize() {
185+
Ok(event) => self.client.decrypt_room_event(&event).await?,
186+
Err(_) => {
187+
// "Broken" messages (i.e., those that cannot be deserialized) are
188+
// returned unchanged so that the caller can handle them individually.
189+
RoomEvent { event, encryption_info: None }
190+
}
191+
};
183192

184193
#[cfg(not(feature = "encryption"))]
185-
let event = RoomEvent { event: Raw::new(&event)?, encryption_info: None };
194+
let event = RoomEvent { event, encryption_info: None };
186195

187196
response.chunk.push(event);
188197
}

0 commit comments

Comments
 (0)