Expand description
(De)serializable types for the events in the Matrix specification. These types are used by other Ruma crates.
All data exchanged over Matrix is expressed as an event. Different event types represent different actions, such as joining a room or sending a message. Events are stored and transmitted as simple JSON structures. While anyone can create a new event type for their own purposes, the Matrix specification defines a number of event types which are considered core to the protocol. This module contains Rust types for all of the event types defined by the specification and facilities for extending the event system for custom event types.
§Core event types
This module includes Rust types for all event types in the Matrix specification.
To better organize the crate, these types live in separate modules with a hierarchy that matches
the reverse domain name notation of the event type. For example, the m.room.message event
lives at ruma::events::room::message::RoomMessageEvent. Each type’s module also contains a
Rust type for that event type’s content field, and any other supporting types required by the
event’s other fields.
§Extending Ruma with custom events
For our examples we will start with a simple custom state event. ruma_event
specifies the state event’s type and its kind.
use ruma_events::macros::EventContent;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "org.example.event", kind = State, state_key_type = String)]
pub struct ExampleContent {
field: String,
}This can be used with events structs, such as passing it into
ruma::api::client::state::send_state_event’s Request.
As a more advanced example we create a reaction message event. For this event we will use a
OriginalSyncMessageLikeEvent struct but any OriginalMessageLikeEvent struct would work.
use ruma_common::OwnedEventId;
use ruma_events::{macros::EventContent, OriginalSyncMessageLikeEvent};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "rel_type")]
pub enum RelatesTo {
#[serde(rename = "m.annotation")]
Annotation {
/// The event this reaction relates to.
event_id: OwnedEventId,
/// The displayable content of the reaction.
key: String,
},
/// Since this event is not fully specified in the Matrix spec
/// it may change or types may be added, we are ready!
#[serde(rename = "m.whatever")]
Whatever,
}
/// The payload for our reaction event.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[ruma_event(type = "m.reaction", kind = MessageLike)]
pub struct ReactionEventContent {
#[serde(rename = "m.relates_to")]
pub relates_to: RelatesTo,
}
let json = serde_json::json!({
"content": {
"m.relates_to": {
"event_id": "$xxxx-xxxx",
"key": "👍",
"rel_type": "m.annotation"
}
},
"event_id": "$xxxx-xxxx",
"origin_server_ts": 1,
"sender": "@someone:example.org",
"type": "m.reaction",
"unsigned": {
"age": 85
}
});
// The downside of this event is we cannot use it with event enums,
// but could be deserialized from a `Raw<_>` that has failed to deserialize.
assert!(matches!(
serde_json::from_value::<OriginalSyncMessageLikeEvent<ReactionEventContent>>(json),
Ok(OriginalSyncMessageLikeEvent {
content: ReactionEventContent {
relates_to: RelatesTo::Annotation { key, .. },
},
..
}) if key == "👍"
));Re-exports§
pub use self::relation::BundledMessageLikeRelations;pub use self::relation::BundledStateRelations;
Modules§
- audio
- Types for extensible audio message events (MSC3927).
- beacon
- Types for the
org.matrix.msc3489.beaconevent, the unstable version ofm.beacon(MSC3489). - beacon_
info - Types for the
org.matrix.msc3489.beacon_infostate event, the unstable version ofm.beacon_info(MSC3489). - call
- Modules for events in the
m.callnamespace. - direct
- Types for the
m.directevent. - do_
not_ disturb - Types for the
dm.filament.do_not_disturbevent. - dummy
- Types for the
m.dummyevent. - emote
- Types for extensible emote message events (MSC3954).
- encrypted
- Types for extensible encrypted events (MSC3956).
- file
- Types for extensible file message events (MSC3551).
- forwarded_
room_ key - Types for the
m.forwarded_room_keyevent. - fully_
read - Types for the
m.fully_readevent. - identity_
server - Types for the
m.identity_serverevent. - ignored_
user_ list - Types for the
m.ignored_user_listevent. - image
- Types for extensible image message events (MSC3552).
- image_
pack - Types for image packs in Matrix (MSC2545).
- key
- Modules for events in the
m.keynamespace. - location
- Types for extensible location message events (MSC3488).
- macros
- Re-export of all the derives needed to create your own event types.
- marked_
unread - Types for the
m.marked_unreadevent. - media_
preview_ config - Types for the
m.media_preview_configevent. - member_
hints - Types for Matrix member hint state events (MSC4171).
- message
- Types for extensible text message events (MSC1767).
- policy
- Modules for events in the
m.policynamespace. - poll
- Modules for events in the
m.pollnamespace (MSC3381). - presence
- A presence event is represented by a struct with a set content field.
- push_
rules - Types for the
m.push_rulesevent. - reaction
- Types for the
m.reactionevent. - receipt
- Types for the
m.receiptevent. - relation
- Types describing relationships between events.
- room
- Modules for events in the
m.roomnamespace. - room_
key - Types for the
m.room_keyevent. - room_
key_ bundle - Types for the
m.room_key_bundleevent defined in MSC4268. - room_
key_ request - Types for the
m.room_key_requestevent. - rtc
- Modules for events in the
m.rtcnamespace. - secret
- Module for events in the
m.secretnamespace. - secret_
storage - Module for events in the
m.secret_storagenamespace. - space
- Types for the
m.spaceevents. - space_
order - Types for the
m.space_orderevent. - sticker
- Types for the
m.stickerevent. - tag
- Types for the
m.tagevent. - typing
- Types for the
m.typingevent. - video
- Types for extensible video message events (MSC3553).
- voice
- Types for voice message events (MSC3245).
Structs§
- Decrypted
Megolm V1Event - The decrypted payload of an
m.megolm.v1.aes-sha2event. - Decrypted
OlmV1 Event - The decrypted payload of an
m.olm.v1.curve25519-aes-sha2event. - Empty
State Key - A type that can be used as the
state_keyfor event types where that field is always empty. - Ephemeral
Room Event - An ephemeral room event.
- False
- The equivalent of the
falseboolean. - Global
Account Data Event - A global account data event.
- Initial
State Event - A minimal state event, used for creating a new room.
- Mentions
- Describes whether the event mentions other users or the room.
- Message
Like Unsigned - Extra information about a message event that is not incorporated into the event’s hash.
- OlmV1
Keys - Public keys used for an
m.olm.v1.curve25519-aes-sha2event. - Original
Message Like Event - An unredacted message-like event.
- Original
State Event - An unredacted state event.
- Original
Sync Message Like Event - An unredacted message-like event without a
room_id. - Original
Sync State Event - An unredacted state event without a
room_id. - Redacted
Message Like Event - A redacted message-like event.
- Redacted
State Event - A redacted state event.
- Redacted
Sync Message Like Event - A redacted message-like event without a
room_id. - Redacted
Sync State Event - A redacted state event without a
room_id. - Redacted
Unsigned - Extra information about a redacted event that is not incorporated into the event’s hash.
- Room
Account Data Event - A room account data event.
- State
Unsigned - Extra information about a state event that is not incorporated into the event’s hash.
- Stripped
State Event - A stripped-down state event, used for previews of rooms the user has been invited to.
- Sync
Ephemeral Room Event - An ephemeral room event without a
room_id. - ToDevice
Event - An event sent using send-to-device messaging.
- True
- The equivalent of the
trueboolean. - Unsigned
Room Redaction Event - A redaction event as found in
unsigned.redacted_because.
Enums§
- AnyEphemeral
Room Event Content - Any ephemeral room event.
- AnyFull
State Event Content - Any state event.
- AnyGlobal
Account Data Event - Any global account data event.
- AnyGlobal
Account Data Event Content - Any global account data event.
- AnyInitial
State Event - Any state event.
- AnyMessage
Like Event - Any message-like event.
- AnyMessage
Like Event Content - Any message-like event.
- AnyRoom
Account Data Event - Any room account data event.
- AnyRoom
Account Data Event Content - Any room account data event.
- AnyState
Event - Any state event.
- AnyState
Event Content - Any state event.
- AnyStripped
State Event - Any state event.
- AnySync
Ephemeral Room Event - Any ephemeral room event.
- AnySync
Message Like Event - Any message-like event.
- AnySync
State Event - Any state event.
- AnySync
Timeline Event - Any sync room event.
- AnyTimeline
Event - Any room event.
- AnyTo
Device Event - Any to-device event.
- AnyTo
Device Event Content - Any to-device event.
- Ephemeral
Room Event Type - The type of
EphemeralRoomEventthis is. - Full
State Event Content - A possibly-redacted state event content.
- Global
Account Data Event Type - The type of
GlobalAccountDataEventthis is. - Message
Like Event - A possibly-redacted message-like event.
- Message
Like Event Type - The type of
MessageLikeEventthis is. - Room
Account Data Event Type - The type of
RoomAccountDataEventthis is. - State
Event - A possibly-redacted state event.
- State
Event Type - The type of
StateEventthis is. - Sync
Message Like Event - A possibly-redacted message-like event without a
room_id. - Sync
State Event - A possibly-redacted state event without a
room_id. - Timeline
Event Type - The type of
TimelineEventthis is. - ToDevice
Event Type - The type of
ToDeviceEventthis is.
Constants§
- RECOMMENDED_
STRIPPED_ STATE_ EVENT_ TYPES - Event types that servers should send as stripped state to help clients identify a room when they can’t access the full room state.
Traits§
- Boolean
Type - A trait for types representing a boolean value.
- Ephemeral
Room Event Content - Content of an ephemeral room event.
- Event
Content From Type - Event content that can be deserialized with its event type.
- Global
Account Data Event Content - Content of a global account-data event.
- Message
Like Event Content - Content of a non-redacted message-like event.
- Possibly
Redacted State Event Content - Content of a state event.
- RawExt
- Extension trait for
Raw<T>. - Redact
Content - Trait to define the behavior of redact an event’s content object.
- Redacted
Message Like Event Content - Content of a redacted message-like event.
- Redacted
State Event Content - Content of a redacted state event.
- Room
Account Data Event Content - Content of a room-specific account-data event.
- State
Event Content - Content of a non-redacted state event.
- Static
Event Content - An event content type with a statically-known event
typevalue. - Static
State Event Content - Content of a non-redacted state event with a corresponding possibly-redacted type.
- ToDevice
Event Content - Content of a to-device event.