diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 8af784eb4..3d1be6b74 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -423,14 +423,7 @@ impl BaseClient { ), ); } - // TODO if there is an - // Action::SetTweak(Tweak::Highlight) we need to store - // its value with the event so a client can show if the - // event is highlighted - // in the UI. - // Requires the possibility to associate custom data - // with events and to - // store them. + event.push_actions = actions.to_owned(); } } Err(e) => { diff --git a/crates/matrix-sdk-common/src/deserialized_responses.rs b/crates/matrix-sdk-common/src/deserialized_responses.rs index 91bf0eaa2..b3d6ff29d 100644 --- a/crates/matrix-sdk-common/src/deserialized_responses.rs +++ b/crates/matrix-sdk-common/src/deserialized_responses.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use ruma::{ events::{AnySyncTimelineEvent, AnyTimelineEvent}, + push::Action, serde::Raw, DeviceKeyAlgorithm, OwnedDeviceId, OwnedEventId, OwnedUserId, }; @@ -59,6 +60,9 @@ pub struct SyncTimelineEvent { /// The encryption info about the event. Will be `None` if the event was not /// encrypted. pub encryption_info: Option, + /// The push actions associated with this event. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub push_actions: Vec, } impl SyncTimelineEvent { @@ -71,7 +75,7 @@ impl SyncTimelineEvent { impl From> for SyncTimelineEvent { fn from(inner: Raw) -> Self { - Self { encryption_info: None, event: inner } + Self { encryption_info: None, event: inner, push_actions: Vec::default() } } } @@ -81,7 +85,11 @@ impl From for SyncTimelineEvent { // `TimelineEvent` without the `room_id`. By converting the raw value in // this way, we simply cause the `room_id` field in the json to be // ignored by a subsequent deserialization. - Self { encryption_info: o.encryption_info, event: o.event.cast() } + Self { + encryption_info: o.encryption_info, + event: o.event.cast(), + push_actions: o.push_actions, + } } } @@ -92,6 +100,8 @@ pub struct TimelineEvent { /// The encryption info about the event. Will be `None` if the event was not /// encrypted. pub encryption_info: Option, + /// The push actions associated with this event. + pub push_actions: Vec, } #[cfg(test)] @@ -115,8 +125,11 @@ mod tests { "sender": "@carl:example.com", }); - let room_event = - TimelineEvent { event: Raw::new(&event).unwrap().cast(), encryption_info: None }; + let room_event = TimelineEvent { + event: Raw::new(&event).unwrap().cast(), + encryption_info: None, + push_actions: Vec::default(), + }; let converted_room_event: SyncTimelineEvent = room_event.into(); diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index fb8afe13a..8bb322fd0 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -1178,7 +1178,11 @@ impl OlmMachine { let (decrypted_event, _) = session.decrypt(event).await?; let encryption_info = self.get_encryption_info(&session, &event.sender).await?; - Ok(TimelineEvent { encryption_info: Some(encryption_info), event: decrypted_event }) + Ok(TimelineEvent { + encryption_info: Some(encryption_info), + event: decrypted_event, + push_actions: Vec::default(), + }) } else { Err(MegolmError::MissingRoomKey) } diff --git a/crates/matrix-sdk/src/room/common.rs b/crates/matrix-sdk/src/room/common.rs index 60c070963..c633ed487 100644 --- a/crates/matrix-sdk/src/room/common.rs +++ b/crates/matrix-sdk/src/room/common.rs @@ -211,7 +211,11 @@ impl Common { chunk: http_response .chunk .into_iter() - .map(|event| TimelineEvent { event, encryption_info: None }) + .map(|event| TimelineEvent { + event, + encryption_info: None, + push_actions: Vec::default(), + }) .collect(), #[cfg(feature = "e2e-encryption")] chunk: Vec::with_capacity(http_response.chunk.len()), @@ -228,21 +232,20 @@ impl Common { if let Ok(event) = machine.decrypt_room_event(event.cast_ref(), room_id).await { event } else { - TimelineEvent { event, encryption_info: None } + TimelineEvent { event, encryption_info: None, push_actions: Vec::default() } } } else { - TimelineEvent { event, encryption_info: None } + TimelineEvent { event, encryption_info: None, push_actions: Vec::default() } }; response.chunk.push(decrypted_event); } } else { - response.chunk.extend( - http_response - .chunk - .into_iter() - .map(|event| TimelineEvent { event, encryption_info: None }), - ); + response.chunk.extend(http_response.chunk.into_iter().map(|event| TimelineEvent { + event, + encryption_info: None, + push_actions: Vec::default(), + })); } Ok(response) @@ -291,11 +294,11 @@ impl Common { return Ok(event); } } - Ok(TimelineEvent { event, encryption_info: None }) + Ok(TimelineEvent { event, encryption_info: None, push_actions: Vec::default() }) } #[cfg(not(feature = "e2e-encryption"))] - Ok(TimelineEvent { event, encryption_info: None }) + Ok(TimelineEvent { event, encryption_info: None, push_actions: Vec::default() }) } pub(crate) async fn request_members(&self) -> Result> { diff --git a/crates/matrix-sdk/src/room/timeline/tests/basic.rs b/crates/matrix-sdk/src/room/timeline/tests/basic.rs index 99ce74850..e8ead03fe 100644 --- a/crates/matrix-sdk/src/room/timeline/tests/basic.rs +++ b/crates/matrix-sdk/src/room/timeline/tests/basic.rs @@ -30,7 +30,7 @@ use crate::room::timeline::{ fn sync_timeline_event(event: JsonValue) -> SyncTimelineEvent { let event = serde_json::from_value(event).unwrap(); - SyncTimelineEvent { event, encryption_info: None } + SyncTimelineEvent { event, encryption_info: None, push_actions: Vec::default() } } #[async_test] diff --git a/crates/matrix-sdk/src/room/timeline/tests/mod.rs b/crates/matrix-sdk/src/room/timeline/tests/mod.rs index 15e9bb717..00c8ac746 100644 --- a/crates/matrix-sdk/src/room/timeline/tests/mod.rs +++ b/crates/matrix-sdk/src/room/timeline/tests/mod.rs @@ -163,8 +163,11 @@ impl TestTimeline { } async fn handle_back_paginated_custom_event(&self, event: JsonValue) { - let timeline_event = - TimelineEvent { event: Raw::new(&event).unwrap().cast(), encryption_info: None }; + let timeline_event = TimelineEvent { + event: Raw::new(&event).unwrap().cast(), + encryption_info: None, + push_actions: Vec::default(), + }; self.inner.handle_back_paginated_event(timeline_event).await; } diff --git a/crates/matrix-sdk/src/sliding_sync/room.rs b/crates/matrix-sdk/src/sliding_sync/room.rs index 19c1e2728..1abaa7dd8 100644 --- a/crates/matrix-sdk/src/sliding_sync/room.rs +++ b/crates/matrix-sdk/src/sliding_sync/room.rs @@ -380,6 +380,7 @@ mod tests { .unwrap() .cast(), encryption_info: None, + push_actions: Vec::default(), } .into()], };