Add extra_content field to events and add Custom event variant.
This commit is contained in:
parent
b84fc9b23e
commit
05ae55abea
31
src/lib.rs
31
src/lib.rs
@ -26,6 +26,8 @@ pub struct Event<T> where T: Deserialize + Serialize {
|
|||||||
pub content: T,
|
pub content: T,
|
||||||
#[serde(rename="type")]
|
#[serde(rename="type")]
|
||||||
pub event_type: EventType,
|
pub event_type: EventType,
|
||||||
|
/// Extra key-value pairs to be mixed into the top-level JSON representation of the event.
|
||||||
|
pub extra_content: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type that represents a kind of Matrix event.
|
/// A type that represents a kind of Matrix event.
|
||||||
@ -37,28 +39,52 @@ pub trait EventKind: Deserialize + Serialize {}
|
|||||||
/// The type of an event.
|
/// The type of an event.
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub enum EventType {
|
pub enum EventType {
|
||||||
|
/// m.call.answer
|
||||||
CallAnswer,
|
CallAnswer,
|
||||||
|
/// m.call.candidates
|
||||||
CallCandidates,
|
CallCandidates,
|
||||||
|
/// m.call.hangup
|
||||||
CallHangup,
|
CallHangup,
|
||||||
|
/// m.call.invite
|
||||||
CallInvite,
|
CallInvite,
|
||||||
|
/// m.presence
|
||||||
Presence,
|
Presence,
|
||||||
|
/// m.receipt
|
||||||
Receipt,
|
Receipt,
|
||||||
|
/// m.room.aliases
|
||||||
RoomAliases,
|
RoomAliases,
|
||||||
|
/// m.room.avatar
|
||||||
RoomAvatar,
|
RoomAvatar,
|
||||||
|
/// m.room.canonical_alias
|
||||||
RoomCanonicalAlias,
|
RoomCanonicalAlias,
|
||||||
|
/// m.room.create
|
||||||
RoomCreate,
|
RoomCreate,
|
||||||
|
/// m.room.guest_access
|
||||||
RoomGuestAccess,
|
RoomGuestAccess,
|
||||||
|
/// m.room.history_visibility
|
||||||
RoomHistoryVisibility,
|
RoomHistoryVisibility,
|
||||||
|
/// m.room.join_rules
|
||||||
RoomJoinRules,
|
RoomJoinRules,
|
||||||
|
/// m.room.member
|
||||||
RoomMember,
|
RoomMember,
|
||||||
|
/// m.room.message
|
||||||
RoomMessage,
|
RoomMessage,
|
||||||
|
/// m.room.name
|
||||||
RoomName,
|
RoomName,
|
||||||
|
/// m.room.power_levels
|
||||||
RoomPowerLevels,
|
RoomPowerLevels,
|
||||||
|
/// m.room.redaction
|
||||||
RoomRedaction,
|
RoomRedaction,
|
||||||
|
/// m.room.third_party_invite
|
||||||
RoomThirdPartyInvite,
|
RoomThirdPartyInvite,
|
||||||
|
/// m.room.topic
|
||||||
RoomTopic,
|
RoomTopic,
|
||||||
|
/// m.tag
|
||||||
Tag,
|
Tag,
|
||||||
|
/// m.typing
|
||||||
Typing,
|
Typing,
|
||||||
|
/// Any event that is not part of the specification.
|
||||||
|
Custom(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An event within the context of a room.
|
/// An event within the context of a room.
|
||||||
@ -66,6 +92,8 @@ pub enum EventType {
|
|||||||
pub struct RoomEvent<T> where T: Deserialize + Serialize {
|
pub struct RoomEvent<T> where T: Deserialize + Serialize {
|
||||||
pub content: T,
|
pub content: T,
|
||||||
pub event_id: String,
|
pub event_id: String,
|
||||||
|
/// Extra key-value pairs to be mixed into the top-level JSON representation of the event.
|
||||||
|
pub extra_content: Option<Value>,
|
||||||
#[serde(rename="type")]
|
#[serde(rename="type")]
|
||||||
pub event_type: EventType,
|
pub event_type: EventType,
|
||||||
pub room_id: String,
|
pub room_id: String,
|
||||||
@ -81,6 +109,8 @@ pub struct StateEvent<T> where T: Deserialize + Serialize {
|
|||||||
pub event_id: String,
|
pub event_id: String,
|
||||||
#[serde(rename="type")]
|
#[serde(rename="type")]
|
||||||
pub event_type: EventType,
|
pub event_type: EventType,
|
||||||
|
/// Extra key-value pairs to be mixed into the top-level JSON representation of the event.
|
||||||
|
pub extra_content: Option<Value>,
|
||||||
pub prev_content: Option<T>,
|
pub prev_content: Option<T>,
|
||||||
pub room_id: String,
|
pub room_id: String,
|
||||||
pub state_key: String,
|
pub state_key: String,
|
||||||
@ -118,6 +148,7 @@ impl Display for EventType {
|
|||||||
EventType::RoomTopic => "m.room.topic",
|
EventType::RoomTopic => "m.room.topic",
|
||||||
EventType::Tag => "m.tag",
|
EventType::Tag => "m.tag",
|
||||||
EventType::Typing => "m.typing",
|
EventType::Typing => "m.typing",
|
||||||
|
EventType::Custom(ref event_type) => event_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(f, "{}", event_type_str)
|
write!(f, "{}", event_type_str)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user