Add E2EE events to EventType and collections types.

This commit is contained in:
Jimmy Cuadra 2019-06-14 23:12:18 -07:00
parent a0a9799c81
commit a0ee826828
3 changed files with 449 additions and 0 deletions

View File

@ -6,8 +6,14 @@ use crate::{
answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent,
}, },
direct::DirectEvent, direct::DirectEvent,
dummy::DummyEvent,
forwarded_room_key::ForwardedRoomKeyEvent,
fully_read::FullyReadEvent, fully_read::FullyReadEvent,
ignored_user_list::IgnoredUserListEvent, ignored_user_list::IgnoredUserListEvent,
key::verification::{
accept::AcceptEvent, cancel::CancelEvent, key::KeyEvent, mac::MacEvent,
request::RequestEvent, start::StartEvent,
},
presence::PresenceEvent, presence::PresenceEvent,
receipt::ReceiptEvent, receipt::ReceiptEvent,
room::{ room::{
@ -15,6 +21,8 @@ use crate::{
avatar::AvatarEvent, avatar::AvatarEvent,
canonical_alias::CanonicalAliasEvent, canonical_alias::CanonicalAliasEvent,
create::CreateEvent, create::CreateEvent,
encrypted::EncryptedEvent,
encryption::EncryptionEvent,
guest_access::GuestAccessEvent, guest_access::GuestAccessEvent,
history_visibility::HistoryVisibilityEvent, history_visibility::HistoryVisibilityEvent,
join_rules::JoinRulesEvent, join_rules::JoinRulesEvent,
@ -29,6 +37,8 @@ use crate::{
tombstone::TombstoneEvent, tombstone::TombstoneEvent,
topic::TopicEvent, topic::TopicEvent,
}, },
room_key::RoomKeyEvent,
room_key_request::RoomKeyRequestEvent,
sticker::StickerEvent, sticker::StickerEvent,
tag::TagEvent, tag::TagEvent,
typing::TypingEvent, typing::TypingEvent,
@ -57,12 +67,36 @@ pub enum Event {
/// m.direct /// m.direct
Direct(DirectEvent), Direct(DirectEvent),
/// m.dummy
Dummy(DummyEvent),
/// m.forwarded_room_key
ForwardedRoomKey(ForwardedRoomKeyEvent),
/// m.fully_read /// m.fully_read
FullyRead(FullyReadEvent), FullyRead(FullyReadEvent),
/// m.ignored_user_list /// m.ignored_user_list
IgnoredUserList(IgnoredUserListEvent), IgnoredUserList(IgnoredUserListEvent),
/// m.key.verification.accept
KeyVerificationAccept(AcceptEvent),
/// m.key.verification.cancel
KeyVerificationCancel(CancelEvent),
/// m.key.verification.key
KeyVerificationKey(KeyEvent),
/// m.key.verification.mac
KeyVerificationMac(MacEvent),
/// m.key.verification.request
KeyVerificationRequest(RequestEvent),
/// m.key.verification.start
KeyVerificationStart(StartEvent),
/// m.presence /// m.presence
Presence(PresenceEvent), Presence(PresenceEvent),
@ -81,6 +115,12 @@ pub enum Event {
/// m.room.create /// m.room.create
RoomCreate(CreateEvent), RoomCreate(CreateEvent),
/// m.room.encrypted
RoomEncrypted(EncryptedEvent),
/// m.room.encryption
RoomEncryption(EncryptionEvent),
/// m.room.guest_access /// m.room.guest_access
RoomGuestAccess(GuestAccessEvent), RoomGuestAccess(GuestAccessEvent),
@ -123,6 +163,12 @@ pub enum Event {
/// m.room.topic /// m.room.topic
RoomTopic(TopicEvent), RoomTopic(TopicEvent),
/// m.room_key
RoomKey(RoomKeyEvent),
/// m.room_key_request
RoomKeyRequest(RoomKeyRequestEvent),
/// m.sticker /// m.sticker
Sticker(StickerEvent), Sticker(StickerEvent),
@ -170,6 +216,12 @@ pub enum RoomEvent {
/// m.room.create /// m.room.create
RoomCreate(CreateEvent), RoomCreate(CreateEvent),
/// m.room.encrypted
RoomEncrypted(EncryptedEvent),
/// m.room.encryption
RoomEncryption(EncryptionEvent),
/// m.room.guest_access /// m.room.guest_access
RoomGuestAccess(GuestAccessEvent), RoomGuestAccess(GuestAccessEvent),
@ -238,6 +290,9 @@ pub enum StateEvent {
/// m.room.create /// m.room.create
RoomCreate(CreateEvent), RoomCreate(CreateEvent),
/// m.room.encryption
RoomEncryption(EncryptionEvent),
/// m.room.guest_access /// m.room.guest_access
RoomGuestAccess(GuestAccessEvent), RoomGuestAccess(GuestAccessEvent),
@ -286,7 +341,15 @@ impl Serialize for Event {
Event::CallHangup(ref event) => event.serialize(serializer), Event::CallHangup(ref event) => event.serialize(serializer),
Event::CallInvite(ref event) => event.serialize(serializer), Event::CallInvite(ref event) => event.serialize(serializer),
Event::Direct(ref event) => event.serialize(serializer), Event::Direct(ref event) => event.serialize(serializer),
Event::Dummy(ref event) => event.serialize(serializer),
Event::ForwardedRoomKey(ref event) => event.serialize(serializer),
Event::FullyRead(ref event) => event.serialize(serializer), Event::FullyRead(ref event) => event.serialize(serializer),
Event::KeyVerificationAccept(ref event) => event.serialize(serializer),
Event::KeyVerificationCancel(ref event) => event.serialize(serializer),
Event::KeyVerificationKey(ref event) => event.serialize(serializer),
Event::KeyVerificationMac(ref event) => event.serialize(serializer),
Event::KeyVerificationRequest(ref event) => event.serialize(serializer),
Event::KeyVerificationStart(ref event) => event.serialize(serializer),
Event::IgnoredUserList(ref event) => event.serialize(serializer), Event::IgnoredUserList(ref event) => event.serialize(serializer),
Event::Presence(ref event) => event.serialize(serializer), Event::Presence(ref event) => event.serialize(serializer),
Event::Receipt(ref event) => event.serialize(serializer), Event::Receipt(ref event) => event.serialize(serializer),
@ -294,6 +357,8 @@ impl Serialize for Event {
Event::RoomAvatar(ref event) => event.serialize(serializer), Event::RoomAvatar(ref event) => event.serialize(serializer),
Event::RoomCanonicalAlias(ref event) => event.serialize(serializer), Event::RoomCanonicalAlias(ref event) => event.serialize(serializer),
Event::RoomCreate(ref event) => event.serialize(serializer), Event::RoomCreate(ref event) => event.serialize(serializer),
Event::RoomEncrypted(ref event) => event.serialize(serializer),
Event::RoomEncryption(ref event) => event.serialize(serializer),
Event::RoomGuestAccess(ref event) => event.serialize(serializer), Event::RoomGuestAccess(ref event) => event.serialize(serializer),
Event::RoomHistoryVisibility(ref event) => event.serialize(serializer), Event::RoomHistoryVisibility(ref event) => event.serialize(serializer),
Event::RoomJoinRules(ref event) => event.serialize(serializer), Event::RoomJoinRules(ref event) => event.serialize(serializer),
@ -308,6 +373,8 @@ impl Serialize for Event {
Event::RoomThirdPartyInvite(ref event) => event.serialize(serializer), Event::RoomThirdPartyInvite(ref event) => event.serialize(serializer),
Event::RoomTombstone(ref event) => event.serialize(serializer), Event::RoomTombstone(ref event) => event.serialize(serializer),
Event::RoomTopic(ref event) => event.serialize(serializer), Event::RoomTopic(ref event) => event.serialize(serializer),
Event::RoomKey(ref event) => event.serialize(serializer),
Event::RoomKeyRequest(ref event) => event.serialize(serializer),
Event::Sticker(ref event) => event.serialize(serializer), Event::Sticker(ref event) => event.serialize(serializer),
Event::Tag(ref event) => event.serialize(serializer), Event::Tag(ref event) => event.serialize(serializer),
Event::Typing(ref event) => event.serialize(serializer), Event::Typing(ref event) => event.serialize(serializer),
@ -376,6 +443,22 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::Direct(event)) Ok(Event::Direct(event))
} }
EventType::Dummy => {
let event = match from_value::<DummyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::Dummy(event))
}
EventType::ForwardedRoomKey => {
let event = match from_value::<ForwardedRoomKeyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::ForwardedRoomKey(event))
}
EventType::FullyRead => { EventType::FullyRead => {
let event = match from_value::<FullyReadEvent>(value) { let event = match from_value::<FullyReadEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -384,6 +467,54 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::FullyRead(event)) Ok(Event::FullyRead(event))
} }
EventType::KeyVerificationAccept => {
let event = match from_value::<AcceptEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationAccept(event))
}
EventType::KeyVerificationCancel => {
let event = match from_value::<CancelEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationCancel(event))
}
EventType::KeyVerificationKey => {
let event = match from_value::<KeyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationKey(event))
}
EventType::KeyVerificationMac => {
let event = match from_value::<MacEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationMac(event))
}
EventType::KeyVerificationRequest => {
let event = match from_value::<RequestEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationRequest(event))
}
EventType::KeyVerificationStart => {
let event = match from_value::<StartEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationStart(event))
}
EventType::IgnoredUserList => { EventType::IgnoredUserList => {
let event = match from_value::<IgnoredUserListEvent>(value) { let event = match from_value::<IgnoredUserListEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -440,6 +571,22 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::RoomCreate(event)) Ok(Event::RoomCreate(event))
} }
EventType::RoomEncrypted => {
let event = match from_value::<EncryptedEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::RoomEncrypted(event))
}
EventType::RoomEncryption => {
let event = match from_value::<EncryptionEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::RoomEncryption(event))
}
EventType::RoomGuestAccess => { EventType::RoomGuestAccess => {
let event = match from_value::<GuestAccessEvent>(value) { let event = match from_value::<GuestAccessEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -552,6 +699,22 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::RoomTopic(event)) Ok(Event::RoomTopic(event))
} }
EventType::RoomKey => {
let event = match from_value::<RoomKeyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::RoomKey(event))
}
EventType::RoomKeyRequest => {
let event = match from_value::<RoomKeyRequestEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::RoomKeyRequest(event))
}
EventType::Sticker => { EventType::Sticker => {
let event = match from_value::<StickerEvent>(value) { let event = match from_value::<StickerEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -624,6 +787,8 @@ impl Serialize for RoomEvent {
RoomEvent::RoomAvatar(ref event) => event.serialize(serializer), RoomEvent::RoomAvatar(ref event) => event.serialize(serializer),
RoomEvent::RoomCanonicalAlias(ref event) => event.serialize(serializer), RoomEvent::RoomCanonicalAlias(ref event) => event.serialize(serializer),
RoomEvent::RoomCreate(ref event) => event.serialize(serializer), RoomEvent::RoomCreate(ref event) => event.serialize(serializer),
RoomEvent::RoomEncrypted(ref event) => event.serialize(serializer),
RoomEvent::RoomEncryption(ref event) => event.serialize(serializer),
RoomEvent::RoomGuestAccess(ref event) => event.serialize(serializer), RoomEvent::RoomGuestAccess(ref event) => event.serialize(serializer),
RoomEvent::RoomHistoryVisibility(ref event) => event.serialize(serializer), RoomEvent::RoomHistoryVisibility(ref event) => event.serialize(serializer),
RoomEvent::RoomJoinRules(ref event) => event.serialize(serializer), RoomEvent::RoomJoinRules(ref event) => event.serialize(serializer),
@ -727,6 +892,22 @@ impl<'de> Deserialize<'de> for RoomEvent {
Ok(RoomEvent::RoomCreate(event)) Ok(RoomEvent::RoomCreate(event))
} }
EventType::RoomEncrypted => {
let event = match from_value::<EncryptedEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(RoomEvent::RoomEncrypted(event))
}
EventType::RoomEncryption => {
let event = match from_value::<EncryptionEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(RoomEvent::RoomEncryption(event))
}
EventType::RoomGuestAccess => { EventType::RoomGuestAccess => {
let event = match from_value::<GuestAccessEvent>(value) { let event = match from_value::<GuestAccessEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -865,10 +1046,20 @@ impl<'de> Deserialize<'de> for RoomEvent {
} }
} }
EventType::Direct EventType::Direct
| EventType::Dummy
| EventType::ForwardedRoomKey
| EventType::FullyRead | EventType::FullyRead
| EventType::KeyVerificationAccept
| EventType::KeyVerificationCancel
| EventType::KeyVerificationKey
| EventType::KeyVerificationMac
| EventType::KeyVerificationRequest
| EventType::KeyVerificationStart
| EventType::IgnoredUserList | EventType::IgnoredUserList
| EventType::Presence | EventType::Presence
| EventType::Receipt | EventType::Receipt
| EventType::RoomKey
| EventType::RoomKeyRequest
| EventType::Tag | EventType::Tag
| EventType::Typing => Err(D::Error::custom("not a room event".to_string())), | EventType::Typing => Err(D::Error::custom("not a room event".to_string())),
EventType::__Nonexhaustive => { EventType::__Nonexhaustive => {
@ -888,6 +1079,7 @@ impl Serialize for StateEvent {
StateEvent::RoomAvatar(ref event) => event.serialize(serializer), StateEvent::RoomAvatar(ref event) => event.serialize(serializer),
StateEvent::RoomCanonicalAlias(ref event) => event.serialize(serializer), StateEvent::RoomCanonicalAlias(ref event) => event.serialize(serializer),
StateEvent::RoomCreate(ref event) => event.serialize(serializer), StateEvent::RoomCreate(ref event) => event.serialize(serializer),
StateEvent::RoomEncryption(ref event) => event.serialize(serializer),
StateEvent::RoomGuestAccess(ref event) => event.serialize(serializer), StateEvent::RoomGuestAccess(ref event) => event.serialize(serializer),
StateEvent::RoomHistoryVisibility(ref event) => event.serialize(serializer), StateEvent::RoomHistoryVisibility(ref event) => event.serialize(serializer),
StateEvent::RoomJoinRules(ref event) => event.serialize(serializer), StateEvent::RoomJoinRules(ref event) => event.serialize(serializer),
@ -954,6 +1146,14 @@ impl<'de> Deserialize<'de> for StateEvent {
Ok(StateEvent::RoomCreate(event)) Ok(StateEvent::RoomCreate(event))
} }
EventType::RoomEncryption => {
let event = match from_value::<EncryptionEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(StateEvent::RoomEncryption(event))
}
EventType::RoomGuestAccess => { EventType::RoomGuestAccess => {
let event = match from_value::<GuestAccessEvent>(value) { let event = match from_value::<GuestAccessEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -1055,13 +1255,24 @@ impl<'de> Deserialize<'de> for StateEvent {
| EventType::CallHangup | EventType::CallHangup
| EventType::CallInvite | EventType::CallInvite
| EventType::Direct | EventType::Direct
| EventType::Dummy
| EventType::ForwardedRoomKey
| EventType::FullyRead | EventType::FullyRead
| EventType::KeyVerificationAccept
| EventType::KeyVerificationCancel
| EventType::KeyVerificationKey
| EventType::KeyVerificationMac
| EventType::KeyVerificationRequest
| EventType::KeyVerificationStart
| EventType::IgnoredUserList | EventType::IgnoredUserList
| EventType::Presence | EventType::Presence
| EventType::Receipt | EventType::Receipt
| EventType::RoomEncrypted
| EventType::RoomMessage | EventType::RoomMessage
| EventType::RoomMessageFeedback | EventType::RoomMessageFeedback
| EventType::RoomRedaction | EventType::RoomRedaction
| EventType::RoomKey
| EventType::RoomKeyRequest
| EventType::Sticker | EventType::Sticker
| EventType::Tag | EventType::Tag
| EventType::Typing => Err(D::Error::custom("not a state event".to_string())), | EventType::Typing => Err(D::Error::custom("not a state event".to_string())),
@ -1087,7 +1298,15 @@ impl_from_t_for_event!(CandidatesEvent, CallCandidates);
impl_from_t_for_event!(HangupEvent, CallHangup); impl_from_t_for_event!(HangupEvent, CallHangup);
impl_from_t_for_event!(InviteEvent, CallInvite); impl_from_t_for_event!(InviteEvent, CallInvite);
impl_from_t_for_event!(DirectEvent, Direct); impl_from_t_for_event!(DirectEvent, Direct);
impl_from_t_for_event!(DummyEvent, Dummy);
impl_from_t_for_event!(ForwardedRoomKeyEvent, ForwardedRoomKey);
impl_from_t_for_event!(FullyReadEvent, FullyRead); impl_from_t_for_event!(FullyReadEvent, FullyRead);
impl_from_t_for_event!(AcceptEvent, KeyVerificationAccept);
impl_from_t_for_event!(CancelEvent, KeyVerificationCancel);
impl_from_t_for_event!(KeyEvent, KeyVerificationKey);
impl_from_t_for_event!(MacEvent, KeyVerificationMac);
impl_from_t_for_event!(RequestEvent, KeyVerificationRequest);
impl_from_t_for_event!(StartEvent, KeyVerificationStart);
impl_from_t_for_event!(IgnoredUserListEvent, IgnoredUserList); impl_from_t_for_event!(IgnoredUserListEvent, IgnoredUserList);
impl_from_t_for_event!(PresenceEvent, Presence); impl_from_t_for_event!(PresenceEvent, Presence);
impl_from_t_for_event!(ReceiptEvent, Receipt); impl_from_t_for_event!(ReceiptEvent, Receipt);
@ -1095,6 +1314,8 @@ impl_from_t_for_event!(AliasesEvent, RoomAliases);
impl_from_t_for_event!(AvatarEvent, RoomAvatar); impl_from_t_for_event!(AvatarEvent, RoomAvatar);
impl_from_t_for_event!(CanonicalAliasEvent, RoomCanonicalAlias); impl_from_t_for_event!(CanonicalAliasEvent, RoomCanonicalAlias);
impl_from_t_for_event!(CreateEvent, RoomCreate); impl_from_t_for_event!(CreateEvent, RoomCreate);
impl_from_t_for_event!(EncryptedEvent, RoomEncrypted);
impl_from_t_for_event!(EncryptionEvent, RoomEncryption);
impl_from_t_for_event!(GuestAccessEvent, RoomGuestAccess); impl_from_t_for_event!(GuestAccessEvent, RoomGuestAccess);
impl_from_t_for_event!(HistoryVisibilityEvent, RoomHistoryVisibility); impl_from_t_for_event!(HistoryVisibilityEvent, RoomHistoryVisibility);
impl_from_t_for_event!(JoinRulesEvent, RoomJoinRules); impl_from_t_for_event!(JoinRulesEvent, RoomJoinRules);
@ -1109,6 +1330,8 @@ impl_from_t_for_event!(ServerAclEvent, RoomServerAcl);
impl_from_t_for_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite); impl_from_t_for_event!(ThirdPartyInviteEvent, RoomThirdPartyInvite);
impl_from_t_for_event!(TombstoneEvent, RoomTombstone); impl_from_t_for_event!(TombstoneEvent, RoomTombstone);
impl_from_t_for_event!(TopicEvent, RoomTopic); impl_from_t_for_event!(TopicEvent, RoomTopic);
impl_from_t_for_event!(RoomKeyEvent, RoomKey);
impl_from_t_for_event!(RoomKeyRequestEvent, RoomKeyRequest);
impl_from_t_for_event!(StickerEvent, Sticker); impl_from_t_for_event!(StickerEvent, Sticker);
impl_from_t_for_event!(TagEvent, Tag); impl_from_t_for_event!(TagEvent, Tag);
impl_from_t_for_event!(TypingEvent, Typing); impl_from_t_for_event!(TypingEvent, Typing);
@ -1134,6 +1357,8 @@ impl_from_t_for_room_event!(AliasesEvent, RoomAliases);
impl_from_t_for_room_event!(AvatarEvent, RoomAvatar); impl_from_t_for_room_event!(AvatarEvent, RoomAvatar);
impl_from_t_for_room_event!(CanonicalAliasEvent, RoomCanonicalAlias); impl_from_t_for_room_event!(CanonicalAliasEvent, RoomCanonicalAlias);
impl_from_t_for_room_event!(CreateEvent, RoomCreate); impl_from_t_for_room_event!(CreateEvent, RoomCreate);
impl_from_t_for_room_event!(EncryptedEvent, RoomEncrypted);
impl_from_t_for_room_event!(EncryptionEvent, RoomEncryption);
impl_from_t_for_room_event!(GuestAccessEvent, RoomGuestAccess); impl_from_t_for_room_event!(GuestAccessEvent, RoomGuestAccess);
impl_from_t_for_room_event!(HistoryVisibilityEvent, RoomHistoryVisibility); impl_from_t_for_room_event!(HistoryVisibilityEvent, RoomHistoryVisibility);
impl_from_t_for_room_event!(JoinRulesEvent, RoomJoinRules); impl_from_t_for_room_event!(JoinRulesEvent, RoomJoinRules);
@ -1166,6 +1391,7 @@ impl_from_t_for_state_event!(AliasesEvent, RoomAliases);
impl_from_t_for_state_event!(AvatarEvent, RoomAvatar); impl_from_t_for_state_event!(AvatarEvent, RoomAvatar);
impl_from_t_for_state_event!(CanonicalAliasEvent, RoomCanonicalAlias); impl_from_t_for_state_event!(CanonicalAliasEvent, RoomCanonicalAlias);
impl_from_t_for_state_event!(CreateEvent, RoomCreate); impl_from_t_for_state_event!(CreateEvent, RoomCreate);
impl_from_t_for_state_event!(EncryptionEvent, RoomEncryption);
impl_from_t_for_state_event!(GuestAccessEvent, RoomGuestAccess); impl_from_t_for_state_event!(GuestAccessEvent, RoomGuestAccess);
impl_from_t_for_state_event!(HistoryVisibilityEvent, RoomHistoryVisibility); impl_from_t_for_state_event!(HistoryVisibilityEvent, RoomHistoryVisibility);
impl_from_t_for_state_event!(JoinRulesEvent, RoomJoinRules); impl_from_t_for_state_event!(JoinRulesEvent, RoomJoinRules);

View File

@ -10,14 +10,23 @@ use crate::{
answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent, answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent,
}, },
direct::DirectEvent, direct::DirectEvent,
dummy::DummyEvent,
forwarded_room_key::ForwardedRoomKeyEvent,
fully_read::FullyReadEvent, fully_read::FullyReadEvent,
ignored_user_list::IgnoredUserListEvent, ignored_user_list::IgnoredUserListEvent,
key::verification::{
accept::AcceptEvent, cancel::CancelEvent, key::KeyEvent, mac::MacEvent,
request::RequestEvent, start::StartEvent,
},
presence::PresenceEvent, presence::PresenceEvent,
receipt::ReceiptEvent, receipt::ReceiptEvent,
room::{ room::{
encrypted::EncryptedEvent,
message::{feedback::FeedbackEvent, MessageEvent}, message::{feedback::FeedbackEvent, MessageEvent},
redaction::RedactionEvent, redaction::RedactionEvent,
}, },
room_key::RoomKeyEvent,
room_key_request::RoomKeyRequestEvent,
sticker::StickerEvent, sticker::StickerEvent,
tag::TagEvent, tag::TagEvent,
typing::TypingEvent, typing::TypingEvent,
@ -30,15 +39,45 @@ pub enum Event {
/// m.direct /// m.direct
Direct(DirectEvent), Direct(DirectEvent),
/// m.dummy
Dummy(DummyEvent),
/// m.forwarded_room_key
ForwardedRoomKey(ForwardedRoomKeyEvent),
/// m.fully_read /// m.fully_read
FullyRead(FullyReadEvent), FullyRead(FullyReadEvent),
/// m.key.verification.accept
KeyVerificationAccept(AcceptEvent),
/// m.key.verification.cancel
KeyVerificationCancel(CancelEvent),
/// m.key.verification.key
KeyVerificationKey(KeyEvent),
/// m.key.verification.mac
KeyVerificationMac(MacEvent),
/// m.key.verification.request
KeyVerificationRequest(RequestEvent),
/// m.key.verification.start
KeyVerificationStart(StartEvent),
/// m.ignored_user_list /// m.ignored_user_list
IgnoredUserList(IgnoredUserListEvent), IgnoredUserList(IgnoredUserListEvent),
/// m.presence /// m.presence
Presence(PresenceEvent), Presence(PresenceEvent),
/// m.room_key
RoomKey(RoomKeyEvent),
/// m.room_key_request
RoomKeyRequest(RoomKeyRequestEvent),
/// m.receipt /// m.receipt
Receipt(ReceiptEvent), Receipt(ReceiptEvent),
@ -68,6 +107,9 @@ pub enum RoomEvent {
/// m.call.invite /// m.call.invite
CallInvite(InviteEvent), CallInvite(InviteEvent),
/// m.room.encrypted
RoomEncrypted(EncryptedEvent),
/// m.room.message /// m.room.message
RoomMessage(MessageEvent), RoomMessage(MessageEvent),
@ -91,10 +133,20 @@ impl Serialize for Event {
{ {
match *self { match *self {
Event::Direct(ref event) => event.serialize(serializer), Event::Direct(ref event) => event.serialize(serializer),
Event::Dummy(ref event) => event.serialize(serializer),
Event::ForwardedRoomKey(ref event) => event.serialize(serializer),
Event::FullyRead(ref event) => event.serialize(serializer), Event::FullyRead(ref event) => event.serialize(serializer),
Event::KeyVerificationAccept(ref event) => event.serialize(serializer),
Event::KeyVerificationCancel(ref event) => event.serialize(serializer),
Event::KeyVerificationKey(ref event) => event.serialize(serializer),
Event::KeyVerificationMac(ref event) => event.serialize(serializer),
Event::KeyVerificationRequest(ref event) => event.serialize(serializer),
Event::KeyVerificationStart(ref event) => event.serialize(serializer),
Event::IgnoredUserList(ref event) => event.serialize(serializer), Event::IgnoredUserList(ref event) => event.serialize(serializer),
Event::Presence(ref event) => event.serialize(serializer), Event::Presence(ref event) => event.serialize(serializer),
Event::Receipt(ref event) => event.serialize(serializer), Event::Receipt(ref event) => event.serialize(serializer),
Event::RoomKey(ref event) => event.serialize(serializer),
Event::RoomKeyRequest(ref event) => event.serialize(serializer),
Event::Tag(ref event) => event.serialize(serializer), Event::Tag(ref event) => event.serialize(serializer),
Event::Typing(ref event) => event.serialize(serializer), Event::Typing(ref event) => event.serialize(serializer),
Event::Custom(ref event) => event.serialize(serializer), Event::Custom(ref event) => event.serialize(serializer),
@ -128,6 +180,22 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::Direct(event)) Ok(Event::Direct(event))
} }
EventType::Dummy => {
let event = match from_value::<DummyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::Dummy(event))
}
EventType::ForwardedRoomKey => {
let event = match from_value::<ForwardedRoomKeyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::ForwardedRoomKey(event))
}
EventType::FullyRead => { EventType::FullyRead => {
let event = match from_value::<FullyReadEvent>(value) { let event = match from_value::<FullyReadEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -136,6 +204,54 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::FullyRead(event)) Ok(Event::FullyRead(event))
} }
EventType::KeyVerificationAccept => {
let event = match from_value::<AcceptEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationAccept(event))
}
EventType::KeyVerificationCancel => {
let event = match from_value::<CancelEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationCancel(event))
}
EventType::KeyVerificationKey => {
let event = match from_value::<KeyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationKey(event))
}
EventType::KeyVerificationMac => {
let event = match from_value::<MacEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationMac(event))
}
EventType::KeyVerificationRequest => {
let event = match from_value::<RequestEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationRequest(event))
}
EventType::KeyVerificationStart => {
let event = match from_value::<StartEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::KeyVerificationStart(event))
}
EventType::IgnoredUserList => { EventType::IgnoredUserList => {
let event = match from_value::<IgnoredUserListEvent>(value) { let event = match from_value::<IgnoredUserListEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -160,6 +276,22 @@ impl<'de> Deserialize<'de> for Event {
Ok(Event::Receipt(event)) Ok(Event::Receipt(event))
} }
EventType::RoomKey => {
let event = match from_value::<RoomKeyEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::RoomKey(event))
}
EventType::RoomKeyRequest => {
let event = match from_value::<RoomKeyRequestEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(Event::RoomKeyRequest(event))
}
EventType::Tag => { EventType::Tag => {
let event = match from_value::<TagEvent>(value) { let event = match from_value::<TagEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -192,6 +324,8 @@ impl<'de> Deserialize<'de> for Event {
| EventType::RoomAvatar | EventType::RoomAvatar
| EventType::RoomCanonicalAlias | EventType::RoomCanonicalAlias
| EventType::RoomCreate | EventType::RoomCreate
| EventType::RoomEncrypted
| EventType::RoomEncryption
| EventType::RoomGuestAccess | EventType::RoomGuestAccess
| EventType::RoomHistoryVisibility | EventType::RoomHistoryVisibility
| EventType::RoomJoinRules | EventType::RoomJoinRules
@ -226,6 +360,7 @@ impl Serialize for RoomEvent {
RoomEvent::CallCandidates(ref event) => event.serialize(serializer), RoomEvent::CallCandidates(ref event) => event.serialize(serializer),
RoomEvent::CallHangup(ref event) => event.serialize(serializer), RoomEvent::CallHangup(ref event) => event.serialize(serializer),
RoomEvent::CallInvite(ref event) => event.serialize(serializer), RoomEvent::CallInvite(ref event) => event.serialize(serializer),
RoomEvent::RoomEncrypted(ref event) => event.serialize(serializer),
RoomEvent::RoomMessage(ref event) => event.serialize(serializer), RoomEvent::RoomMessage(ref event) => event.serialize(serializer),
RoomEvent::RoomMessageFeedback(ref event) => event.serialize(serializer), RoomEvent::RoomMessageFeedback(ref event) => event.serialize(serializer),
RoomEvent::RoomRedaction(ref event) => event.serialize(serializer), RoomEvent::RoomRedaction(ref event) => event.serialize(serializer),
@ -285,6 +420,14 @@ impl<'de> Deserialize<'de> for RoomEvent {
Ok(RoomEvent::CallInvite(event)) Ok(RoomEvent::CallInvite(event))
} }
EventType::RoomEncrypted => {
let event = match from_value::<EncryptedEvent>(value) {
Ok(event) => event,
Err(error) => return Err(D::Error::custom(error.to_string())),
};
Ok(RoomEvent::RoomEncrypted(event))
}
EventType::RoomMessage => { EventType::RoomMessage => {
let event = match from_value::<MessageEvent>(value) { let event = match from_value::<MessageEvent>(value) {
Ok(event) => event, Ok(event) => event,
@ -326,7 +469,15 @@ impl<'de> Deserialize<'de> for RoomEvent {
Ok(RoomEvent::CustomRoom(event)) Ok(RoomEvent::CustomRoom(event))
} }
EventType::Direct EventType::Direct
| EventType::Dummy
| EventType::ForwardedRoomKey
| EventType::FullyRead | EventType::FullyRead
| EventType::KeyVerificationAccept
| EventType::KeyVerificationCancel
| EventType::KeyVerificationKey
| EventType::KeyVerificationMac
| EventType::KeyVerificationRequest
| EventType::KeyVerificationStart
| EventType::IgnoredUserList | EventType::IgnoredUserList
| EventType::Presence | EventType::Presence
| EventType::Receipt | EventType::Receipt
@ -334,6 +485,7 @@ impl<'de> Deserialize<'de> for RoomEvent {
| EventType::RoomAvatar | EventType::RoomAvatar
| EventType::RoomCanonicalAlias | EventType::RoomCanonicalAlias
| EventType::RoomCreate | EventType::RoomCreate
| EventType::RoomEncryption
| EventType::RoomGuestAccess | EventType::RoomGuestAccess
| EventType::RoomHistoryVisibility | EventType::RoomHistoryVisibility
| EventType::RoomJoinRules | EventType::RoomJoinRules
@ -345,6 +497,8 @@ impl<'de> Deserialize<'de> for RoomEvent {
| EventType::RoomThirdPartyInvite | EventType::RoomThirdPartyInvite
| EventType::RoomTombstone | EventType::RoomTombstone
| EventType::RoomTopic | EventType::RoomTopic
| EventType::RoomKey
| EventType::RoomKeyRequest
| EventType::Tag | EventType::Tag
| EventType::Typing => { | EventType::Typing => {
Err(D::Error::custom("not exclusively a room event".to_string())) Err(D::Error::custom("not exclusively a room event".to_string()))
@ -366,7 +520,15 @@ macro_rules! impl_from_t_for_event {
} }
impl_from_t_for_event!(DirectEvent, Direct); impl_from_t_for_event!(DirectEvent, Direct);
impl_from_t_for_event!(DummyEvent, Dummy);
impl_from_t_for_event!(ForwardedRoomKeyEvent, ForwardedRoomKey);
impl_from_t_for_event!(FullyReadEvent, FullyRead); impl_from_t_for_event!(FullyReadEvent, FullyRead);
impl_from_t_for_event!(AcceptEvent, KeyVerificationAccept);
impl_from_t_for_event!(CancelEvent, KeyVerificationCancel);
impl_from_t_for_event!(KeyEvent, KeyVerificationKey);
impl_from_t_for_event!(MacEvent, KeyVerificationMac);
impl_from_t_for_event!(RequestEvent, KeyVerificationRequest);
impl_from_t_for_event!(StartEvent, KeyVerificationStart);
impl_from_t_for_event!(IgnoredUserListEvent, IgnoredUserList); impl_from_t_for_event!(IgnoredUserListEvent, IgnoredUserList);
impl_from_t_for_event!(PresenceEvent, Presence); impl_from_t_for_event!(PresenceEvent, Presence);
impl_from_t_for_event!(ReceiptEvent, Receipt); impl_from_t_for_event!(ReceiptEvent, Receipt);
@ -388,6 +550,7 @@ impl_from_t_for_room_event!(AnswerEvent, CallAnswer);
impl_from_t_for_room_event!(CandidatesEvent, CallCandidates); impl_from_t_for_room_event!(CandidatesEvent, CallCandidates);
impl_from_t_for_room_event!(HangupEvent, CallHangup); impl_from_t_for_room_event!(HangupEvent, CallHangup);
impl_from_t_for_room_event!(InviteEvent, CallInvite); impl_from_t_for_room_event!(InviteEvent, CallInvite);
impl_from_t_for_room_event!(EncryptedEvent, RoomEncrypted);
impl_from_t_for_room_event!(MessageEvent, RoomMessage); impl_from_t_for_room_event!(MessageEvent, RoomMessage);
impl_from_t_for_room_event!(FeedbackEvent, RoomMessageFeedback); impl_from_t_for_room_event!(FeedbackEvent, RoomMessageFeedback);
impl_from_t_for_room_event!(RedactionEvent, RoomRedaction); impl_from_t_for_room_event!(RedactionEvent, RoomRedaction);

View File

@ -155,9 +155,33 @@ pub enum EventType {
/// m.direct /// m.direct
Direct, Direct,
/// m.dummy
Dummy,
/// m.forwarded_room_key
ForwardedRoomKey,
/// m.fully_read /// m.fully_read
FullyRead, FullyRead,
/// m.key.verification.accept
KeyVerificationAccept,
/// m.key.verification.cancel
KeyVerificationCancel,
/// m.key.verification.key
KeyVerificationKey,
/// m.key.verification.mac
KeyVerificationMac,
/// m.key.verification.request
KeyVerificationRequest,
/// m.key.verification.start
KeyVerificationStart,
/// m.ignored_user_list /// m.ignored_user_list
IgnoredUserList, IgnoredUserList,
@ -179,6 +203,12 @@ pub enum EventType {
/// m.room.create /// m.room.create
RoomCreate, RoomCreate,
/// m.room.encrypted
RoomEncrypted,
/// m.room.encryption
RoomEncryption,
/// m.room.guest_access /// m.room.guest_access
RoomGuestAccess, RoomGuestAccess,
@ -221,6 +251,12 @@ pub enum EventType {
/// m.room.topic /// m.room.topic
RoomTopic, RoomTopic,
/// m.room_key
RoomKey,
/// m.room_key_request
RoomKeyRequest,
/// m.sticker /// m.sticker
Sticker, Sticker,
@ -308,7 +344,15 @@ impl Display for EventType {
EventType::CallHangup => "m.call.hangup", EventType::CallHangup => "m.call.hangup",
EventType::CallInvite => "m.call.invite", EventType::CallInvite => "m.call.invite",
EventType::Direct => "m.direct", EventType::Direct => "m.direct",
EventType::Dummy => "m.dummy",
EventType::ForwardedRoomKey => "m.forwarded_room_key",
EventType::FullyRead => "m.fully_read", EventType::FullyRead => "m.fully_read",
EventType::KeyVerificationAccept => "m.key.verification.accept",
EventType::KeyVerificationCancel => "m.key.verification.cancel",
EventType::KeyVerificationKey => "m.key.verification.key",
EventType::KeyVerificationMac => "m.key.verification.mac",
EventType::KeyVerificationRequest => "m.key.verification.request",
EventType::KeyVerificationStart => "m.key.verification.start",
EventType::IgnoredUserList => "m.ignored_user_list", EventType::IgnoredUserList => "m.ignored_user_list",
EventType::Presence => "m.presence", EventType::Presence => "m.presence",
EventType::Receipt => "m.receipt", EventType::Receipt => "m.receipt",
@ -316,6 +360,8 @@ impl Display for EventType {
EventType::RoomAvatar => "m.room.avatar", EventType::RoomAvatar => "m.room.avatar",
EventType::RoomCanonicalAlias => "m.room.canonical_alias", EventType::RoomCanonicalAlias => "m.room.canonical_alias",
EventType::RoomCreate => "m.room.create", EventType::RoomCreate => "m.room.create",
EventType::RoomEncrypted => "m.room.encrypted",
EventType::RoomEncryption => "m.room.encryption",
EventType::RoomGuestAccess => "m.room.guest_access", EventType::RoomGuestAccess => "m.room.guest_access",
EventType::RoomHistoryVisibility => "m.room.history_visibility", EventType::RoomHistoryVisibility => "m.room.history_visibility",
EventType::RoomJoinRules => "m.room.join_rules", EventType::RoomJoinRules => "m.room.join_rules",
@ -330,6 +376,8 @@ impl Display for EventType {
EventType::RoomThirdPartyInvite => "m.room.third_party_invite", EventType::RoomThirdPartyInvite => "m.room.third_party_invite",
EventType::RoomTombstone => "m.room.tombstone", EventType::RoomTombstone => "m.room.tombstone",
EventType::RoomTopic => "m.room.topic", EventType::RoomTopic => "m.room.topic",
EventType::RoomKey => "m.room_key",
EventType::RoomKeyRequest => "m.room_key_request",
EventType::Sticker => "m.sticker", EventType::Sticker => "m.sticker",
EventType::Tag => "m.tag", EventType::Tag => "m.tag",
EventType::Typing => "m.typing", EventType::Typing => "m.typing",
@ -351,7 +399,15 @@ impl<'a> From<&'a str> for EventType {
"m.call.hangup" => EventType::CallHangup, "m.call.hangup" => EventType::CallHangup,
"m.call.invite" => EventType::CallInvite, "m.call.invite" => EventType::CallInvite,
"m.direct" => EventType::Direct, "m.direct" => EventType::Direct,
"m.dummy" => EventType::Dummy,
"m.forwarded_room_key" => EventType::ForwardedRoomKey,
"m.fully_read" => EventType::FullyRead, "m.fully_read" => EventType::FullyRead,
"m.key.verification.accept" => EventType::KeyVerificationAccept,
"m.key.verification.cancel" => EventType::KeyVerificationCancel,
"m.key.verification.key" => EventType::KeyVerificationKey,
"m.key.verification.mac" => EventType::KeyVerificationMac,
"m.key.verification.request" => EventType::KeyVerificationRequest,
"m.key.verification.start" => EventType::KeyVerificationStart,
"m.ignored_user_list" => EventType::IgnoredUserList, "m.ignored_user_list" => EventType::IgnoredUserList,
"m.presence" => EventType::Presence, "m.presence" => EventType::Presence,
"m.receipt" => EventType::Receipt, "m.receipt" => EventType::Receipt,
@ -359,6 +415,8 @@ impl<'a> From<&'a str> for EventType {
"m.room.avatar" => EventType::RoomAvatar, "m.room.avatar" => EventType::RoomAvatar,
"m.room.canonical_alias" => EventType::RoomCanonicalAlias, "m.room.canonical_alias" => EventType::RoomCanonicalAlias,
"m.room.create" => EventType::RoomCreate, "m.room.create" => EventType::RoomCreate,
"m.room.encrypted" => EventType::RoomEncrypted,
"m.room.encryption" => EventType::RoomEncryption,
"m.room.guest_access" => EventType::RoomGuestAccess, "m.room.guest_access" => EventType::RoomGuestAccess,
"m.room.history_visibility" => EventType::RoomHistoryVisibility, "m.room.history_visibility" => EventType::RoomHistoryVisibility,
"m.room.join_rules" => EventType::RoomJoinRules, "m.room.join_rules" => EventType::RoomJoinRules,
@ -373,6 +431,8 @@ impl<'a> From<&'a str> for EventType {
"m.room.third_party_invite" => EventType::RoomThirdPartyInvite, "m.room.third_party_invite" => EventType::RoomThirdPartyInvite,
"m.room.tombstone" => EventType::RoomTombstone, "m.room.tombstone" => EventType::RoomTombstone,
"m.room.topic" => EventType::RoomTopic, "m.room.topic" => EventType::RoomTopic,
"m.room_key" => EventType::RoomKey,
"m.room_key_request" => EventType::RoomKeyRequest,
"m.sticker" => EventType::Sticker, "m.sticker" => EventType::Sticker,
"m.tag" => EventType::Tag, "m.tag" => EventType::Tag,
"m.typing" => EventType::Typing, "m.typing" => EventType::Typing,