acter_core/models/
meta.rsuse matrix_sdk::room::Room;
use matrix_sdk_base::ruma::{
events::room::redaction::OriginalRoomRedactionEvent, MilliSecondsSinceUnixEpoch, OwnedEventId,
OwnedRoomId, OwnedUserId, UserId,
};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(any(test, feature = "testing"), derive(PartialEq, Eq))]
pub struct EventMeta {
pub event_id: OwnedEventId,
pub sender: OwnedUserId,
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
pub room_id: OwnedRoomId,
#[serde(default)]
pub(crate) redacted: Option<OwnedEventId>,
}
impl EventMeta {
pub fn for_redacted_source(value: &OriginalRoomRedactionEvent) -> Option<Self> {
let target_event_id = value.redacts.clone()?;
Some(EventMeta {
event_id: target_event_id,
sender: value.sender.clone(),
room_id: value.room_id.clone(),
origin_server_ts: value.origin_server_ts,
redacted: None,
})
}
}
pub async fn can_redact(room: &Room, sender_id: &UserId) -> crate::error::Result<bool> {
let client = room.client();
let Some(user_id) = client.user_id() else {
return Ok(false);
};
Ok(if sender_id == user_id {
room.can_user_redact_own(user_id).await?
} else {
room.can_user_redact_other(user_id).await?
})
}