Return an EventType from Event::event_type.
This commit is contained in:
parent
149bf66da8
commit
0270e84a1d
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.call.answer* event.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
use core::{Event, EventType, RoomEvent};
|
||||
use super::{SessionDescription, SessionDescriptionType};
|
||||
|
||||
/// This event is sent by the callee when they wish to answer the call.
|
||||
@ -16,8 +16,8 @@ impl<'a> Event<'a, AnswerEventContent<'a>> for AnswerEvent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.answer"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::CallAnswer
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.call.candidates* event.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
use core::{Event, EventType, RoomEvent};
|
||||
|
||||
/// This event is sent by callers after sending an invite and by the callee after answering.
|
||||
/// Its purpose is to give the other party additional ICE candidates to try using to communicate.
|
||||
@ -16,8 +16,8 @@ impl<'a> Event<'a, CandidatesEventContent<'a>> for CandidatesEvent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.candidates"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::CallCandidates
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.call.hangup* event.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
use core::{Event, EventType, RoomEvent};
|
||||
|
||||
/// Sent by either party to signal their termination of the call. This can be sent either once the
|
||||
/// call has has been established or before to abort the call.
|
||||
@ -16,8 +16,8 @@ impl<'a> Event<'a, HangupEventContent<'a>> for HangupEvent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.hangup"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::CallHangup
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.call.invite* event.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
use core::{Event, EventType, RoomEvent};
|
||||
use super::{SessionDescription, SessionDescriptionType};
|
||||
|
||||
/// This event is sent by the caller when they wish to establish a call.
|
||||
@ -16,8 +16,8 @@ impl<'a> Event<'a, InviteEventContent<'a>> for InviteEvent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.invite"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::CallInvite
|
||||
}
|
||||
}
|
||||
|
||||
|
32
src/core.rs
32
src/core.rs
@ -1,11 +1,37 @@
|
||||
//! Traits for the basic kinds of events.
|
||||
//! Types for the basic kinds of events.
|
||||
|
||||
/// The type of an event.
|
||||
pub enum EventType {
|
||||
CallAnswer,
|
||||
CallCandidates,
|
||||
CallHangup,
|
||||
CallInvite,
|
||||
Presence,
|
||||
Receipt,
|
||||
RoomAliases,
|
||||
RoomAvatar,
|
||||
RoomCanonicalAlias,
|
||||
RoomCreate,
|
||||
RoomGuestAccess,
|
||||
RoomHistoryVisibility,
|
||||
RoomJoinRules,
|
||||
RoomMember,
|
||||
RoomMessage,
|
||||
RoomMessageFeedback,
|
||||
RoomName,
|
||||
RoomPowerLevels,
|
||||
RoomRedaction,
|
||||
RoomThirdPartyInvite,
|
||||
RoomTopic,
|
||||
Typing,
|
||||
}
|
||||
|
||||
/// Functionality common to all events.
|
||||
pub trait Event<'a, T> {
|
||||
/// The primary event payload.
|
||||
fn content(&'a self) -> &'a T;
|
||||
/// The type of event, e.g. *com.example.subdomain.event.type*.
|
||||
fn event_type(&self) -> &'static str;
|
||||
/// The type of event.
|
||||
fn event_type(&self) -> EventType;
|
||||
}
|
||||
|
||||
/// An event emitted within the context of a room.
|
||||
|
26
src/lib.rs
26
src/lib.rs
@ -7,29 +7,3 @@ pub mod presence;
|
||||
pub mod receipt;
|
||||
pub mod room;
|
||||
pub mod typing;
|
||||
|
||||
/// The type of an event.
|
||||
pub enum EventTypes {
|
||||
CallAnswer,
|
||||
CallCandidates,
|
||||
CallHangup,
|
||||
CallInvite,
|
||||
Presence,
|
||||
Receipt,
|
||||
RoomAliases,
|
||||
RoomAvatar,
|
||||
RoomCanonicalAlias,
|
||||
RoomCreate,
|
||||
RoomGuestAccess,
|
||||
RoomHistoryVisibility,
|
||||
RoomJoinRules,
|
||||
RoomMember,
|
||||
RoomMessage,
|
||||
RoomMessageFeedback,
|
||||
RoomName,
|
||||
RoomPowerLevels,
|
||||
RoomRedaction,
|
||||
RoomThirdPartyInvite,
|
||||
RoomTopic,
|
||||
Typing,
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.presence* event.
|
||||
|
||||
use core::Event;
|
||||
use core::{Event, EventType};
|
||||
|
||||
/// Informs the client of a user's presence state change.
|
||||
pub struct PresenceEvent<'a> {
|
||||
@ -13,8 +13,8 @@ impl<'a> Event<'a, PresenceEventContent<'a>> for PresenceEvent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.presence"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::Presence
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use core::Event;
|
||||
use core::{Event, EventType};
|
||||
|
||||
/// Informs the client of new receipts.
|
||||
pub struct ReceiptEvent<'a> {
|
||||
@ -15,8 +15,8 @@ impl<'a> Event<'a, ReceiptEventContent<'a>> for ReceiptEvent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.receipt"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::Receipt
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.room.aliases* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
use core::{Event, EventType, RoomEvent, StateEvent};
|
||||
|
||||
/// Informs the room about what room aliases it has been given.
|
||||
pub struct AliasesEvent<'a, 'b> {
|
||||
@ -18,8 +18,8 @@ impl<'a, 'b> Event<'a, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.aliases"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::RoomAliases
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.room.avatar* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
use core::{Event, EventType, RoomEvent, StateEvent};
|
||||
use super::ImageInfo;
|
||||
|
||||
/// A picture that is associated with the room.
|
||||
@ -19,8 +19,8 @@ impl<'a, 'b> Event<'a, AvatarEventContent<'a>> for AvatarEvent<'a, 'b> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.avatar"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::RoomAvatar
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.room.canonical_alias* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
use core::{Event, EventType, RoomEvent, StateEvent};
|
||||
|
||||
/// Informs the room as to which alias is the canonical one.
|
||||
pub struct CanonicalAliasEvent<'a, 'b> {
|
||||
@ -16,8 +16,8 @@ impl<'a, 'b> Event<'a, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.canonical_alias"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::RoomCanonicalAlias
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.room.create* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
use core::{Event, EventType, RoomEvent, StateEvent};
|
||||
|
||||
/// This is the first event in a room and cannot be changed. It acts as the root of all other
|
||||
/// events.
|
||||
@ -17,8 +17,8 @@ impl<'a, 'b> Event<'a, CreateEventContent<'a>> for CreateEvent<'a, 'b> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.create"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::RoomCreate
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.room.history_visibility* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
use core::{Event, EventType, RoomEvent, StateEvent};
|
||||
|
||||
/// This event controls whether a member of a room can see the events that happened in a room from
|
||||
/// before they joined.
|
||||
@ -17,8 +17,8 @@ impl<'a, 'b> Event<'a, HistoryVisibilityEventContent<'a>> for HistoryVisibilityE
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.history_visibility"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::RoomHistoryVisibility
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.room.join_rules* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
use core::{Event, EventType, RoomEvent, StateEvent};
|
||||
|
||||
/// Describes how users are allowed to join the room.
|
||||
pub struct JoinRulesEvent<'a, 'b> {
|
||||
@ -16,8 +16,8 @@ impl<'a, 'b> Event<'a, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.join_rules"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::RoomJoinRules
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Types for the *m.typing* event.
|
||||
|
||||
use core::Event;
|
||||
use core::{Event, EventType};
|
||||
|
||||
/// Informs the client of the list of users currently typing.
|
||||
pub struct TypingEvent<'a> {
|
||||
@ -15,8 +15,8 @@ impl<'a> Event<'a, TypingEventContent<'a>> for TypingEvent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.typing"
|
||||
fn event_type(&self) -> EventType {
|
||||
EventType::Typing
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user