2025-02-23 01:17:45 -05:00
|
|
|
use ruma::{EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId, events::TimelineEventType};
|
2025-02-05 12:22:22 +00:00
|
|
|
use serde_json::value::RawValue as RawJsonValue;
|
|
|
|
|
|
|
|
|
|
/// Abstraction of a PDU so users can have their own PDU types.
|
|
|
|
|
pub trait Event {
|
|
|
|
|
/// The `EventId` of this event.
|
2025-04-22 11:00:55 +00:00
|
|
|
fn event_id(&self) -> &EventId;
|
2025-02-05 12:22:22 +00:00
|
|
|
|
|
|
|
|
/// The `RoomId` of this event.
|
|
|
|
|
fn room_id(&self) -> &RoomId;
|
|
|
|
|
|
|
|
|
|
/// The `UserId` of this event.
|
|
|
|
|
fn sender(&self) -> &UserId;
|
|
|
|
|
|
|
|
|
|
/// The time of creation on the originating server.
|
|
|
|
|
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch;
|
|
|
|
|
|
|
|
|
|
/// The event type.
|
|
|
|
|
fn event_type(&self) -> &TimelineEventType;
|
|
|
|
|
|
|
|
|
|
/// The event's content.
|
|
|
|
|
fn content(&self) -> &RawJsonValue;
|
|
|
|
|
|
|
|
|
|
/// The state key for this event.
|
|
|
|
|
fn state_key(&self) -> Option<&str>;
|
|
|
|
|
|
|
|
|
|
/// The events before this event.
|
|
|
|
|
// Requires GATs to avoid boxing (and TAIT for making it convenient).
|
2025-04-22 11:00:55 +00:00
|
|
|
fn prev_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Send + '_;
|
2025-02-05 12:22:22 +00:00
|
|
|
|
|
|
|
|
/// All the authenticating events for this event.
|
|
|
|
|
// Requires GATs to avoid boxing (and TAIT for making it convenient).
|
2025-04-22 11:00:55 +00:00
|
|
|
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Send + '_;
|
2025-02-05 12:22:22 +00:00
|
|
|
|
|
|
|
|
/// If this event is a redaction event this is the event it redacts.
|
2025-04-22 11:00:55 +00:00
|
|
|
fn redacts(&self) -> Option<&EventId>;
|
2025-02-05 12:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T: Event> Event for &T {
|
2025-04-22 11:00:55 +00:00
|
|
|
fn event_id(&self) -> &EventId { (*self).event_id() }
|
2025-02-05 12:22:22 +00:00
|
|
|
|
|
|
|
|
fn room_id(&self) -> &RoomId { (*self).room_id() }
|
|
|
|
|
|
|
|
|
|
fn sender(&self) -> &UserId { (*self).sender() }
|
|
|
|
|
|
|
|
|
|
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch { (*self).origin_server_ts() }
|
|
|
|
|
|
|
|
|
|
fn event_type(&self) -> &TimelineEventType { (*self).event_type() }
|
|
|
|
|
|
|
|
|
|
fn content(&self) -> &RawJsonValue { (*self).content() }
|
|
|
|
|
|
|
|
|
|
fn state_key(&self) -> Option<&str> { (*self).state_key() }
|
|
|
|
|
|
2025-04-22 11:00:55 +00:00
|
|
|
fn prev_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Send + '_ {
|
2025-02-05 12:22:22 +00:00
|
|
|
(*self).prev_events()
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 11:00:55 +00:00
|
|
|
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Send + '_ {
|
2025-02-05 12:22:22 +00:00
|
|
|
(*self).auth_events()
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 11:00:55 +00:00
|
|
|
fn redacts(&self) -> Option<&EventId> { (*self).redacts() }
|
2025-02-05 12:22:22 +00:00
|
|
|
}
|