Subclass Event
Subtask of #939 (closed).
This is mostly to explain what I have in mind regarding subclassing the Event
type. I'm trying to use subclasses as much as possible (ie types that share the same properties should have the same parent type), so that makes a lot more types.
Types Inheritance
The type names are those I plan to use. They might not be pretty but they reflect why they are separated.
As can be seen below, StateEvent
doesn't have properties of its own except it will allow to access the event directly as an AnySyncStateEvent
.
Event (non-instantiable)
├── UnsupportedEvent
└── SupportedEvent (non-instantiable)
├── RelatedEvent (non-instantiable)
│ ├── AggregatorEvent (non-instantiable)
│ │ ├── EncryptedEvent
│ │ └── MessageEvent
│ ├── ReactionEvent
└── StateEvent
Type selection flow
This is here mostly to justify the logic behind the different types.
graph TD
Event --> a_deser(Deserialize)
a_deser --> c_deser{Success?}
c_deser -- No --> UnsupportedEvent
c_deser -- Yes --> c_is_state{ruma::StateEvent?}
c_is_state -- Yes --> c_supported_state{Supported State?}
c_supported_state -- Yes --> StateEvent
c_supported_state -- No ---> UnsupportedEvent
c_is_state -- No --> c_redacted{Redacted?}
c_redacted -- Yes --> UnsupportedEvent
c_redacted -- No --> c_related{Has Relation?}
c_related -- No --> c_encrypted{Encrypted?}
c_related -- Yes --> c_reaction{Reaction?}
c_reaction -- No --> c_encrypted
c_reaction -- Yes --> ReactionEvent
c_encrypted -- No --> c_supported_message{Supported Message?}
c_encrypted -- Yes --> a_decrypt(Decrypt)
a_decrypt --> c_decrypt{Success?}
c_decrypt -- Yes -->c_supported_message
c_decrypt -- No --> EncryptedEvent
EncryptedEvent -- Retry --> a_decrypt
c_supported_message -- No --> UnsupportedEvent
c_supported_message -- Yes --> MessageEvent
Types Methods & Properties
This is not thorough but basically shows why the different types are needed. The signatures only use basic Rust types for brievity and clarity, but they might use more complicated types in practice.
Event
pure_event
source
room
timestamp
is_hidden
UnsupportedEvent
type_ as Option<EventType>
event_id as Option<OwnedEventId>
sender_id as Option<OwnedUserId>
SupportedEvent
event_id as OwnedEventId
sender_id as OwnedUserId
RelatedEvent
relates_to() -> Option<ChildRelationEvent>
relation_type() -> Option<RelationType>
AggregatorEvent
replacing_events() -> Vec<ChildRelationEvent>
replacement() -> Option<ChildRelationEvent>
reactions() -> Vec<ReactionEvent>
replies_to() -> Option<MessageEvent>
EncryptedEvent
try_to_decrypt()
MessageEvent
content
ReactionEvent
key
StateEvent
None