mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-09 00:15:23 -04:00
sdk-base: Expose calculated push actions on event
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Jonas Platte
parent
84d83dda0a
commit
84ff8980f3
@@ -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) => {
|
||||
|
||||
@@ -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<EncryptionInfo>,
|
||||
/// The push actions associated with this event.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub push_actions: Vec<Action>,
|
||||
}
|
||||
|
||||
impl SyncTimelineEvent {
|
||||
@@ -71,7 +75,7 @@ impl SyncTimelineEvent {
|
||||
|
||||
impl From<Raw<AnySyncTimelineEvent>> for SyncTimelineEvent {
|
||||
fn from(inner: Raw<AnySyncTimelineEvent>) -> Self {
|
||||
Self { encryption_info: None, event: inner }
|
||||
Self { encryption_info: None, event: inner, push_actions: Vec::default() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +85,11 @@ impl From<TimelineEvent> 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<EncryptionInfo>,
|
||||
/// The push actions associated with this event.
|
||||
pub push_actions: Vec<Action>,
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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<Option<MembersResponse>> {
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -380,6 +380,7 @@ mod tests {
|
||||
.unwrap()
|
||||
.cast(),
|
||||
encryption_info: None,
|
||||
push_actions: Vec::default(),
|
||||
}
|
||||
.into()],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user