Delete collections module
This commit is contained in:
parent
5dc1405d9d
commit
27a9b36499
@ -1,560 +0,0 @@
|
|||||||
//! Enums for heterogeneous collections of events, inclusive for every event type that implements
|
|
||||||
//! the trait of the same name.
|
|
||||||
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use super::raw::all as raw;
|
|
||||||
use crate::{
|
|
||||||
call::{
|
|
||||||
answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent,
|
|
||||||
},
|
|
||||||
direct::DirectEvent,
|
|
||||||
dummy::DummyEvent,
|
|
||||||
forwarded_room_key::ForwardedRoomKeyEvent,
|
|
||||||
fully_read::FullyReadEvent,
|
|
||||||
ignored_user_list::IgnoredUserListEvent,
|
|
||||||
key::verification::{
|
|
||||||
accept::AcceptEvent, cancel::CancelEvent, key::KeyEvent, mac::MacEvent,
|
|
||||||
request::RequestEvent, start::StartEvent,
|
|
||||||
},
|
|
||||||
presence::PresenceEvent,
|
|
||||||
push_rules::PushRulesEvent,
|
|
||||||
receipt::ReceiptEvent,
|
|
||||||
room::{
|
|
||||||
aliases::AliasesEvent,
|
|
||||||
avatar::AvatarEvent,
|
|
||||||
canonical_alias::CanonicalAliasEvent,
|
|
||||||
create::CreateEvent,
|
|
||||||
encrypted::EncryptedEvent,
|
|
||||||
encryption::EncryptionEvent,
|
|
||||||
guest_access::GuestAccessEvent,
|
|
||||||
history_visibility::HistoryVisibilityEvent,
|
|
||||||
join_rules::JoinRulesEvent,
|
|
||||||
member::MemberEvent,
|
|
||||||
message::{feedback::FeedbackEvent, MessageEvent},
|
|
||||||
name::NameEvent,
|
|
||||||
pinned_events::PinnedEventsEvent,
|
|
||||||
power_levels::PowerLevelsEvent,
|
|
||||||
redaction::RedactionEvent,
|
|
||||||
server_acl::ServerAclEvent,
|
|
||||||
third_party_invite::ThirdPartyInviteEvent,
|
|
||||||
tombstone::TombstoneEvent,
|
|
||||||
topic::TopicEvent,
|
|
||||||
},
|
|
||||||
room_key::RoomKeyEvent,
|
|
||||||
room_key_request::RoomKeyRequestEvent,
|
|
||||||
sticker::StickerEvent,
|
|
||||||
tag::TagEvent,
|
|
||||||
typing::TypingEvent,
|
|
||||||
CustomEvent, CustomRoomEvent, CustomStateEvent, TryFromRaw,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// A basic event, room event, or state event.
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum Event {
|
|
||||||
/// m.call.answer
|
|
||||||
CallAnswer(AnswerEvent),
|
|
||||||
|
|
||||||
/// m.call.candidates
|
|
||||||
CallCandidates(CandidatesEvent),
|
|
||||||
|
|
||||||
/// m.call.hangup
|
|
||||||
CallHangup(HangupEvent),
|
|
||||||
|
|
||||||
/// m.call.invite
|
|
||||||
CallInvite(InviteEvent),
|
|
||||||
|
|
||||||
/// m.direct
|
|
||||||
Direct(DirectEvent),
|
|
||||||
|
|
||||||
/// m.dummy
|
|
||||||
Dummy(DummyEvent),
|
|
||||||
|
|
||||||
/// m.forwarded_room_key
|
|
||||||
ForwardedRoomKey(ForwardedRoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.fully_read
|
|
||||||
FullyRead(FullyReadEvent),
|
|
||||||
|
|
||||||
/// m.ignored_user_list
|
|
||||||
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
|
|
||||||
Presence(PresenceEvent),
|
|
||||||
|
|
||||||
/// m.push_rules
|
|
||||||
PushRules(PushRulesEvent),
|
|
||||||
|
|
||||||
/// m.receipt
|
|
||||||
Receipt(ReceiptEvent),
|
|
||||||
|
|
||||||
/// m.room.aliases
|
|
||||||
RoomAliases(AliasesEvent),
|
|
||||||
|
|
||||||
/// m.room.avatar
|
|
||||||
RoomAvatar(AvatarEvent),
|
|
||||||
|
|
||||||
/// m.room.canonical_alias
|
|
||||||
RoomCanonicalAlias(CanonicalAliasEvent),
|
|
||||||
|
|
||||||
/// m.room.create
|
|
||||||
RoomCreate(CreateEvent),
|
|
||||||
|
|
||||||
/// m.room.encrypted
|
|
||||||
RoomEncrypted(EncryptedEvent),
|
|
||||||
|
|
||||||
/// m.room.encryption
|
|
||||||
RoomEncryption(EncryptionEvent),
|
|
||||||
|
|
||||||
/// m.room.guest_access
|
|
||||||
RoomGuestAccess(GuestAccessEvent),
|
|
||||||
|
|
||||||
/// m.room.history_visibility
|
|
||||||
RoomHistoryVisibility(HistoryVisibilityEvent),
|
|
||||||
|
|
||||||
/// m.room.join_rules
|
|
||||||
RoomJoinRules(JoinRulesEvent),
|
|
||||||
|
|
||||||
/// m.room.member
|
|
||||||
RoomMember(MemberEvent),
|
|
||||||
|
|
||||||
/// m.room.message
|
|
||||||
RoomMessage(MessageEvent),
|
|
||||||
|
|
||||||
/// m.room.message.feedback
|
|
||||||
RoomMessageFeedback(FeedbackEvent),
|
|
||||||
|
|
||||||
/// m.room.name
|
|
||||||
RoomName(NameEvent),
|
|
||||||
|
|
||||||
/// m.room.pinned_events
|
|
||||||
RoomPinnedEvents(PinnedEventsEvent),
|
|
||||||
|
|
||||||
/// m.room.power_levels
|
|
||||||
RoomPowerLevels(PowerLevelsEvent),
|
|
||||||
|
|
||||||
/// m.room.redaction
|
|
||||||
RoomRedaction(RedactionEvent),
|
|
||||||
|
|
||||||
/// m.room.server_acl
|
|
||||||
RoomServerAcl(ServerAclEvent),
|
|
||||||
|
|
||||||
/// m.room.third_party_invite
|
|
||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
|
||||||
|
|
||||||
/// m.room.tombstone
|
|
||||||
RoomTombstone(TombstoneEvent),
|
|
||||||
|
|
||||||
/// m.room.topic
|
|
||||||
RoomTopic(TopicEvent),
|
|
||||||
|
|
||||||
/// m.room_key
|
|
||||||
RoomKey(RoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.room_key_request
|
|
||||||
RoomKeyRequest(RoomKeyRequestEvent),
|
|
||||||
|
|
||||||
/// m.sticker
|
|
||||||
Sticker(StickerEvent),
|
|
||||||
|
|
||||||
/// m.tag
|
|
||||||
Tag(TagEvent),
|
|
||||||
|
|
||||||
/// m.typing
|
|
||||||
Typing(TypingEvent),
|
|
||||||
|
|
||||||
/// Any basic event that is not part of the specification.
|
|
||||||
Custom(CustomEvent),
|
|
||||||
|
|
||||||
/// Any room event that is not part of the specification.
|
|
||||||
CustomRoom(CustomRoomEvent),
|
|
||||||
|
|
||||||
/// Any state event that is not part of the specification.
|
|
||||||
CustomState(CustomStateEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A room event or state event.
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum RoomEvent {
|
|
||||||
/// m.call.answer
|
|
||||||
CallAnswer(AnswerEvent),
|
|
||||||
|
|
||||||
/// m.call.candidates
|
|
||||||
CallCandidates(CandidatesEvent),
|
|
||||||
|
|
||||||
/// m.call.hangup
|
|
||||||
CallHangup(HangupEvent),
|
|
||||||
|
|
||||||
/// m.call.invite
|
|
||||||
CallInvite(InviteEvent),
|
|
||||||
|
|
||||||
/// m.room.aliases
|
|
||||||
RoomAliases(AliasesEvent),
|
|
||||||
|
|
||||||
/// m.room.avatar
|
|
||||||
RoomAvatar(AvatarEvent),
|
|
||||||
|
|
||||||
/// m.room.canonical_alias
|
|
||||||
RoomCanonicalAlias(CanonicalAliasEvent),
|
|
||||||
|
|
||||||
/// m.room.create
|
|
||||||
RoomCreate(CreateEvent),
|
|
||||||
|
|
||||||
/// m.room.encrypted
|
|
||||||
RoomEncrypted(EncryptedEvent),
|
|
||||||
|
|
||||||
/// m.room.encryption
|
|
||||||
RoomEncryption(EncryptionEvent),
|
|
||||||
|
|
||||||
/// m.room.guest_access
|
|
||||||
RoomGuestAccess(GuestAccessEvent),
|
|
||||||
|
|
||||||
/// m.room.history_visibility
|
|
||||||
RoomHistoryVisibility(HistoryVisibilityEvent),
|
|
||||||
|
|
||||||
/// m.room.join_rules
|
|
||||||
RoomJoinRules(JoinRulesEvent),
|
|
||||||
|
|
||||||
/// m.room.member
|
|
||||||
RoomMember(MemberEvent),
|
|
||||||
|
|
||||||
/// m.room.message
|
|
||||||
RoomMessage(MessageEvent),
|
|
||||||
|
|
||||||
/// m.room.message.feedback
|
|
||||||
RoomMessageFeedback(FeedbackEvent),
|
|
||||||
|
|
||||||
/// m.room.name
|
|
||||||
RoomName(NameEvent),
|
|
||||||
|
|
||||||
/// m.room.pinned_events
|
|
||||||
RoomPinnedEvents(PinnedEventsEvent),
|
|
||||||
|
|
||||||
/// m.room.power_levels
|
|
||||||
RoomPowerLevels(PowerLevelsEvent),
|
|
||||||
|
|
||||||
/// m.room.redaction
|
|
||||||
RoomRedaction(RedactionEvent),
|
|
||||||
|
|
||||||
/// m.room.server_acl
|
|
||||||
RoomServerAcl(ServerAclEvent),
|
|
||||||
|
|
||||||
/// m.room.third_party_invite
|
|
||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
|
||||||
|
|
||||||
/// m.room.tombstone
|
|
||||||
RoomTombstone(TombstoneEvent),
|
|
||||||
|
|
||||||
/// m.room.topic
|
|
||||||
RoomTopic(TopicEvent),
|
|
||||||
|
|
||||||
/// m.sticker
|
|
||||||
Sticker(StickerEvent),
|
|
||||||
|
|
||||||
/// Any room event that is not part of the specification.
|
|
||||||
CustomRoom(CustomRoomEvent),
|
|
||||||
|
|
||||||
/// Any state event that is not part of the specification.
|
|
||||||
CustomState(CustomStateEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A state event.
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum StateEvent {
|
|
||||||
/// m.room.aliases
|
|
||||||
RoomAliases(AliasesEvent),
|
|
||||||
|
|
||||||
/// m.room.avatar
|
|
||||||
RoomAvatar(AvatarEvent),
|
|
||||||
|
|
||||||
/// m.room.canonical_alias
|
|
||||||
RoomCanonicalAlias(CanonicalAliasEvent),
|
|
||||||
|
|
||||||
/// m.room.create
|
|
||||||
RoomCreate(CreateEvent),
|
|
||||||
|
|
||||||
/// m.room.encryption
|
|
||||||
RoomEncryption(EncryptionEvent),
|
|
||||||
|
|
||||||
/// m.room.guest_access
|
|
||||||
RoomGuestAccess(GuestAccessEvent),
|
|
||||||
|
|
||||||
/// m.room.history_visibility
|
|
||||||
RoomHistoryVisibility(HistoryVisibilityEvent),
|
|
||||||
|
|
||||||
/// m.room.join_rules
|
|
||||||
RoomJoinRules(JoinRulesEvent),
|
|
||||||
|
|
||||||
/// m.room.member
|
|
||||||
RoomMember(MemberEvent),
|
|
||||||
|
|
||||||
/// m.room.name
|
|
||||||
RoomName(NameEvent),
|
|
||||||
|
|
||||||
/// m.room.pinned_events
|
|
||||||
RoomPinnedEvents(PinnedEventsEvent),
|
|
||||||
|
|
||||||
/// m.room.power_levels
|
|
||||||
RoomPowerLevels(PowerLevelsEvent),
|
|
||||||
|
|
||||||
/// m.room.server_acl
|
|
||||||
RoomServerAcl(ServerAclEvent),
|
|
||||||
|
|
||||||
/// m.room.third_party_invite
|
|
||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
|
||||||
|
|
||||||
/// m.room.tombstone
|
|
||||||
RoomTombstone(TombstoneEvent),
|
|
||||||
|
|
||||||
/// m.room.topic
|
|
||||||
RoomTopic(TopicEvent),
|
|
||||||
|
|
||||||
/// Any state event that is not part of the specification.
|
|
||||||
CustomState(CustomStateEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFromRaw for Event {
|
|
||||||
type Raw = raw::Event;
|
|
||||||
type Err = String;
|
|
||||||
|
|
||||||
fn try_from_raw(raw: raw::Event) -> Result<Self, Self::Err> {
|
|
||||||
use crate::util::try_convert_variant as conv;
|
|
||||||
use raw::Event::*;
|
|
||||||
|
|
||||||
match raw {
|
|
||||||
CallAnswer(c) => conv(Event::CallAnswer, c),
|
|
||||||
CallCandidates(c) => conv(Event::CallCandidates, c),
|
|
||||||
CallHangup(c) => conv(Event::CallHangup, c),
|
|
||||||
CallInvite(c) => conv(Event::CallInvite, c),
|
|
||||||
Direct(c) => conv(Event::Direct, c),
|
|
||||||
Dummy(c) => conv(Event::Dummy, c),
|
|
||||||
ForwardedRoomKey(c) => conv(Event::ForwardedRoomKey, c),
|
|
||||||
FullyRead(c) => conv(Event::FullyRead, c),
|
|
||||||
IgnoredUserList(c) => conv(Event::IgnoredUserList, c),
|
|
||||||
KeyVerificationAccept(c) => conv(Event::KeyVerificationAccept, c),
|
|
||||||
KeyVerificationCancel(c) => conv(Event::KeyVerificationCancel, c),
|
|
||||||
KeyVerificationKey(c) => conv(Event::KeyVerificationKey, c),
|
|
||||||
KeyVerificationMac(c) => conv(Event::KeyVerificationMac, c),
|
|
||||||
KeyVerificationRequest(c) => conv(Event::KeyVerificationRequest, c),
|
|
||||||
KeyVerificationStart(c) => conv(Event::KeyVerificationStart, c),
|
|
||||||
Presence(c) => conv(Event::Presence, c),
|
|
||||||
PushRules(c) => conv(Event::PushRules, c),
|
|
||||||
Receipt(c) => conv(Event::Receipt, c),
|
|
||||||
RoomAliases(c) => conv(Event::RoomAliases, c),
|
|
||||||
RoomAvatar(c) => conv(Event::RoomAvatar, c),
|
|
||||||
RoomCanonicalAlias(c) => conv(Event::RoomCanonicalAlias, c),
|
|
||||||
RoomCreate(c) => conv(Event::RoomCreate, c),
|
|
||||||
RoomEncrypted(c) => conv(Event::RoomEncrypted, c),
|
|
||||||
RoomEncryption(c) => conv(Event::RoomEncryption, c),
|
|
||||||
RoomGuestAccess(c) => conv(Event::RoomGuestAccess, c),
|
|
||||||
RoomHistoryVisibility(c) => conv(Event::RoomHistoryVisibility, c),
|
|
||||||
RoomJoinRules(c) => conv(Event::RoomJoinRules, c),
|
|
||||||
RoomMember(c) => conv(Event::RoomMember, c),
|
|
||||||
RoomMessage(c) => conv(Event::RoomMessage, c),
|
|
||||||
RoomMessageFeedback(c) => conv(Event::RoomMessageFeedback, c),
|
|
||||||
RoomName(c) => conv(Event::RoomName, c),
|
|
||||||
RoomPinnedEvents(c) => conv(Event::RoomPinnedEvents, c),
|
|
||||||
RoomPowerLevels(c) => conv(Event::RoomPowerLevels, c),
|
|
||||||
RoomRedaction(c) => conv(Event::RoomRedaction, c),
|
|
||||||
RoomServerAcl(c) => conv(Event::RoomServerAcl, c),
|
|
||||||
RoomThirdPartyInvite(c) => conv(Event::RoomThirdPartyInvite, c),
|
|
||||||
RoomTombstone(c) => conv(Event::RoomTombstone, c),
|
|
||||||
RoomTopic(c) => conv(Event::RoomTopic, c),
|
|
||||||
RoomKey(c) => conv(Event::RoomKey, c),
|
|
||||||
RoomKeyRequest(c) => conv(Event::RoomKeyRequest, c),
|
|
||||||
Sticker(c) => conv(Event::Sticker, c),
|
|
||||||
Tag(c) => conv(Event::Tag, c),
|
|
||||||
Typing(c) => conv(Event::Typing, c),
|
|
||||||
Custom(c) => conv(Event::Custom, c),
|
|
||||||
CustomRoom(c) => conv(Event::CustomRoom, c),
|
|
||||||
CustomState(c) => conv(Event::CustomState, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFromRaw for RoomEvent {
|
|
||||||
type Raw = raw::RoomEvent;
|
|
||||||
type Err = String;
|
|
||||||
|
|
||||||
fn try_from_raw(raw: raw::RoomEvent) -> Result<Self, Self::Err> {
|
|
||||||
use crate::util::try_convert_variant as conv;
|
|
||||||
use raw::RoomEvent::*;
|
|
||||||
|
|
||||||
match raw {
|
|
||||||
CallAnswer(c) => conv(RoomEvent::CallAnswer, c),
|
|
||||||
CallCandidates(c) => conv(RoomEvent::CallCandidates, c),
|
|
||||||
CallHangup(c) => conv(RoomEvent::CallHangup, c),
|
|
||||||
CallInvite(c) => conv(RoomEvent::CallInvite, c),
|
|
||||||
RoomAliases(c) => conv(RoomEvent::RoomAliases, c),
|
|
||||||
RoomAvatar(c) => conv(RoomEvent::RoomAvatar, c),
|
|
||||||
RoomCanonicalAlias(c) => conv(RoomEvent::RoomCanonicalAlias, c),
|
|
||||||
RoomCreate(c) => conv(RoomEvent::RoomCreate, c),
|
|
||||||
RoomEncrypted(c) => conv(RoomEvent::RoomEncrypted, c),
|
|
||||||
RoomEncryption(c) => conv(RoomEvent::RoomEncryption, c),
|
|
||||||
RoomGuestAccess(c) => conv(RoomEvent::RoomGuestAccess, c),
|
|
||||||
RoomHistoryVisibility(c) => conv(RoomEvent::RoomHistoryVisibility, c),
|
|
||||||
RoomJoinRules(c) => conv(RoomEvent::RoomJoinRules, c),
|
|
||||||
RoomMember(c) => conv(RoomEvent::RoomMember, c),
|
|
||||||
RoomMessage(c) => conv(RoomEvent::RoomMessage, c),
|
|
||||||
RoomMessageFeedback(c) => conv(RoomEvent::RoomMessageFeedback, c),
|
|
||||||
RoomName(c) => conv(RoomEvent::RoomName, c),
|
|
||||||
RoomPinnedEvents(c) => conv(RoomEvent::RoomPinnedEvents, c),
|
|
||||||
RoomPowerLevels(c) => conv(RoomEvent::RoomPowerLevels, c),
|
|
||||||
RoomRedaction(c) => conv(RoomEvent::RoomRedaction, c),
|
|
||||||
RoomServerAcl(c) => conv(RoomEvent::RoomServerAcl, c),
|
|
||||||
RoomThirdPartyInvite(c) => conv(RoomEvent::RoomThirdPartyInvite, c),
|
|
||||||
RoomTombstone(c) => conv(RoomEvent::RoomTombstone, c),
|
|
||||||
RoomTopic(c) => conv(RoomEvent::RoomTopic, c),
|
|
||||||
Sticker(c) => conv(RoomEvent::Sticker, c),
|
|
||||||
CustomRoom(c) => conv(RoomEvent::CustomRoom, c),
|
|
||||||
CustomState(c) => conv(RoomEvent::CustomState, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFromRaw for StateEvent {
|
|
||||||
type Raw = raw::StateEvent;
|
|
||||||
type Err = String;
|
|
||||||
|
|
||||||
fn try_from_raw(raw: raw::StateEvent) -> Result<Self, Self::Err> {
|
|
||||||
use crate::util::try_convert_variant as conv;
|
|
||||||
use raw::StateEvent::*;
|
|
||||||
|
|
||||||
match raw {
|
|
||||||
RoomAliases(c) => conv(StateEvent::RoomAliases, c),
|
|
||||||
RoomAvatar(c) => conv(StateEvent::RoomAvatar, c),
|
|
||||||
RoomCanonicalAlias(c) => conv(StateEvent::RoomCanonicalAlias, c),
|
|
||||||
RoomCreate(c) => conv(StateEvent::RoomCreate, c),
|
|
||||||
RoomEncryption(c) => conv(StateEvent::RoomEncryption, c),
|
|
||||||
RoomGuestAccess(c) => conv(StateEvent::RoomGuestAccess, c),
|
|
||||||
RoomHistoryVisibility(c) => conv(StateEvent::RoomHistoryVisibility, c),
|
|
||||||
RoomJoinRules(c) => conv(StateEvent::RoomJoinRules, c),
|
|
||||||
RoomMember(c) => conv(StateEvent::RoomMember, c),
|
|
||||||
RoomName(c) => conv(StateEvent::RoomName, c),
|
|
||||||
RoomPinnedEvents(c) => conv(StateEvent::RoomPinnedEvents, c),
|
|
||||||
RoomPowerLevels(c) => conv(StateEvent::RoomPowerLevels, c),
|
|
||||||
RoomServerAcl(c) => conv(StateEvent::RoomServerAcl, c),
|
|
||||||
RoomThirdPartyInvite(c) => conv(StateEvent::RoomThirdPartyInvite, c),
|
|
||||||
RoomTombstone(c) => conv(StateEvent::RoomTombstone, c),
|
|
||||||
RoomTopic(c) => conv(StateEvent::RoomTopic, c),
|
|
||||||
CustomState(c) => conv(StateEvent::CustomState, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_from_for_enum!(Event, AnswerEvent, CallAnswer);
|
|
||||||
impl_from_for_enum!(Event, CandidatesEvent, CallCandidates);
|
|
||||||
impl_from_for_enum!(Event, HangupEvent, CallHangup);
|
|
||||||
impl_from_for_enum!(Event, InviteEvent, CallInvite);
|
|
||||||
impl_from_for_enum!(Event, DirectEvent, Direct);
|
|
||||||
impl_from_for_enum!(Event, DummyEvent, Dummy);
|
|
||||||
impl_from_for_enum!(Event, ForwardedRoomKeyEvent, ForwardedRoomKey);
|
|
||||||
impl_from_for_enum!(Event, FullyReadEvent, FullyRead);
|
|
||||||
impl_from_for_enum!(Event, AcceptEvent, KeyVerificationAccept);
|
|
||||||
impl_from_for_enum!(Event, CancelEvent, KeyVerificationCancel);
|
|
||||||
impl_from_for_enum!(Event, KeyEvent, KeyVerificationKey);
|
|
||||||
impl_from_for_enum!(Event, MacEvent, KeyVerificationMac);
|
|
||||||
impl_from_for_enum!(Event, RequestEvent, KeyVerificationRequest);
|
|
||||||
impl_from_for_enum!(Event, StartEvent, KeyVerificationStart);
|
|
||||||
impl_from_for_enum!(Event, IgnoredUserListEvent, IgnoredUserList);
|
|
||||||
impl_from_for_enum!(Event, PresenceEvent, Presence);
|
|
||||||
impl_from_for_enum!(Event, PushRulesEvent, PushRules);
|
|
||||||
impl_from_for_enum!(Event, ReceiptEvent, Receipt);
|
|
||||||
impl_from_for_enum!(Event, AliasesEvent, RoomAliases);
|
|
||||||
impl_from_for_enum!(Event, AvatarEvent, RoomAvatar);
|
|
||||||
impl_from_for_enum!(Event, CanonicalAliasEvent, RoomCanonicalAlias);
|
|
||||||
impl_from_for_enum!(Event, CreateEvent, RoomCreate);
|
|
||||||
impl_from_for_enum!(Event, EncryptedEvent, RoomEncrypted);
|
|
||||||
impl_from_for_enum!(Event, EncryptionEvent, RoomEncryption);
|
|
||||||
impl_from_for_enum!(Event, GuestAccessEvent, RoomGuestAccess);
|
|
||||||
impl_from_for_enum!(Event, HistoryVisibilityEvent, RoomHistoryVisibility);
|
|
||||||
impl_from_for_enum!(Event, JoinRulesEvent, RoomJoinRules);
|
|
||||||
impl_from_for_enum!(Event, MemberEvent, RoomMember);
|
|
||||||
impl_from_for_enum!(Event, MessageEvent, RoomMessage);
|
|
||||||
impl_from_for_enum!(Event, FeedbackEvent, RoomMessageFeedback);
|
|
||||||
impl_from_for_enum!(Event, NameEvent, RoomName);
|
|
||||||
impl_from_for_enum!(Event, PinnedEventsEvent, RoomPinnedEvents);
|
|
||||||
impl_from_for_enum!(Event, PowerLevelsEvent, RoomPowerLevels);
|
|
||||||
impl_from_for_enum!(Event, RedactionEvent, RoomRedaction);
|
|
||||||
impl_from_for_enum!(Event, ServerAclEvent, RoomServerAcl);
|
|
||||||
impl_from_for_enum!(Event, ThirdPartyInviteEvent, RoomThirdPartyInvite);
|
|
||||||
impl_from_for_enum!(Event, TombstoneEvent, RoomTombstone);
|
|
||||||
impl_from_for_enum!(Event, TopicEvent, RoomTopic);
|
|
||||||
impl_from_for_enum!(Event, RoomKeyEvent, RoomKey);
|
|
||||||
impl_from_for_enum!(Event, RoomKeyRequestEvent, RoomKeyRequest);
|
|
||||||
impl_from_for_enum!(Event, StickerEvent, Sticker);
|
|
||||||
impl_from_for_enum!(Event, TagEvent, Tag);
|
|
||||||
impl_from_for_enum!(Event, TypingEvent, Typing);
|
|
||||||
impl_from_for_enum!(Event, CustomEvent, Custom);
|
|
||||||
impl_from_for_enum!(Event, CustomRoomEvent, CustomRoom);
|
|
||||||
impl_from_for_enum!(Event, CustomStateEvent, CustomState);
|
|
||||||
|
|
||||||
impl_from_for_enum!(RoomEvent, AnswerEvent, CallAnswer);
|
|
||||||
impl_from_for_enum!(RoomEvent, CandidatesEvent, CallCandidates);
|
|
||||||
impl_from_for_enum!(RoomEvent, HangupEvent, CallHangup);
|
|
||||||
impl_from_for_enum!(RoomEvent, InviteEvent, CallInvite);
|
|
||||||
impl_from_for_enum!(RoomEvent, AliasesEvent, RoomAliases);
|
|
||||||
impl_from_for_enum!(RoomEvent, AvatarEvent, RoomAvatar);
|
|
||||||
impl_from_for_enum!(RoomEvent, CanonicalAliasEvent, RoomCanonicalAlias);
|
|
||||||
impl_from_for_enum!(RoomEvent, CreateEvent, RoomCreate);
|
|
||||||
impl_from_for_enum!(RoomEvent, EncryptedEvent, RoomEncrypted);
|
|
||||||
impl_from_for_enum!(RoomEvent, EncryptionEvent, RoomEncryption);
|
|
||||||
impl_from_for_enum!(RoomEvent, GuestAccessEvent, RoomGuestAccess);
|
|
||||||
impl_from_for_enum!(RoomEvent, HistoryVisibilityEvent, RoomHistoryVisibility);
|
|
||||||
impl_from_for_enum!(RoomEvent, JoinRulesEvent, RoomJoinRules);
|
|
||||||
impl_from_for_enum!(RoomEvent, MemberEvent, RoomMember);
|
|
||||||
impl_from_for_enum!(RoomEvent, MessageEvent, RoomMessage);
|
|
||||||
impl_from_for_enum!(RoomEvent, FeedbackEvent, RoomMessageFeedback);
|
|
||||||
impl_from_for_enum!(RoomEvent, NameEvent, RoomName);
|
|
||||||
impl_from_for_enum!(RoomEvent, PinnedEventsEvent, RoomPinnedEvents);
|
|
||||||
impl_from_for_enum!(RoomEvent, PowerLevelsEvent, RoomPowerLevels);
|
|
||||||
impl_from_for_enum!(RoomEvent, RedactionEvent, RoomRedaction);
|
|
||||||
impl_from_for_enum!(RoomEvent, ServerAclEvent, RoomServerAcl);
|
|
||||||
impl_from_for_enum!(RoomEvent, StickerEvent, Sticker);
|
|
||||||
impl_from_for_enum!(RoomEvent, ThirdPartyInviteEvent, RoomThirdPartyInvite);
|
|
||||||
impl_from_for_enum!(RoomEvent, TombstoneEvent, RoomTombstone);
|
|
||||||
impl_from_for_enum!(RoomEvent, TopicEvent, RoomTopic);
|
|
||||||
impl_from_for_enum!(RoomEvent, CustomRoomEvent, CustomRoom);
|
|
||||||
impl_from_for_enum!(RoomEvent, CustomStateEvent, CustomState);
|
|
||||||
|
|
||||||
impl_from_for_enum!(StateEvent, AliasesEvent, RoomAliases);
|
|
||||||
impl_from_for_enum!(StateEvent, AvatarEvent, RoomAvatar);
|
|
||||||
impl_from_for_enum!(StateEvent, CanonicalAliasEvent, RoomCanonicalAlias);
|
|
||||||
impl_from_for_enum!(StateEvent, CreateEvent, RoomCreate);
|
|
||||||
impl_from_for_enum!(StateEvent, EncryptionEvent, RoomEncryption);
|
|
||||||
impl_from_for_enum!(StateEvent, GuestAccessEvent, RoomGuestAccess);
|
|
||||||
impl_from_for_enum!(StateEvent, HistoryVisibilityEvent, RoomHistoryVisibility);
|
|
||||||
impl_from_for_enum!(StateEvent, JoinRulesEvent, RoomJoinRules);
|
|
||||||
impl_from_for_enum!(StateEvent, MemberEvent, RoomMember);
|
|
||||||
impl_from_for_enum!(StateEvent, NameEvent, RoomName);
|
|
||||||
impl_from_for_enum!(StateEvent, PinnedEventsEvent, RoomPinnedEvents);
|
|
||||||
impl_from_for_enum!(StateEvent, PowerLevelsEvent, RoomPowerLevels);
|
|
||||||
impl_from_for_enum!(StateEvent, ServerAclEvent, RoomServerAcl);
|
|
||||||
impl_from_for_enum!(StateEvent, ThirdPartyInviteEvent, RoomThirdPartyInvite);
|
|
||||||
impl_from_for_enum!(StateEvent, TombstoneEvent, RoomTombstone);
|
|
||||||
impl_from_for_enum!(StateEvent, TopicEvent, RoomTopic);
|
|
||||||
impl_from_for_enum!(StateEvent, CustomStateEvent, CustomState);
|
|
@ -1,218 +0,0 @@
|
|||||||
//! Enums for heterogeneous collections of events, exclusive to event types that implement "at
|
|
||||||
//! most" the trait of the same name.
|
|
||||||
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
pub use super::all::StateEvent;
|
|
||||||
use super::raw::only as raw;
|
|
||||||
use crate::{
|
|
||||||
call::{
|
|
||||||
answer::AnswerEvent, candidates::CandidatesEvent, hangup::HangupEvent, invite::InviteEvent,
|
|
||||||
},
|
|
||||||
direct::DirectEvent,
|
|
||||||
dummy::DummyEvent,
|
|
||||||
forwarded_room_key::ForwardedRoomKeyEvent,
|
|
||||||
fully_read::FullyReadEvent,
|
|
||||||
ignored_user_list::IgnoredUserListEvent,
|
|
||||||
key::verification::{
|
|
||||||
accept::AcceptEvent, cancel::CancelEvent, key::KeyEvent, mac::MacEvent,
|
|
||||||
request::RequestEvent, start::StartEvent,
|
|
||||||
},
|
|
||||||
presence::PresenceEvent,
|
|
||||||
push_rules::PushRulesEvent,
|
|
||||||
receipt::ReceiptEvent,
|
|
||||||
room::{
|
|
||||||
encrypted::EncryptedEvent,
|
|
||||||
message::{feedback::FeedbackEvent, MessageEvent},
|
|
||||||
redaction::RedactionEvent,
|
|
||||||
},
|
|
||||||
room_key::RoomKeyEvent,
|
|
||||||
room_key_request::RoomKeyRequestEvent,
|
|
||||||
sticker::StickerEvent,
|
|
||||||
tag::TagEvent,
|
|
||||||
typing::TypingEvent,
|
|
||||||
CustomEvent, CustomRoomEvent, TryFromRaw,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// A basic event.
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum Event {
|
|
||||||
/// m.direct
|
|
||||||
Direct(DirectEvent),
|
|
||||||
|
|
||||||
/// m.dummy
|
|
||||||
Dummy(DummyEvent),
|
|
||||||
|
|
||||||
/// m.forwarded_room_key
|
|
||||||
ForwardedRoomKey(ForwardedRoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.fully_read
|
|
||||||
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
|
|
||||||
IgnoredUserList(IgnoredUserListEvent),
|
|
||||||
|
|
||||||
/// m.presence
|
|
||||||
Presence(PresenceEvent),
|
|
||||||
|
|
||||||
/// m.push_rules
|
|
||||||
PushRules(PushRulesEvent),
|
|
||||||
|
|
||||||
/// m.room_key
|
|
||||||
RoomKey(RoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.room_key_request
|
|
||||||
RoomKeyRequest(RoomKeyRequestEvent),
|
|
||||||
|
|
||||||
/// m.receipt
|
|
||||||
Receipt(ReceiptEvent),
|
|
||||||
|
|
||||||
/// m.tag
|
|
||||||
Tag(TagEvent),
|
|
||||||
|
|
||||||
/// m.typing
|
|
||||||
Typing(TypingEvent),
|
|
||||||
|
|
||||||
/// Any basic event that is not part of the specification.
|
|
||||||
Custom(CustomEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A room event.
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
#[serde(untagged)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum RoomEvent {
|
|
||||||
/// m.call.answer
|
|
||||||
CallAnswer(AnswerEvent),
|
|
||||||
|
|
||||||
/// m.call.candidates
|
|
||||||
CallCandidates(CandidatesEvent),
|
|
||||||
|
|
||||||
/// m.call.hangup
|
|
||||||
CallHangup(HangupEvent),
|
|
||||||
|
|
||||||
/// m.call.invite
|
|
||||||
CallInvite(InviteEvent),
|
|
||||||
|
|
||||||
/// m.room.encrypted
|
|
||||||
RoomEncrypted(EncryptedEvent),
|
|
||||||
|
|
||||||
/// m.room.message
|
|
||||||
RoomMessage(MessageEvent),
|
|
||||||
|
|
||||||
/// m.room.message.feedback
|
|
||||||
RoomMessageFeedback(FeedbackEvent),
|
|
||||||
|
|
||||||
/// m.room.redaction
|
|
||||||
RoomRedaction(RedactionEvent),
|
|
||||||
|
|
||||||
/// m.sticker
|
|
||||||
Sticker(StickerEvent),
|
|
||||||
|
|
||||||
/// Any room event that is not part of the specification.
|
|
||||||
CustomRoom(CustomRoomEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFromRaw for Event {
|
|
||||||
type Raw = raw::Event;
|
|
||||||
type Err = String;
|
|
||||||
|
|
||||||
fn try_from_raw(raw: raw::Event) -> Result<Self, Self::Err> {
|
|
||||||
use crate::util::try_convert_variant as conv;
|
|
||||||
use raw::Event::*;
|
|
||||||
|
|
||||||
match raw {
|
|
||||||
Direct(c) => conv(Event::Direct, c),
|
|
||||||
Dummy(c) => conv(Event::Dummy, c),
|
|
||||||
ForwardedRoomKey(c) => conv(Event::ForwardedRoomKey, c),
|
|
||||||
FullyRead(c) => conv(Event::FullyRead, c),
|
|
||||||
KeyVerificationAccept(c) => conv(Event::KeyVerificationAccept, c),
|
|
||||||
KeyVerificationCancel(c) => conv(Event::KeyVerificationCancel, c),
|
|
||||||
KeyVerificationKey(c) => conv(Event::KeyVerificationKey, c),
|
|
||||||
KeyVerificationMac(c) => conv(Event::KeyVerificationMac, c),
|
|
||||||
KeyVerificationRequest(c) => conv(Event::KeyVerificationRequest, c),
|
|
||||||
KeyVerificationStart(c) => conv(Event::KeyVerificationStart, c),
|
|
||||||
IgnoredUserList(c) => conv(Event::IgnoredUserList, c),
|
|
||||||
Presence(c) => conv(Event::Presence, c),
|
|
||||||
PushRules(c) => conv(Event::PushRules, c),
|
|
||||||
RoomKey(c) => conv(Event::RoomKey, c),
|
|
||||||
RoomKeyRequest(c) => conv(Event::RoomKeyRequest, c),
|
|
||||||
Receipt(c) => conv(Event::Receipt, c),
|
|
||||||
Tag(c) => conv(Event::Tag, c),
|
|
||||||
Typing(c) => conv(Event::Typing, c),
|
|
||||||
Custom(c) => conv(Event::Custom, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFromRaw for RoomEvent {
|
|
||||||
type Raw = raw::RoomEvent;
|
|
||||||
type Err = String;
|
|
||||||
|
|
||||||
fn try_from_raw(raw: raw::RoomEvent) -> Result<Self, Self::Err> {
|
|
||||||
use crate::util::try_convert_variant as conv;
|
|
||||||
use raw::RoomEvent::*;
|
|
||||||
|
|
||||||
match raw {
|
|
||||||
CallAnswer(c) => conv(RoomEvent::CallAnswer, c),
|
|
||||||
CallCandidates(c) => conv(RoomEvent::CallCandidates, c),
|
|
||||||
CallHangup(c) => conv(RoomEvent::CallHangup, c),
|
|
||||||
CallInvite(c) => conv(RoomEvent::CallInvite, c),
|
|
||||||
RoomEncrypted(c) => conv(RoomEvent::RoomEncrypted, c),
|
|
||||||
RoomMessage(c) => conv(RoomEvent::RoomMessage, c),
|
|
||||||
RoomMessageFeedback(c) => conv(RoomEvent::RoomMessageFeedback, c),
|
|
||||||
RoomRedaction(c) => conv(RoomEvent::RoomRedaction, c),
|
|
||||||
Sticker(c) => conv(RoomEvent::Sticker, c),
|
|
||||||
CustomRoom(c) => conv(RoomEvent::CustomRoom, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_from_for_enum!(Event, DirectEvent, Direct);
|
|
||||||
impl_from_for_enum!(Event, DummyEvent, Dummy);
|
|
||||||
impl_from_for_enum!(Event, ForwardedRoomKeyEvent, ForwardedRoomKey);
|
|
||||||
impl_from_for_enum!(Event, FullyReadEvent, FullyRead);
|
|
||||||
impl_from_for_enum!(Event, AcceptEvent, KeyVerificationAccept);
|
|
||||||
impl_from_for_enum!(Event, CancelEvent, KeyVerificationCancel);
|
|
||||||
impl_from_for_enum!(Event, KeyEvent, KeyVerificationKey);
|
|
||||||
impl_from_for_enum!(Event, MacEvent, KeyVerificationMac);
|
|
||||||
impl_from_for_enum!(Event, RequestEvent, KeyVerificationRequest);
|
|
||||||
impl_from_for_enum!(Event, StartEvent, KeyVerificationStart);
|
|
||||||
impl_from_for_enum!(Event, IgnoredUserListEvent, IgnoredUserList);
|
|
||||||
impl_from_for_enum!(Event, PresenceEvent, Presence);
|
|
||||||
impl_from_for_enum!(Event, PushRulesEvent, PushRules);
|
|
||||||
impl_from_for_enum!(Event, ReceiptEvent, Receipt);
|
|
||||||
impl_from_for_enum!(Event, TagEvent, Tag);
|
|
||||||
impl_from_for_enum!(Event, TypingEvent, Typing);
|
|
||||||
impl_from_for_enum!(Event, CustomEvent, Custom);
|
|
||||||
|
|
||||||
impl_from_for_enum!(RoomEvent, AnswerEvent, CallAnswer);
|
|
||||||
impl_from_for_enum!(RoomEvent, CandidatesEvent, CallCandidates);
|
|
||||||
impl_from_for_enum!(RoomEvent, HangupEvent, CallHangup);
|
|
||||||
impl_from_for_enum!(RoomEvent, InviteEvent, CallInvite);
|
|
||||||
impl_from_for_enum!(RoomEvent, EncryptedEvent, RoomEncrypted);
|
|
||||||
impl_from_for_enum!(RoomEvent, MessageEvent, RoomMessage);
|
|
||||||
impl_from_for_enum!(RoomEvent, FeedbackEvent, RoomMessageFeedback);
|
|
||||||
impl_from_for_enum!(RoomEvent, RedactionEvent, RoomRedaction);
|
|
||||||
impl_from_for_enum!(RoomEvent, StickerEvent, Sticker);
|
|
||||||
impl_from_for_enum!(RoomEvent, CustomRoomEvent, CustomRoom);
|
|
@ -1,651 +0,0 @@
|
|||||||
//! Enums for heterogeneous collections of events, inclusive for every event type that implements
|
|
||||||
//! the trait of the same name.
|
|
||||||
|
|
||||||
use serde::{de::Error as _, Deserialize, Deserializer};
|
|
||||||
use serde_json::Value as JsonValue;
|
|
||||||
|
|
||||||
use super::only;
|
|
||||||
use crate::{
|
|
||||||
call::{
|
|
||||||
answer::raw::AnswerEvent, candidates::raw::CandidatesEvent, hangup::raw::HangupEvent,
|
|
||||||
invite::raw::InviteEvent,
|
|
||||||
},
|
|
||||||
custom::raw::{CustomEvent, CustomRoomEvent, CustomStateEvent},
|
|
||||||
direct::raw::DirectEvent,
|
|
||||||
dummy::raw::DummyEvent,
|
|
||||||
forwarded_room_key::raw::ForwardedRoomKeyEvent,
|
|
||||||
fully_read::raw::FullyReadEvent,
|
|
||||||
ignored_user_list::raw::IgnoredUserListEvent,
|
|
||||||
key::verification::{
|
|
||||||
accept::raw::AcceptEvent, cancel::raw::CancelEvent, key::raw::KeyEvent, mac::raw::MacEvent,
|
|
||||||
request::raw::RequestEvent, start::raw::StartEvent,
|
|
||||||
},
|
|
||||||
presence::raw::PresenceEvent,
|
|
||||||
push_rules::raw::PushRulesEvent,
|
|
||||||
receipt::raw::ReceiptEvent,
|
|
||||||
room::{
|
|
||||||
aliases::raw::AliasesEvent,
|
|
||||||
avatar::raw::AvatarEvent,
|
|
||||||
canonical_alias::raw::CanonicalAliasEvent,
|
|
||||||
create::raw::CreateEvent,
|
|
||||||
encrypted::raw::EncryptedEvent,
|
|
||||||
encryption::raw::EncryptionEvent,
|
|
||||||
guest_access::raw::GuestAccessEvent,
|
|
||||||
history_visibility::raw::HistoryVisibilityEvent,
|
|
||||||
join_rules::raw::JoinRulesEvent,
|
|
||||||
member::raw::MemberEvent,
|
|
||||||
message::{feedback::raw::FeedbackEvent, raw::MessageEvent},
|
|
||||||
name::raw::NameEvent,
|
|
||||||
pinned_events::raw::PinnedEventsEvent,
|
|
||||||
power_levels::raw::PowerLevelsEvent,
|
|
||||||
redaction::raw::RedactionEvent,
|
|
||||||
server_acl::raw::ServerAclEvent,
|
|
||||||
third_party_invite::raw::ThirdPartyInviteEvent,
|
|
||||||
tombstone::raw::TombstoneEvent,
|
|
||||||
topic::raw::TopicEvent,
|
|
||||||
},
|
|
||||||
room_key::raw::RoomKeyEvent,
|
|
||||||
room_key_request::raw::RoomKeyRequestEvent,
|
|
||||||
sticker::raw::StickerEvent,
|
|
||||||
tag::raw::TagEvent,
|
|
||||||
typing::raw::TypingEvent,
|
|
||||||
util::get_field,
|
|
||||||
EventType,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// A basic event, room event, or state event.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum Event {
|
|
||||||
/// m.call.answer
|
|
||||||
CallAnswer(AnswerEvent),
|
|
||||||
|
|
||||||
/// m.call.candidates
|
|
||||||
CallCandidates(CandidatesEvent),
|
|
||||||
|
|
||||||
/// m.call.hangup
|
|
||||||
CallHangup(HangupEvent),
|
|
||||||
|
|
||||||
/// m.call.invite
|
|
||||||
CallInvite(InviteEvent),
|
|
||||||
|
|
||||||
/// m.direct
|
|
||||||
Direct(DirectEvent),
|
|
||||||
|
|
||||||
/// m.dummy
|
|
||||||
Dummy(DummyEvent),
|
|
||||||
|
|
||||||
/// m.forwarded_room_key
|
|
||||||
ForwardedRoomKey(ForwardedRoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.fully_read
|
|
||||||
FullyRead(FullyReadEvent),
|
|
||||||
|
|
||||||
/// m.ignored_user_list
|
|
||||||
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
|
|
||||||
Presence(PresenceEvent),
|
|
||||||
|
|
||||||
/// m.push_rules
|
|
||||||
PushRules(PushRulesEvent),
|
|
||||||
|
|
||||||
/// m.receipt
|
|
||||||
Receipt(ReceiptEvent),
|
|
||||||
|
|
||||||
/// m.room.aliases
|
|
||||||
RoomAliases(AliasesEvent),
|
|
||||||
|
|
||||||
/// m.room.avatar
|
|
||||||
RoomAvatar(AvatarEvent),
|
|
||||||
|
|
||||||
/// m.room.canonical_alias
|
|
||||||
RoomCanonicalAlias(CanonicalAliasEvent),
|
|
||||||
|
|
||||||
/// m.room.create
|
|
||||||
RoomCreate(CreateEvent),
|
|
||||||
|
|
||||||
/// m.room.encrypted
|
|
||||||
RoomEncrypted(EncryptedEvent),
|
|
||||||
|
|
||||||
/// m.room.encryption
|
|
||||||
RoomEncryption(EncryptionEvent),
|
|
||||||
|
|
||||||
/// m.room.guest_access
|
|
||||||
RoomGuestAccess(GuestAccessEvent),
|
|
||||||
|
|
||||||
/// m.room.history_visibility
|
|
||||||
RoomHistoryVisibility(HistoryVisibilityEvent),
|
|
||||||
|
|
||||||
/// m.room.join_rules
|
|
||||||
RoomJoinRules(JoinRulesEvent),
|
|
||||||
|
|
||||||
/// m.room.member
|
|
||||||
RoomMember(MemberEvent),
|
|
||||||
|
|
||||||
/// m.room.message
|
|
||||||
RoomMessage(MessageEvent),
|
|
||||||
|
|
||||||
/// m.room.message.feedback
|
|
||||||
RoomMessageFeedback(FeedbackEvent),
|
|
||||||
|
|
||||||
/// m.room.name
|
|
||||||
RoomName(NameEvent),
|
|
||||||
|
|
||||||
/// m.room.pinned_events
|
|
||||||
RoomPinnedEvents(PinnedEventsEvent),
|
|
||||||
|
|
||||||
/// m.room.power_levels
|
|
||||||
RoomPowerLevels(PowerLevelsEvent),
|
|
||||||
|
|
||||||
/// m.room.redaction
|
|
||||||
RoomRedaction(RedactionEvent),
|
|
||||||
|
|
||||||
/// m.room.server_acl
|
|
||||||
RoomServerAcl(ServerAclEvent),
|
|
||||||
|
|
||||||
/// m.room.third_party_invite
|
|
||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
|
||||||
|
|
||||||
/// m.room.tombstone
|
|
||||||
RoomTombstone(TombstoneEvent),
|
|
||||||
|
|
||||||
/// m.room.topic
|
|
||||||
RoomTopic(TopicEvent),
|
|
||||||
|
|
||||||
/// m.room_key
|
|
||||||
RoomKey(RoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.room_key_request
|
|
||||||
RoomKeyRequest(RoomKeyRequestEvent),
|
|
||||||
|
|
||||||
/// m.sticker
|
|
||||||
Sticker(StickerEvent),
|
|
||||||
|
|
||||||
/// m.tag
|
|
||||||
Tag(TagEvent),
|
|
||||||
|
|
||||||
/// m.typing
|
|
||||||
Typing(TypingEvent),
|
|
||||||
|
|
||||||
/// Any basic event that is not part of the specification.
|
|
||||||
Custom(CustomEvent),
|
|
||||||
|
|
||||||
/// Any room event that is not part of the specification.
|
|
||||||
CustomRoom(CustomRoomEvent),
|
|
||||||
|
|
||||||
/// Any state event that is not part of the specification.
|
|
||||||
CustomState(CustomStateEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A room event or state event.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum RoomEvent {
|
|
||||||
/// m.call.answer
|
|
||||||
CallAnswer(AnswerEvent),
|
|
||||||
|
|
||||||
/// m.call.candidates
|
|
||||||
CallCandidates(CandidatesEvent),
|
|
||||||
|
|
||||||
/// m.call.hangup
|
|
||||||
CallHangup(HangupEvent),
|
|
||||||
|
|
||||||
/// m.call.invite
|
|
||||||
CallInvite(InviteEvent),
|
|
||||||
|
|
||||||
/// m.room.aliases
|
|
||||||
RoomAliases(AliasesEvent),
|
|
||||||
|
|
||||||
/// m.room.avatar
|
|
||||||
RoomAvatar(AvatarEvent),
|
|
||||||
|
|
||||||
/// m.room.canonical_alias
|
|
||||||
RoomCanonicalAlias(CanonicalAliasEvent),
|
|
||||||
|
|
||||||
/// m.room.create
|
|
||||||
RoomCreate(CreateEvent),
|
|
||||||
|
|
||||||
/// m.room.encrypted
|
|
||||||
RoomEncrypted(EncryptedEvent),
|
|
||||||
|
|
||||||
/// m.room.encryption
|
|
||||||
RoomEncryption(EncryptionEvent),
|
|
||||||
|
|
||||||
/// m.room.guest_access
|
|
||||||
RoomGuestAccess(GuestAccessEvent),
|
|
||||||
|
|
||||||
/// m.room.history_visibility
|
|
||||||
RoomHistoryVisibility(HistoryVisibilityEvent),
|
|
||||||
|
|
||||||
/// m.room.join_rules
|
|
||||||
RoomJoinRules(JoinRulesEvent),
|
|
||||||
|
|
||||||
/// m.room.member
|
|
||||||
RoomMember(MemberEvent),
|
|
||||||
|
|
||||||
/// m.room.message
|
|
||||||
RoomMessage(MessageEvent),
|
|
||||||
|
|
||||||
/// m.room.message.feedback
|
|
||||||
RoomMessageFeedback(FeedbackEvent),
|
|
||||||
|
|
||||||
/// m.room.name
|
|
||||||
RoomName(NameEvent),
|
|
||||||
|
|
||||||
/// m.room.pinned_events
|
|
||||||
RoomPinnedEvents(PinnedEventsEvent),
|
|
||||||
|
|
||||||
/// m.room.power_levels
|
|
||||||
RoomPowerLevels(PowerLevelsEvent),
|
|
||||||
|
|
||||||
/// m.room.redaction
|
|
||||||
RoomRedaction(RedactionEvent),
|
|
||||||
|
|
||||||
/// m.room.server_acl
|
|
||||||
RoomServerAcl(ServerAclEvent),
|
|
||||||
|
|
||||||
/// m.room.third_party_invite
|
|
||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
|
||||||
|
|
||||||
/// m.room.tombstone
|
|
||||||
RoomTombstone(TombstoneEvent),
|
|
||||||
|
|
||||||
/// m.room.topic
|
|
||||||
RoomTopic(TopicEvent),
|
|
||||||
|
|
||||||
/// m.sticker
|
|
||||||
Sticker(StickerEvent),
|
|
||||||
|
|
||||||
/// Any room event that is not part of the specification.
|
|
||||||
CustomRoom(CustomRoomEvent),
|
|
||||||
|
|
||||||
/// Any state event that is not part of the specification.
|
|
||||||
CustomState(CustomStateEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A state event.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum StateEvent {
|
|
||||||
/// m.room.aliases
|
|
||||||
RoomAliases(AliasesEvent),
|
|
||||||
|
|
||||||
/// m.room.avatar
|
|
||||||
RoomAvatar(AvatarEvent),
|
|
||||||
|
|
||||||
/// m.room.canonical_alias
|
|
||||||
RoomCanonicalAlias(CanonicalAliasEvent),
|
|
||||||
|
|
||||||
/// m.room.create
|
|
||||||
RoomCreate(CreateEvent),
|
|
||||||
|
|
||||||
/// m.room.encryption
|
|
||||||
RoomEncryption(EncryptionEvent),
|
|
||||||
|
|
||||||
/// m.room.guest_access
|
|
||||||
RoomGuestAccess(GuestAccessEvent),
|
|
||||||
|
|
||||||
/// m.room.history_visibility
|
|
||||||
RoomHistoryVisibility(HistoryVisibilityEvent),
|
|
||||||
|
|
||||||
/// m.room.join_rules
|
|
||||||
RoomJoinRules(JoinRulesEvent),
|
|
||||||
|
|
||||||
/// m.room.member
|
|
||||||
RoomMember(MemberEvent),
|
|
||||||
|
|
||||||
/// m.room.name
|
|
||||||
RoomName(NameEvent),
|
|
||||||
|
|
||||||
/// m.room.pinned_events
|
|
||||||
RoomPinnedEvents(PinnedEventsEvent),
|
|
||||||
|
|
||||||
/// m.room.power_levels
|
|
||||||
RoomPowerLevels(PowerLevelsEvent),
|
|
||||||
|
|
||||||
/// m.room.server_acl
|
|
||||||
RoomServerAcl(ServerAclEvent),
|
|
||||||
|
|
||||||
/// m.room.third_party_invite
|
|
||||||
RoomThirdPartyInvite(ThirdPartyInviteEvent),
|
|
||||||
|
|
||||||
/// m.room.tombstone
|
|
||||||
RoomTombstone(TombstoneEvent),
|
|
||||||
|
|
||||||
/// m.room.topic
|
|
||||||
RoomTopic(TopicEvent),
|
|
||||||
|
|
||||||
/// Any state event that is not part of the specification.
|
|
||||||
CustomState(CustomStateEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Event {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use crate::util::try_variant_from_value as from_value;
|
|
||||||
use EventType::*;
|
|
||||||
|
|
||||||
let value = JsonValue::deserialize(deserializer)?;
|
|
||||||
let event_type = get_field(&value, "type")?;
|
|
||||||
|
|
||||||
match event_type {
|
|
||||||
CallAnswer => from_value(value, Event::CallAnswer),
|
|
||||||
CallCandidates => from_value(value, Event::CallCandidates),
|
|
||||||
CallHangup => from_value(value, Event::CallHangup),
|
|
||||||
CallInvite => from_value(value, Event::CallInvite),
|
|
||||||
Direct => from_value(value, Event::Direct),
|
|
||||||
Dummy => from_value(value, Event::Dummy),
|
|
||||||
ForwardedRoomKey => from_value(value, Event::ForwardedRoomKey),
|
|
||||||
FullyRead => from_value(value, Event::FullyRead),
|
|
||||||
IgnoredUserList => from_value(value, Event::IgnoredUserList),
|
|
||||||
KeyVerificationAccept => from_value(value, Event::KeyVerificationAccept),
|
|
||||||
KeyVerificationCancel => from_value(value, Event::KeyVerificationCancel),
|
|
||||||
KeyVerificationKey => from_value(value, Event::KeyVerificationKey),
|
|
||||||
KeyVerificationMac => from_value(value, Event::KeyVerificationMac),
|
|
||||||
KeyVerificationRequest => from_value(value, Event::KeyVerificationRequest),
|
|
||||||
KeyVerificationStart => from_value(value, Event::KeyVerificationStart),
|
|
||||||
Presence => from_value(value, Event::Presence),
|
|
||||||
PushRules => from_value(value, Event::PushRules),
|
|
||||||
Receipt => from_value(value, Event::Receipt),
|
|
||||||
RoomAliases => from_value(value, Event::RoomAliases),
|
|
||||||
RoomAvatar => from_value(value, Event::RoomAvatar),
|
|
||||||
RoomCanonicalAlias => from_value(value, Event::RoomCanonicalAlias),
|
|
||||||
RoomCreate => from_value(value, Event::RoomCreate),
|
|
||||||
RoomEncrypted => from_value(value, Event::RoomEncrypted),
|
|
||||||
RoomEncryption => from_value(value, Event::RoomEncryption),
|
|
||||||
RoomGuestAccess => from_value(value, Event::RoomGuestAccess),
|
|
||||||
RoomHistoryVisibility => from_value(value, Event::RoomHistoryVisibility),
|
|
||||||
RoomJoinRules => from_value(value, Event::RoomJoinRules),
|
|
||||||
RoomMember => from_value(value, Event::RoomMember),
|
|
||||||
RoomMessage => from_value(value, Event::RoomMessage),
|
|
||||||
RoomMessageFeedback => from_value(value, Event::RoomMessageFeedback),
|
|
||||||
RoomName => from_value(value, Event::RoomName),
|
|
||||||
RoomPinnedEvents => from_value(value, Event::RoomPinnedEvents),
|
|
||||||
RoomPowerLevels => from_value(value, Event::RoomPowerLevels),
|
|
||||||
RoomRedaction => from_value(value, Event::RoomRedaction),
|
|
||||||
RoomServerAcl => from_value(value, Event::RoomServerAcl),
|
|
||||||
RoomThirdPartyInvite => from_value(value, Event::RoomThirdPartyInvite),
|
|
||||||
RoomTombstone => from_value(value, Event::RoomTombstone),
|
|
||||||
RoomTopic => from_value(value, Event::RoomTopic),
|
|
||||||
RoomKey => from_value(value, Event::RoomKey),
|
|
||||||
RoomKeyRequest => from_value(value, Event::RoomKeyRequest),
|
|
||||||
Sticker => from_value(value, Event::Sticker),
|
|
||||||
Tag => from_value(value, Event::Tag),
|
|
||||||
Typing => from_value(value, Event::Typing),
|
|
||||||
Custom(_event_type_name) => {
|
|
||||||
if value.get("state_key").is_some() {
|
|
||||||
from_value(value, Event::CustomState)
|
|
||||||
} else if value.get("event_id").is_some()
|
|
||||||
&& value.get("room_id").is_some()
|
|
||||||
&& value.get("sender").is_some()
|
|
||||||
{
|
|
||||||
from_value(value, Event::CustomRoom)
|
|
||||||
} else {
|
|
||||||
from_value(value, Event::Custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for RoomEvent {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use crate::util::try_variant_from_value as from_value;
|
|
||||||
use EventType::*;
|
|
||||||
|
|
||||||
let value = JsonValue::deserialize(deserializer)?;
|
|
||||||
let event_type = get_field(&value, "type")?;
|
|
||||||
|
|
||||||
match event_type {
|
|
||||||
CallAnswer => from_value(value, RoomEvent::CallAnswer),
|
|
||||||
CallCandidates => from_value(value, RoomEvent::CallCandidates),
|
|
||||||
CallHangup => from_value(value, RoomEvent::CallHangup),
|
|
||||||
CallInvite => from_value(value, RoomEvent::CallInvite),
|
|
||||||
RoomAliases => from_value(value, RoomEvent::RoomAliases),
|
|
||||||
RoomAvatar => from_value(value, RoomEvent::RoomAvatar),
|
|
||||||
RoomCanonicalAlias => from_value(value, RoomEvent::RoomCanonicalAlias),
|
|
||||||
RoomCreate => from_value(value, RoomEvent::RoomCreate),
|
|
||||||
RoomEncrypted => from_value(value, RoomEvent::RoomEncrypted),
|
|
||||||
RoomEncryption => from_value(value, RoomEvent::RoomEncryption),
|
|
||||||
RoomGuestAccess => from_value(value, RoomEvent::RoomGuestAccess),
|
|
||||||
RoomHistoryVisibility => from_value(value, RoomEvent::RoomHistoryVisibility),
|
|
||||||
RoomJoinRules => from_value(value, RoomEvent::RoomJoinRules),
|
|
||||||
RoomMember => from_value(value, RoomEvent::RoomMember),
|
|
||||||
RoomMessage => from_value(value, RoomEvent::RoomMessage),
|
|
||||||
RoomMessageFeedback => from_value(value, RoomEvent::RoomMessageFeedback),
|
|
||||||
RoomName => from_value(value, RoomEvent::RoomName),
|
|
||||||
RoomPinnedEvents => from_value(value, RoomEvent::RoomPinnedEvents),
|
|
||||||
RoomPowerLevels => from_value(value, RoomEvent::RoomPowerLevels),
|
|
||||||
RoomRedaction => from_value(value, RoomEvent::RoomRedaction),
|
|
||||||
RoomServerAcl => from_value(value, RoomEvent::RoomServerAcl),
|
|
||||||
RoomThirdPartyInvite => from_value(value, RoomEvent::RoomThirdPartyInvite),
|
|
||||||
RoomTombstone => from_value(value, RoomEvent::RoomTombstone),
|
|
||||||
RoomTopic => from_value(value, RoomEvent::RoomTopic),
|
|
||||||
Sticker => from_value(value, RoomEvent::Sticker),
|
|
||||||
Custom(_event_type_name) => {
|
|
||||||
if value.get("state_key").is_some() {
|
|
||||||
from_value(value, RoomEvent::CustomState)
|
|
||||||
} else {
|
|
||||||
from_value(value, RoomEvent::CustomRoom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Direct
|
|
||||||
| Dummy
|
|
||||||
| ForwardedRoomKey
|
|
||||||
| FullyRead
|
|
||||||
| IgnoredUserList
|
|
||||||
| KeyVerificationAccept
|
|
||||||
| KeyVerificationCancel
|
|
||||||
| KeyVerificationKey
|
|
||||||
| KeyVerificationMac
|
|
||||||
| KeyVerificationRequest
|
|
||||||
| KeyVerificationStart
|
|
||||||
| Presence
|
|
||||||
| PushRules
|
|
||||||
| Receipt
|
|
||||||
| RoomKey
|
|
||||||
| RoomKeyRequest
|
|
||||||
| Tag
|
|
||||||
| Typing => Err(D::Error::custom("invalid event type")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for StateEvent {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use crate::util::try_variant_from_value as from_value;
|
|
||||||
use EventType::*;
|
|
||||||
|
|
||||||
let value = JsonValue::deserialize(deserializer)?;
|
|
||||||
let event_type = get_field(&value, "type")?;
|
|
||||||
|
|
||||||
match event_type {
|
|
||||||
RoomAliases => from_value(value, StateEvent::RoomAliases),
|
|
||||||
RoomAvatar => from_value(value, StateEvent::RoomAvatar),
|
|
||||||
RoomCanonicalAlias => from_value(value, StateEvent::RoomCanonicalAlias),
|
|
||||||
RoomCreate => from_value(value, StateEvent::RoomCreate),
|
|
||||||
RoomEncryption => from_value(value, StateEvent::RoomEncryption),
|
|
||||||
RoomGuestAccess => from_value(value, StateEvent::RoomGuestAccess),
|
|
||||||
RoomHistoryVisibility => from_value(value, StateEvent::RoomHistoryVisibility),
|
|
||||||
RoomJoinRules => from_value(value, StateEvent::RoomJoinRules),
|
|
||||||
RoomMember => from_value(value, StateEvent::RoomMember),
|
|
||||||
RoomName => from_value(value, StateEvent::RoomName),
|
|
||||||
RoomPinnedEvents => from_value(value, StateEvent::RoomPinnedEvents),
|
|
||||||
RoomPowerLevels => from_value(value, StateEvent::RoomPowerLevels),
|
|
||||||
RoomServerAcl => from_value(value, StateEvent::RoomServerAcl),
|
|
||||||
RoomThirdPartyInvite => from_value(value, StateEvent::RoomThirdPartyInvite),
|
|
||||||
RoomTombstone => from_value(value, StateEvent::RoomTombstone),
|
|
||||||
RoomTopic => from_value(value, StateEvent::RoomTopic),
|
|
||||||
Custom(_event_type_name) => from_value(value, StateEvent::CustomState),
|
|
||||||
CallAnswer
|
|
||||||
| CallCandidates
|
|
||||||
| CallHangup
|
|
||||||
| CallInvite
|
|
||||||
| Direct
|
|
||||||
| Dummy
|
|
||||||
| ForwardedRoomKey
|
|
||||||
| FullyRead
|
|
||||||
| IgnoredUserList
|
|
||||||
| KeyVerificationAccept
|
|
||||||
| KeyVerificationCancel
|
|
||||||
| KeyVerificationKey
|
|
||||||
| KeyVerificationMac
|
|
||||||
| KeyVerificationRequest
|
|
||||||
| KeyVerificationStart
|
|
||||||
| Presence
|
|
||||||
| PushRules
|
|
||||||
| Receipt
|
|
||||||
| RoomEncrypted
|
|
||||||
| RoomKey
|
|
||||||
| RoomKeyRequest
|
|
||||||
| RoomMessage
|
|
||||||
| RoomMessageFeedback
|
|
||||||
| RoomRedaction
|
|
||||||
| Sticker
|
|
||||||
| Tag
|
|
||||||
| Typing => Err(D::Error::custom("invalid event type")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<only::Event> for Event {
|
|
||||||
fn from(event: only::Event) -> Self {
|
|
||||||
use only::Event::*;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Direct(ev) => Event::Direct(ev),
|
|
||||||
Dummy(ev) => Event::Dummy(ev),
|
|
||||||
ForwardedRoomKey(ev) => Event::ForwardedRoomKey(ev),
|
|
||||||
FullyRead(ev) => Event::FullyRead(ev),
|
|
||||||
KeyVerificationAccept(ev) => Event::KeyVerificationAccept(ev),
|
|
||||||
KeyVerificationCancel(ev) => Event::KeyVerificationCancel(ev),
|
|
||||||
KeyVerificationKey(ev) => Event::KeyVerificationKey(ev),
|
|
||||||
KeyVerificationMac(ev) => Event::KeyVerificationMac(ev),
|
|
||||||
KeyVerificationRequest(ev) => Event::KeyVerificationRequest(ev),
|
|
||||||
KeyVerificationStart(ev) => Event::KeyVerificationStart(ev),
|
|
||||||
IgnoredUserList(ev) => Event::IgnoredUserList(ev),
|
|
||||||
Presence(ev) => Event::Presence(ev),
|
|
||||||
PushRules(ev) => Event::PushRules(ev),
|
|
||||||
RoomKey(ev) => Event::RoomKey(ev),
|
|
||||||
RoomKeyRequest(ev) => Event::RoomKeyRequest(ev),
|
|
||||||
Receipt(ev) => Event::Receipt(ev),
|
|
||||||
Tag(ev) => Event::Tag(ev),
|
|
||||||
Typing(ev) => Event::Typing(ev),
|
|
||||||
Custom(ev) => Event::Custom(ev),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<RoomEvent> for Event {
|
|
||||||
fn from(room_event: RoomEvent) -> Self {
|
|
||||||
use RoomEvent::*;
|
|
||||||
|
|
||||||
match room_event {
|
|
||||||
CallAnswer(ev) => Event::CallAnswer(ev),
|
|
||||||
CallCandidates(ev) => Event::CallCandidates(ev),
|
|
||||||
CallHangup(ev) => Event::CallHangup(ev),
|
|
||||||
CallInvite(ev) => Event::CallInvite(ev),
|
|
||||||
RoomAliases(ev) => Event::RoomAliases(ev),
|
|
||||||
RoomAvatar(ev) => Event::RoomAvatar(ev),
|
|
||||||
RoomCanonicalAlias(ev) => Event::RoomCanonicalAlias(ev),
|
|
||||||
RoomCreate(ev) => Event::RoomCreate(ev),
|
|
||||||
RoomEncrypted(ev) => Event::RoomEncrypted(ev),
|
|
||||||
RoomEncryption(ev) => Event::RoomEncryption(ev),
|
|
||||||
RoomGuestAccess(ev) => Event::RoomGuestAccess(ev),
|
|
||||||
RoomHistoryVisibility(ev) => Event::RoomHistoryVisibility(ev),
|
|
||||||
RoomJoinRules(ev) => Event::RoomJoinRules(ev),
|
|
||||||
RoomMember(ev) => Event::RoomMember(ev),
|
|
||||||
RoomMessage(ev) => Event::RoomMessage(ev),
|
|
||||||
RoomMessageFeedback(ev) => Event::RoomMessageFeedback(ev),
|
|
||||||
RoomName(ev) => Event::RoomName(ev),
|
|
||||||
RoomPinnedEvents(ev) => Event::RoomPinnedEvents(ev),
|
|
||||||
RoomPowerLevels(ev) => Event::RoomPowerLevels(ev),
|
|
||||||
RoomRedaction(ev) => Event::RoomRedaction(ev),
|
|
||||||
RoomServerAcl(ev) => Event::RoomServerAcl(ev),
|
|
||||||
RoomThirdPartyInvite(ev) => Event::RoomThirdPartyInvite(ev),
|
|
||||||
RoomTombstone(ev) => Event::RoomTombstone(ev),
|
|
||||||
RoomTopic(ev) => Event::RoomTopic(ev),
|
|
||||||
Sticker(ev) => Event::Sticker(ev),
|
|
||||||
CustomRoom(ev) => Event::CustomRoom(ev),
|
|
||||||
CustomState(ev) => Event::CustomState(ev),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<only::RoomEvent> for RoomEvent {
|
|
||||||
fn from(room_event: only::RoomEvent) -> Self {
|
|
||||||
use only::RoomEvent::*;
|
|
||||||
|
|
||||||
match room_event {
|
|
||||||
CallAnswer(ev) => RoomEvent::CallAnswer(ev),
|
|
||||||
CallCandidates(ev) => RoomEvent::CallCandidates(ev),
|
|
||||||
CallHangup(ev) => RoomEvent::CallHangup(ev),
|
|
||||||
CallInvite(ev) => RoomEvent::CallInvite(ev),
|
|
||||||
RoomEncrypted(ev) => RoomEvent::RoomEncrypted(ev),
|
|
||||||
RoomMessage(ev) => RoomEvent::RoomMessage(ev),
|
|
||||||
RoomMessageFeedback(ev) => RoomEvent::RoomMessageFeedback(ev),
|
|
||||||
RoomRedaction(ev) => RoomEvent::RoomRedaction(ev),
|
|
||||||
Sticker(ev) => RoomEvent::Sticker(ev),
|
|
||||||
CustomRoom(ev) => RoomEvent::CustomRoom(ev),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StateEvent> for RoomEvent {
|
|
||||||
fn from(state_event: StateEvent) -> Self {
|
|
||||||
use StateEvent::*;
|
|
||||||
|
|
||||||
match state_event {
|
|
||||||
RoomAliases(ev) => RoomEvent::RoomAliases(ev),
|
|
||||||
RoomAvatar(ev) => RoomEvent::RoomAvatar(ev),
|
|
||||||
RoomCanonicalAlias(ev) => RoomEvent::RoomCanonicalAlias(ev),
|
|
||||||
RoomCreate(ev) => RoomEvent::RoomCreate(ev),
|
|
||||||
RoomEncryption(ev) => RoomEvent::RoomEncryption(ev),
|
|
||||||
RoomGuestAccess(ev) => RoomEvent::RoomGuestAccess(ev),
|
|
||||||
RoomHistoryVisibility(ev) => RoomEvent::RoomHistoryVisibility(ev),
|
|
||||||
RoomJoinRules(ev) => RoomEvent::RoomJoinRules(ev),
|
|
||||||
RoomMember(ev) => RoomEvent::RoomMember(ev),
|
|
||||||
RoomName(ev) => RoomEvent::RoomName(ev),
|
|
||||||
RoomPinnedEvents(ev) => RoomEvent::RoomPinnedEvents(ev),
|
|
||||||
RoomPowerLevels(ev) => RoomEvent::RoomPowerLevels(ev),
|
|
||||||
RoomServerAcl(ev) => RoomEvent::RoomServerAcl(ev),
|
|
||||||
RoomThirdPartyInvite(ev) => RoomEvent::RoomThirdPartyInvite(ev),
|
|
||||||
RoomTombstone(ev) => RoomEvent::RoomTombstone(ev),
|
|
||||||
RoomTopic(ev) => RoomEvent::RoomTopic(ev),
|
|
||||||
CustomState(ev) => RoomEvent::CustomState(ev),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StateEvent> for Event {
|
|
||||||
fn from(state_event: StateEvent) -> Self {
|
|
||||||
Event::from(RoomEvent::from(state_event))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,255 +0,0 @@
|
|||||||
//! Enums for heterogeneous collections of events, exclusive to event types that implement "at
|
|
||||||
//! most" the trait of the same name.
|
|
||||||
|
|
||||||
use serde::{de::Error as _, Deserialize, Deserializer};
|
|
||||||
use serde_json::Value as JsonValue;
|
|
||||||
|
|
||||||
pub use super::all::StateEvent;
|
|
||||||
use crate::{
|
|
||||||
call::{
|
|
||||||
answer::raw::AnswerEvent, candidates::raw::CandidatesEvent, hangup::raw::HangupEvent,
|
|
||||||
invite::raw::InviteEvent,
|
|
||||||
},
|
|
||||||
custom::raw::{CustomEvent, CustomRoomEvent},
|
|
||||||
direct::raw::DirectEvent,
|
|
||||||
dummy::raw::DummyEvent,
|
|
||||||
forwarded_room_key::raw::ForwardedRoomKeyEvent,
|
|
||||||
fully_read::raw::FullyReadEvent,
|
|
||||||
ignored_user_list::raw::IgnoredUserListEvent,
|
|
||||||
key::verification::{
|
|
||||||
accept::raw::AcceptEvent, cancel::raw::CancelEvent, key::raw::KeyEvent, mac::raw::MacEvent,
|
|
||||||
request::raw::RequestEvent, start::raw::StartEvent,
|
|
||||||
},
|
|
||||||
presence::raw::PresenceEvent,
|
|
||||||
push_rules::raw::PushRulesEvent,
|
|
||||||
receipt::raw::ReceiptEvent,
|
|
||||||
room::{
|
|
||||||
encrypted::raw::EncryptedEvent,
|
|
||||||
message::{feedback::raw::FeedbackEvent, raw::MessageEvent},
|
|
||||||
redaction::raw::RedactionEvent,
|
|
||||||
},
|
|
||||||
room_key::raw::RoomKeyEvent,
|
|
||||||
room_key_request::raw::RoomKeyRequestEvent,
|
|
||||||
sticker::raw::StickerEvent,
|
|
||||||
tag::raw::TagEvent,
|
|
||||||
typing::raw::TypingEvent,
|
|
||||||
util::get_field,
|
|
||||||
EventType,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// A basic event.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum Event {
|
|
||||||
/// m.direct
|
|
||||||
Direct(DirectEvent),
|
|
||||||
|
|
||||||
/// m.dummy
|
|
||||||
Dummy(DummyEvent),
|
|
||||||
|
|
||||||
/// m.forwarded_room_key
|
|
||||||
ForwardedRoomKey(ForwardedRoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.fully_read
|
|
||||||
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
|
|
||||||
IgnoredUserList(IgnoredUserListEvent),
|
|
||||||
|
|
||||||
/// m.presence
|
|
||||||
Presence(PresenceEvent),
|
|
||||||
|
|
||||||
/// m.push_rules
|
|
||||||
PushRules(PushRulesEvent),
|
|
||||||
|
|
||||||
/// m.room_key
|
|
||||||
RoomKey(RoomKeyEvent),
|
|
||||||
|
|
||||||
/// m.room_key_request
|
|
||||||
RoomKeyRequest(RoomKeyRequestEvent),
|
|
||||||
|
|
||||||
/// m.receipt
|
|
||||||
Receipt(ReceiptEvent),
|
|
||||||
|
|
||||||
/// m.tag
|
|
||||||
Tag(TagEvent),
|
|
||||||
|
|
||||||
/// m.typing
|
|
||||||
Typing(TypingEvent),
|
|
||||||
|
|
||||||
/// Any basic event that is not part of the specification.
|
|
||||||
Custom(CustomEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A room event.
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
pub enum RoomEvent {
|
|
||||||
/// m.call.answer
|
|
||||||
CallAnswer(AnswerEvent),
|
|
||||||
|
|
||||||
/// m.call.candidates
|
|
||||||
CallCandidates(CandidatesEvent),
|
|
||||||
|
|
||||||
/// m.call.hangup
|
|
||||||
CallHangup(HangupEvent),
|
|
||||||
|
|
||||||
/// m.call.invite
|
|
||||||
CallInvite(InviteEvent),
|
|
||||||
|
|
||||||
/// m.room.encrypted
|
|
||||||
RoomEncrypted(EncryptedEvent),
|
|
||||||
|
|
||||||
/// m.room.message
|
|
||||||
RoomMessage(MessageEvent),
|
|
||||||
|
|
||||||
/// m.room.message.feedback
|
|
||||||
RoomMessageFeedback(FeedbackEvent),
|
|
||||||
|
|
||||||
/// m.room.redaction
|
|
||||||
RoomRedaction(RedactionEvent),
|
|
||||||
|
|
||||||
/// m.sticker
|
|
||||||
Sticker(StickerEvent),
|
|
||||||
|
|
||||||
/// Any room event that is not part of the specification.
|
|
||||||
CustomRoom(CustomRoomEvent),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Event {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use crate::util::try_variant_from_value as from_value;
|
|
||||||
use EventType::*;
|
|
||||||
|
|
||||||
let value = JsonValue::deserialize(deserializer)?;
|
|
||||||
let event_type = get_field(&value, "type")?;
|
|
||||||
|
|
||||||
match event_type {
|
|
||||||
Direct => from_value(value, Event::Direct),
|
|
||||||
Dummy => from_value(value, Event::Dummy),
|
|
||||||
ForwardedRoomKey => from_value(value, Event::ForwardedRoomKey),
|
|
||||||
FullyRead => from_value(value, Event::FullyRead),
|
|
||||||
KeyVerificationAccept => from_value(value, Event::KeyVerificationAccept),
|
|
||||||
KeyVerificationCancel => from_value(value, Event::KeyVerificationCancel),
|
|
||||||
KeyVerificationKey => from_value(value, Event::KeyVerificationKey),
|
|
||||||
KeyVerificationMac => from_value(value, Event::KeyVerificationMac),
|
|
||||||
KeyVerificationRequest => from_value(value, Event::KeyVerificationRequest),
|
|
||||||
KeyVerificationStart => from_value(value, Event::KeyVerificationStart),
|
|
||||||
IgnoredUserList => from_value(value, Event::IgnoredUserList),
|
|
||||||
Presence => from_value(value, Event::Presence),
|
|
||||||
PushRules => from_value(value, Event::PushRules),
|
|
||||||
RoomKey => from_value(value, Event::RoomKey),
|
|
||||||
RoomKeyRequest => from_value(value, Event::RoomKeyRequest),
|
|
||||||
Receipt => from_value(value, Event::Receipt),
|
|
||||||
Tag => from_value(value, Event::Tag),
|
|
||||||
Typing => from_value(value, Event::Typing),
|
|
||||||
Custom(_event_type_name) => from_value(value, Event::Custom),
|
|
||||||
CallAnswer
|
|
||||||
| CallCandidates
|
|
||||||
| CallHangup
|
|
||||||
| CallInvite
|
|
||||||
| RoomAliases
|
|
||||||
| RoomAvatar
|
|
||||||
| RoomCanonicalAlias
|
|
||||||
| RoomCreate
|
|
||||||
| RoomEncrypted
|
|
||||||
| RoomEncryption
|
|
||||||
| RoomGuestAccess
|
|
||||||
| RoomHistoryVisibility
|
|
||||||
| RoomJoinRules
|
|
||||||
| RoomMember
|
|
||||||
| RoomMessage
|
|
||||||
| RoomMessageFeedback
|
|
||||||
| RoomName
|
|
||||||
| RoomPinnedEvents
|
|
||||||
| RoomPowerLevels
|
|
||||||
| RoomServerAcl
|
|
||||||
| RoomThirdPartyInvite
|
|
||||||
| RoomTombstone
|
|
||||||
| RoomTopic
|
|
||||||
| RoomRedaction
|
|
||||||
| Sticker => Err(D::Error::custom("invalid event type")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for RoomEvent {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use crate::util::try_variant_from_value as from_value;
|
|
||||||
use EventType::*;
|
|
||||||
|
|
||||||
let value = JsonValue::deserialize(deserializer)?;
|
|
||||||
let event_type = get_field(&value, "type")?;
|
|
||||||
|
|
||||||
match event_type {
|
|
||||||
CallAnswer => from_value(value, RoomEvent::CallAnswer),
|
|
||||||
CallCandidates => from_value(value, RoomEvent::CallCandidates),
|
|
||||||
CallHangup => from_value(value, RoomEvent::CallHangup),
|
|
||||||
CallInvite => from_value(value, RoomEvent::CallInvite),
|
|
||||||
RoomEncrypted => from_value(value, RoomEvent::RoomEncrypted),
|
|
||||||
RoomMessage => from_value(value, RoomEvent::RoomMessage),
|
|
||||||
RoomMessageFeedback => from_value(value, RoomEvent::RoomMessageFeedback),
|
|
||||||
RoomRedaction => from_value(value, RoomEvent::RoomRedaction),
|
|
||||||
Sticker => from_value(value, RoomEvent::Sticker),
|
|
||||||
Custom(_event_type_name) => from_value(value, RoomEvent::CustomRoom),
|
|
||||||
Direct
|
|
||||||
| Dummy
|
|
||||||
| ForwardedRoomKey
|
|
||||||
| FullyRead
|
|
||||||
| IgnoredUserList
|
|
||||||
| KeyVerificationAccept
|
|
||||||
| KeyVerificationCancel
|
|
||||||
| KeyVerificationKey
|
|
||||||
| KeyVerificationMac
|
|
||||||
| KeyVerificationRequest
|
|
||||||
| KeyVerificationStart
|
|
||||||
| Presence
|
|
||||||
| PushRules
|
|
||||||
| Receipt
|
|
||||||
| RoomAvatar
|
|
||||||
| RoomAliases
|
|
||||||
| RoomCanonicalAlias
|
|
||||||
| RoomCreate
|
|
||||||
| RoomEncryption
|
|
||||||
| RoomGuestAccess
|
|
||||||
| RoomHistoryVisibility
|
|
||||||
| RoomJoinRules
|
|
||||||
| RoomKey
|
|
||||||
| RoomKeyRequest
|
|
||||||
| RoomMember
|
|
||||||
| RoomName
|
|
||||||
| RoomPinnedEvents
|
|
||||||
| RoomPowerLevels
|
|
||||||
| RoomServerAcl
|
|
||||||
| RoomThirdPartyInvite
|
|
||||||
| RoomTombstone
|
|
||||||
| RoomTopic
|
|
||||||
| Tag
|
|
||||||
| Typing => Err(D::Error::custom("invalid event type")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
10
src/lib.rs
10
src/lib.rs
@ -143,16 +143,6 @@ extern crate self as ruma_events;
|
|||||||
|
|
||||||
pub mod call;
|
pub mod call;
|
||||||
// pub mod custom;
|
// pub mod custom;
|
||||||
/// Enums for heterogeneous collections of events.
|
|
||||||
// pub mod collections {
|
|
||||||
// pub mod all;
|
|
||||||
// pub mod only;
|
|
||||||
|
|
||||||
// mod raw {
|
|
||||||
// pub mod all;
|
|
||||||
// pub mod only;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// pub mod direct;
|
// pub mod direct;
|
||||||
// pub mod dummy;
|
// pub mod dummy;
|
||||||
pub mod forwarded_room_key;
|
pub mod forwarded_room_key;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user