1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::collections::BTreeMap;

use js_int::UInt;
use ruma_common::MilliSecondsSinceUnixEpoch;
use ruma_events::{pdu::EventHash, EventType};
use ruma_identifiers::{EventId, RoomId, ServerName, ServerSigningKeyId, UserId};
use serde_json::value::Value as JsonValue;

/// 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;

    /// 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 kind of event.
    fn kind(&self) -> EventType;

    /// The `UserId` of this PDU.
    fn content(&self) -> serde_json::Value;

    /// The state key for this event.
    fn state_key(&self) -> Option<String>;

    /// The events before this event.
    fn prev_events(&self) -> Vec<EventId>;

    /// The maximum number of `prev_events` plus 1.
    ///
    /// This is only used in state resolution version 1.
    fn depth(&self) -> &UInt;

    /// All the authenticating events for this event.
    fn auth_events(&self) -> Vec<EventId>;

    /// If this event is a redaction event this is the event it redacts.
    fn redacts(&self) -> Option<&EventId>;

    /// The `unsigned` content of this event.
    fn unsigned(&self) -> &BTreeMap<String, JsonValue>;

    fn hashes(&self) -> &EventHash;

    fn signatures(&self) -> BTreeMap<Box<ServerName>, BTreeMap<ServerSigningKeyId, String>>;
}