Files
tuwunel/src/core/matrix/event.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
2.0 KiB
Rust
Raw Normal View History

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.
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).
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).
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.
fn redacts(&self) -> Option<&EventId>;
2025-02-05 12:22:22 +00:00
}
impl<T: Event> Event for &T {
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() }
fn prev_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Send + '_ {
2025-02-05 12:22:22 +00:00
(*self).prev_events()
}
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Send + '_ {
2025-02-05 12:22:22 +00:00
(*self).auth_events()
}
fn redacts(&self) -> Option<&EventId> { (*self).redacts() }
2025-02-05 12:22:22 +00:00
}