Skip to content

Commit

Permalink
common: Extract inner parts of [Sync]TimelineEvent
Browse files Browse the repository at this point in the history
Pull out the bits of these classes which are dependent on success or otherwise
of decrypting an event to a new enum.
  • Loading branch information
richvdh committed Oct 4, 2024
1 parent 0892244 commit 455bbd4
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 132 deletions.
26 changes: 23 additions & 3 deletions crates/matrix-sdk-base/src/latest_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,12 @@ mod tests {
json!({
"latest_event": {
"event": {
"encryption_info": null,
"event": {
"event_id": "$1"
"inner_event": {
"PlainText": {
"event": {
"event_id": "$1"
}
}
}
},
}
Expand All @@ -578,6 +581,23 @@ mod tests {
assert!(deserialized.latest_event.sender_name_is_ambiguous.is_none());

// The previous format can also be deserialized.
let serialized = json!({
"latest_event": {
"event": {
"encryption_info": null,
"event": {
"event_id": "$1"
}
},
}
});

let deserialized: TestStruct = serde_json::from_value(serialized).unwrap();
assert_eq!(deserialized.latest_event.event().event_id().unwrap(), "$1");
assert!(deserialized.latest_event.sender_profile.is_none());
assert!(deserialized.latest_event.sender_name_is_ambiguous.is_none());

// The even older format can also be deserialized.
let serialized = json!({
"latest_event": event
});
Expand Down
5 changes: 1 addition & 4 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,10 +1805,7 @@ mod tests {
"encryption_state_synced": true,
"latest_event": {
"event": {
"encryption_info": null,
"event": {
"sender": "@u:i.uk",
},
"inner_event": {"PlainText": {"event": {"sender": "@u:i.uk"}}},
},
},
"base_info": {
Expand Down
Loading

0 comments on commit 455bbd4

Please sign in to comment.