Move each event into its own module.
This commit is contained in:
parent
074d966c80
commit
787f4d0af2
201
src/call.rs
201
src/call.rs
@ -1,201 +0,0 @@
|
||||
//! Events within the *m.call* namespace.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
|
||||
/// This event is sent by the callee when they wish to answer the call.
|
||||
pub struct AnswerEvent<'a> {
|
||||
content: AnswerEventContent<'a>,
|
||||
event_id: String,
|
||||
room_id: String,
|
||||
user_id: String,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, AnswerEventContent<'a>> for AnswerEvent<'a> {
|
||||
fn content(&'a self) -> &'a AnswerEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.answer"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, AnswerEventContent<'a>> for AnswerEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `AnswerEvent`.
|
||||
pub struct AnswerEventContent<'a> {
|
||||
/// The VoIP session description.
|
||||
answer: SessionDescription<'a>,
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: String,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
||||
|
||||
/// A VoIP session description.
|
||||
pub struct SessionDescription<'a> {
|
||||
/// The type of session description.
|
||||
session_type: SessionDescriptionType,
|
||||
/// The SDP text of the session description.
|
||||
sdp: &'a str,
|
||||
}
|
||||
|
||||
/// The type of VoIP session description.
|
||||
pub enum SessionDescriptionType {
|
||||
/// An answer.
|
||||
Answer,
|
||||
/// An offer.
|
||||
Offer,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub struct CandidatesEvent<'a> {
|
||||
content: CandidatesEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, CandidatesEventContent<'a>> for CandidatesEvent<'a> {
|
||||
fn content(&'a self) -> &'a CandidatesEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.candidates"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, CandidatesEventContent<'a>> for CandidatesEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `CandidatesEvent`.
|
||||
pub struct CandidatesEventContent<'a> {
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: &'a str,
|
||||
/// A list of candidates.
|
||||
candidates: &'a[Candidate<'a>],
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
||||
|
||||
/// An ICE (Interactive Connectivity Establishment) candidate.
|
||||
pub struct Candidate<'a> {
|
||||
/// The SDP "a" line of the candidate.
|
||||
candidate: &'a str,
|
||||
/// The SDP media type this candidate is intended for.
|
||||
sdp_mid: &'a str,
|
||||
/// The index of the SDP "m" line this candidate is intended for.
|
||||
sdp_m_line_index: u64,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub struct HangupEvent<'a> {
|
||||
content: HangupEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, HangupEventContent<'a>> for HangupEvent<'a> {
|
||||
fn content(&'a self) -> &'a HangupEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.hangup"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, HangupEventContent<'a>> for HangupEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `HangupEvent`.
|
||||
pub struct HangupEventContent<'a> {
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: &'a str,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
||||
|
||||
/// This event is sent by the caller when they wish to establish a call.
|
||||
pub struct InviteEvent<'a> {
|
||||
content: InviteEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, InviteEventContent<'a>> for InviteEvent<'a> {
|
||||
fn content(&'a self) -> &'a InviteEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.invite"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, InviteEventContent<'a>> for InviteEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `InviteEvent`.
|
||||
pub struct InviteEventContent<'a> {
|
||||
/// A unique identifer for the call.
|
||||
call_id: &'a str,
|
||||
/// The time in milliseconds that the invite is valid for. Once the invite age exceeds this
|
||||
/// value, clients should discard it. They should also no longer show the call as awaiting an
|
||||
/// answer in the UI.
|
||||
lifetime: u64,
|
||||
/// The session description object.
|
||||
offer: SessionDescription<'a>,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
46
src/call/answer.rs
Normal file
46
src/call/answer.rs
Normal file
@ -0,0 +1,46 @@
|
||||
//! Types for the *m.call.answer* event.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
use super::{SessionDescription, SessionDescriptionType};
|
||||
|
||||
/// This event is sent by the callee when they wish to answer the call.
|
||||
pub struct AnswerEvent<'a> {
|
||||
content: AnswerEventContent<'a>,
|
||||
event_id: String,
|
||||
room_id: String,
|
||||
user_id: String,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, AnswerEventContent<'a>> for AnswerEvent<'a> {
|
||||
fn content(&'a self) -> &'a AnswerEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.answer"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, AnswerEventContent<'a>> for AnswerEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `AnswerEvent`.
|
||||
pub struct AnswerEventContent<'a> {
|
||||
/// The VoIP session description.
|
||||
answer: SessionDescription<'a>,
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: String,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
56
src/call/candidates.rs
Normal file
56
src/call/candidates.rs
Normal file
@ -0,0 +1,56 @@
|
||||
//! Types for the *m.call.candidates* event.
|
||||
|
||||
use core::{Event, 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.
|
||||
pub struct CandidatesEvent<'a> {
|
||||
content: CandidatesEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, CandidatesEventContent<'a>> for CandidatesEvent<'a> {
|
||||
fn content(&'a self) -> &'a CandidatesEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.candidates"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, CandidatesEventContent<'a>> for CandidatesEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `CandidatesEvent`.
|
||||
pub struct CandidatesEventContent<'a> {
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: &'a str,
|
||||
/// A list of candidates.
|
||||
candidates: &'a[Candidate<'a>],
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
||||
|
||||
/// An ICE (Interactive Connectivity Establishment) candidate.
|
||||
pub struct Candidate<'a> {
|
||||
/// The SDP "a" line of the candidate.
|
||||
candidate: &'a str,
|
||||
/// The SDP media type this candidate is intended for.
|
||||
sdp_mid: &'a str,
|
||||
/// The index of the SDP "m" line this candidate is intended for.
|
||||
sdp_m_line_index: u64,
|
||||
}
|
44
src/call/hangup.rs
Normal file
44
src/call/hangup.rs
Normal file
@ -0,0 +1,44 @@
|
||||
//! Types for the *m.call.hangup* event.
|
||||
|
||||
use core::{Event, 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.
|
||||
pub struct HangupEvent<'a> {
|
||||
content: HangupEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, HangupEventContent<'a>> for HangupEvent<'a> {
|
||||
fn content(&'a self) -> &'a HangupEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.hangup"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, HangupEventContent<'a>> for HangupEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `HangupEvent`.
|
||||
pub struct HangupEventContent<'a> {
|
||||
/// The ID of the call this event relates to.
|
||||
call_id: &'a str,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
50
src/call/invite.rs
Normal file
50
src/call/invite.rs
Normal file
@ -0,0 +1,50 @@
|
||||
//! Types for the *m.call.invite* event.
|
||||
|
||||
use core::{Event, RoomEvent};
|
||||
use super::{SessionDescription, SessionDescriptionType};
|
||||
|
||||
/// This event is sent by the caller when they wish to establish a call.
|
||||
pub struct InviteEvent<'a> {
|
||||
content: InviteEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> Event<'a, InviteEventContent<'a>> for InviteEvent<'a> {
|
||||
fn content(&'a self) -> &'a InviteEventContent {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.call.invite"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> RoomEvent<'a, InviteEventContent<'a>> for InviteEvent<'a> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `InviteEvent`.
|
||||
pub struct InviteEventContent<'a> {
|
||||
/// A unique identifer for the call.
|
||||
call_id: &'a str,
|
||||
/// The time in milliseconds that the invite is valid for. Once the invite age exceeds this
|
||||
/// value, clients should discard it. They should also no longer show the call as awaiting an
|
||||
/// answer in the UI.
|
||||
lifetime: u64,
|
||||
/// The session description object.
|
||||
offer: SessionDescription<'a>,
|
||||
/// The version of the VoIP specification this messages adheres to.
|
||||
version: u64,
|
||||
}
|
24
src/call/mod.rs
Normal file
24
src/call/mod.rs
Normal file
@ -0,0 +1,24 @@
|
||||
//! Modules for events in the *m.call* namespace.
|
||||
//!
|
||||
//! This module also contains types shared by events in its child namespaces.
|
||||
|
||||
pub mod answer;
|
||||
pub mod candidates;
|
||||
pub mod hangup;
|
||||
pub mod invite;
|
||||
|
||||
/// A VoIP session description.
|
||||
pub struct SessionDescription<'a> {
|
||||
/// The type of session description.
|
||||
session_type: SessionDescriptionType,
|
||||
/// The SDP text of the session description.
|
||||
sdp: &'a str,
|
||||
}
|
||||
|
||||
/// The type of VoIP session description.
|
||||
pub enum SessionDescriptionType {
|
||||
/// An answer.
|
||||
Answer,
|
||||
/// An offer.
|
||||
Offer,
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//! Traits for types of events that share common fields.
|
||||
//! Traits for the basic kinds of events.
|
||||
|
||||
/// The basic set of fields all events must have.
|
||||
/// Functionality common to all events.
|
||||
pub trait Event<'a, T> {
|
||||
/// The primary event payload.
|
||||
fn content(&'a self) -> &'a T;
|
||||
|
26
src/lib.rs
26
src/lib.rs
@ -7,3 +7,29 @@ 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,4 +1,4 @@
|
||||
//! Events within the *m.presence* namespace.
|
||||
//! Types for the *m.presence* event.
|
||||
|
||||
use core::Event;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! Events within the *m.receipt* namespace.
|
||||
//! Types for the *m.receipt* event.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -20,9 +20,10 @@ impl<'a> Event<'a, ReceiptEventContent<'a>> for ReceiptEvent<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `ReceiptEvent`. The mapping of event ID to a collection of receipts for this
|
||||
/// event ID. The event ID is the ID of the event being acknowledged and *not* an ID for the receipt
|
||||
/// itself.
|
||||
/// The payload of a `ReceiptEvent`.
|
||||
///
|
||||
/// A mapping of event ID to a collection of receipts for this event ID. The event ID is the ID of
|
||||
/// the event being acknowledged and *not* an ID for the receipt itself.
|
||||
pub type ReceiptEventContent<'a> = HashMap<&'a str, Receipts<'a>>;
|
||||
|
||||
/// A collection of receipts.
|
||||
@ -31,7 +32,9 @@ pub struct Receipts<'a> {
|
||||
m_read: UserReceipts<'a>,
|
||||
}
|
||||
|
||||
/// The mapping of user ID to receipt. The user ID is the entity who sent this receipt.
|
||||
/// A mapping of user ID to receipt.
|
||||
///
|
||||
/// The user ID is the entity who sent this receipt.
|
||||
pub type UserReceipts<'a> = HashMap<&'a str, Receipt>;
|
||||
|
||||
/// An acknowledgement of an event.
|
||||
|
57
src/room/aliases.rs
Normal file
57
src/room/aliases.rs
Normal file
@ -0,0 +1,57 @@
|
||||
//! Types for the *m.room.aliases* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
|
||||
/// Informs the room about what room aliases it has been given.
|
||||
pub struct AliasesEvent<'a, 'b> {
|
||||
content: AliasesEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<AliasesEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
/// The homeserver domain which owns these room aliases.
|
||||
state_key: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a AliasesEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.aliases"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
|
||||
fn prev_content(&'a self) -> Option<&'b AliasesEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn state_key(&self) -> &'a str {
|
||||
&self.state_key
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `AliasesEvent`.
|
||||
pub struct AliasesEventContent<'a> {
|
||||
/// A list of room aliases.
|
||||
aliases: &'a[&'a str],
|
||||
}
|
1
src/room/avatar.rs
Normal file
1
src/room/avatar.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.avatar* event.
|
52
src/room/canonical_alias.rs
Normal file
52
src/room/canonical_alias.rs
Normal file
@ -0,0 +1,52 @@
|
||||
//! Types for the *m.room.canonical_alias* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
|
||||
/// Informs the room as to which alias is the canonical one.
|
||||
pub struct CanonicalAliasEvent<'a, 'b> {
|
||||
content: CanonicalAliasEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<CanonicalAliasEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a CanonicalAliasEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.canonical_alias"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'a, 'b> {
|
||||
fn prev_content(&'a self) -> Option<&'b CanonicalAliasEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `CanonicalAliasEvent`.
|
||||
pub struct CanonicalAliasEventContent<'a> {
|
||||
/// The canonical alias.
|
||||
alias: &'a str,
|
||||
}
|
||||
|
46
src/room/create.rs
Normal file
46
src/room/create.rs
Normal file
@ -0,0 +1,46 @@
|
||||
//! Types for the *m.room.create* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
|
||||
/// This is the first event in a room and cannot be changed. It acts as the root of all other
|
||||
/// events.
|
||||
pub struct CreateEvent<'a, 'b> {
|
||||
content: CreateEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<CreateEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, CreateEventContent<'a>> for CreateEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a CreateEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.create"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, CreateEventContent<'a>> for CreateEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, CreateEventContent<'a>> for CreateEvent<'a, 'b> {}
|
||||
|
||||
/// The payload of a `CreateEvent`.
|
||||
pub struct CreateEventContent<'a> {
|
||||
/// The `user_id` of the room creator. This is set by the homeserver.
|
||||
creator: &'a str,
|
||||
}
|
||||
|
1
src/room/guest_access.rs
Normal file
1
src/room/guest_access.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.guest_access* event.
|
73
src/room/history_visibility.rs
Normal file
73
src/room/history_visibility.rs
Normal file
@ -0,0 +1,73 @@
|
||||
//! Types for the *m.room.history_visibility* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
|
||||
/// This event controls whether a member of a room can see the events that happened in a room from
|
||||
/// before they joined.
|
||||
pub struct HistoryVisibilityEvent<'a, 'b> {
|
||||
content: HistoryVisibilityEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<HistoryVisibilityEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, HistoryVisibilityEventContent<'a>> for HistoryVisibilityEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a HistoryVisibilityEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.history_visibility"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, HistoryVisibilityEventContent<'a>> for HistoryVisibilityEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, HistoryVisibilityEventContent<'a>>
|
||||
for HistoryVisibilityEvent<'a, 'b>
|
||||
{
|
||||
fn prev_content(&'a self) -> Option<&'b HistoryVisibilityEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `HistoryVisibilityEvent`.
|
||||
pub struct HistoryVisibilityEventContent<'a> {
|
||||
/// Who can see the room history.
|
||||
history_visibility: &'a HistoryVisibility,
|
||||
}
|
||||
|
||||
/// Who can see a room's history.
|
||||
pub enum HistoryVisibility {
|
||||
/// Previous events are accessible to newly joined members from the point they were invited
|
||||
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||
/// than *invite* or *join*.
|
||||
Invited,
|
||||
/// Previous events are accessible to newly joined members from the point they joined the room
|
||||
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||
/// than *join*.
|
||||
Joined,
|
||||
/// Previous events are always accessible to newly joined members. All events in the room are
|
||||
/// accessible, even those sent when the member was not a part of the room.
|
||||
Shared,
|
||||
/// All events while this is the `HistoryVisibility` value may be shared by any
|
||||
/// participating homeserver with anyone, regardless of whether they have ever joined the room.
|
||||
WorldReadable,
|
||||
}
|
||||
|
64
src/room/join_rules.rs
Normal file
64
src/room/join_rules.rs
Normal file
@ -0,0 +1,64 @@
|
||||
//! Types for the *m.room.join_rules* event.
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
|
||||
/// Describes how users are allowed to join the room.
|
||||
pub struct JoinRulesEvent<'a, 'b> {
|
||||
content: JoinRulesEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<JoinRulesEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a JoinRulesEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.join_rules"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
|
||||
fn prev_content(&'a self) -> Option<&'b JoinRulesEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `JoinRulesEvent`.
|
||||
pub struct JoinRulesEventContent<'a> {
|
||||
/// The type of rules used for users wishing to join this room.
|
||||
join_rule: &'a JoinRules,
|
||||
}
|
||||
|
||||
/// The rule used for users wishing to join this room.
|
||||
pub enum JoinRules {
|
||||
/// A user who wishes to join the room must first receive an invite to the room from someone
|
||||
/// already inside of the room.
|
||||
Invite,
|
||||
/// Reserved but not yet implemented by the Matrix specification.
|
||||
Knock,
|
||||
/// Reserved but not yet implemented by the Matrix specification.
|
||||
Private,
|
||||
/// Anyone can join the room without any prior action.
|
||||
Public,
|
||||
}
|
1
src/room/member.rs
Normal file
1
src/room/member.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.member* event.
|
@ -1 +0,0 @@
|
||||
//! Events within the *m.room.message* namespace.
|
1
src/room/message/feedback.rs
Normal file
1
src/room/message/feedback.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.message.feedback* event.
|
3
src/room/message/mod.rs
Normal file
3
src/room/message/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
//! Modules for events in the *m.room.message* namespace and types for the *m.room.message* event.
|
||||
|
||||
pub mod feedback;
|
293
src/room/mod.rs
293
src/room/mod.rs
@ -1,279 +1,18 @@
|
||||
//! Events within the *m.room* namespace.
|
||||
//! Modules for events in the *m.room* namespace.
|
||||
//!
|
||||
//! This module also contains types shared by events in its child namespaces.
|
||||
|
||||
pub mod aliases;
|
||||
pub mod avatar;
|
||||
pub mod canonical_alias;
|
||||
pub mod create;
|
||||
pub mod guest_access;
|
||||
pub mod history_visibility;
|
||||
pub mod join_rules;
|
||||
pub mod member;
|
||||
pub mod message;
|
||||
|
||||
use core::{Event, RoomEvent, StateEvent};
|
||||
|
||||
/// Informs the room about what room aliases it has been given.
|
||||
pub struct AliasesEvent<'a, 'b> {
|
||||
content: AliasesEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<AliasesEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
/// The homeserver domain which owns these room aliases.
|
||||
state_key: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a AliasesEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.aliases"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, AliasesEventContent<'a>> for AliasesEvent<'a, 'b> {
|
||||
fn prev_content(&'a self) -> Option<&'b AliasesEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn state_key(&self) -> &'a str {
|
||||
&self.state_key
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of an `AliasesEvent`.
|
||||
pub struct AliasesEventContent<'a> {
|
||||
/// A list of room aliases.
|
||||
aliases: &'a[&'a str],
|
||||
}
|
||||
|
||||
/// Informs the room as to which alias is the canonical one.
|
||||
pub struct CanonicalAliasEvent<'a, 'b> {
|
||||
content: CanonicalAliasEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<CanonicalAliasEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a CanonicalAliasEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.canonical_alias"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, CanonicalAliasEventContent<'a>> for CanonicalAliasEvent<'a, 'b> {
|
||||
fn prev_content(&'a self) -> Option<&'b CanonicalAliasEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `CanonicalAliasEvent`.
|
||||
pub struct CanonicalAliasEventContent<'a> {
|
||||
/// The canonical alias.
|
||||
alias: &'a str,
|
||||
}
|
||||
|
||||
/// This is the first event in a room and cannot be changed. It acts as the root of all other
|
||||
/// events.
|
||||
pub struct CreateEvent<'a, 'b> {
|
||||
content: CreateEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<CreateEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, CreateEventContent<'a>> for CreateEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a CreateEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.create"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, CreateEventContent<'a>> for CreateEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, CreateEventContent<'a>> for CreateEvent<'a, 'b> {}
|
||||
|
||||
/// The payload of a `CreateEvent`.
|
||||
pub struct CreateEventContent<'a> {
|
||||
/// The `user_id` of the room creator. This is set by the homeserver.
|
||||
creator: &'a str,
|
||||
}
|
||||
|
||||
/// This event controls whether a member of a room can see the events that happened in a room from
|
||||
/// before they joined.
|
||||
pub struct HistoryVisibilityEvent<'a, 'b> {
|
||||
content: HistoryVisibilityEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<HistoryVisibilityEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, HistoryVisibilityEventContent<'a>> for HistoryVisibilityEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a HistoryVisibilityEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.history_visibility"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, HistoryVisibilityEventContent<'a>> for HistoryVisibilityEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, HistoryVisibilityEventContent<'a>>
|
||||
for HistoryVisibilityEvent<'a, 'b>
|
||||
{
|
||||
fn prev_content(&'a self) -> Option<&'b HistoryVisibilityEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `HistoryVisibilityEvent`.
|
||||
pub struct HistoryVisibilityEventContent<'a> {
|
||||
/// Who can see the room history.
|
||||
history_visibility: &'a HistoryVisibility,
|
||||
}
|
||||
|
||||
/// Who can see a room's history.
|
||||
pub enum HistoryVisibility {
|
||||
/// Previous events are accessible to newly joined members from the point they were invited
|
||||
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||
/// than *invite* or *join*.
|
||||
Invited,
|
||||
/// Previous events are accessible to newly joined members from the point they joined the room
|
||||
/// onwards. Events stop being accessible when the member's state changes to something other
|
||||
/// than *join*.
|
||||
Joined,
|
||||
/// Previous events are always accessible to newly joined members. All events in the room are
|
||||
/// accessible, even those sent when the member was not a part of the room.
|
||||
Shared,
|
||||
/// All events while this is the `HistoryVisibility` value may be shared by any
|
||||
/// participating homeserver with anyone, regardless of whether they have ever joined the room.
|
||||
WorldReadable,
|
||||
}
|
||||
|
||||
/// Describes how users are allowed to join the room.
|
||||
pub struct JoinRulesEvent<'a, 'b> {
|
||||
content: JoinRulesEventContent<'a>,
|
||||
event_id: &'a str,
|
||||
prev_content: Option<JoinRulesEventContent<'b>>,
|
||||
room_id: &'a str,
|
||||
user_id: &'a str,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Event<'a, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
|
||||
fn content(&'a self) -> &'a JoinRulesEventContent<'a> {
|
||||
&self.content
|
||||
}
|
||||
|
||||
fn event_type(&self) -> &'static str {
|
||||
"m.room.join_rules"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> RoomEvent<'a, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
|
||||
fn event_id(&'a self) -> &'a str {
|
||||
&self.event_id
|
||||
}
|
||||
|
||||
fn room_id(&'a self) -> &'a str {
|
||||
&self.room_id
|
||||
}
|
||||
|
||||
fn user_id(&'a self) -> &'a str {
|
||||
&self.user_id
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> StateEvent<'a, 'b, JoinRulesEventContent<'a>> for JoinRulesEvent<'a, 'b> {
|
||||
fn prev_content(&'a self) -> Option<&'b JoinRulesEventContent> {
|
||||
match self.prev_content {
|
||||
Some(ref prev_content) => Some(prev_content),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload of a `JoinRulesEvent`.
|
||||
pub struct JoinRulesEventContent<'a> {
|
||||
/// The type of rules used for users wishing to join this room.
|
||||
join_rule: &'a JoinRules,
|
||||
}
|
||||
|
||||
/// The rule used for users wishing to join this room.
|
||||
pub enum JoinRules {
|
||||
/// A user who wishes to join the room must first receive an invite to the room from someone
|
||||
/// already inside of the room.
|
||||
Invite,
|
||||
/// Reserved but not yet implemented by the Matrix specification.
|
||||
Knock,
|
||||
/// Reserved but not yet implemented by the Matrix specification.
|
||||
Private,
|
||||
/// Anyone can join the room without any prior action.
|
||||
Public,
|
||||
}
|
||||
pub mod name;
|
||||
pub mod power_levels;
|
||||
pub mod redaction;
|
||||
pub mod third_party_invite;
|
||||
pub mod topic;
|
||||
|
1
src/room/name.rs
Normal file
1
src/room/name.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.name* event.
|
1
src/room/power_levels.rs
Normal file
1
src/room/power_levels.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.power_levels* event.
|
1
src/room/redaction.rs
Normal file
1
src/room/redaction.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.redaction* event.
|
2
src/room/third_party_invite.rs
Normal file
2
src/room/third_party_invite.rs
Normal file
@ -0,0 +1,2 @@
|
||||
//! Types for the *m.room.third_party_invite* event.
|
||||
|
1
src/room/topic.rs
Normal file
1
src/room/topic.rs
Normal file
@ -0,0 +1 @@
|
||||
//! Types for the *m.room.topic* event.
|
@ -1,4 +1,4 @@
|
||||
//! Events within the *m.typing* namespace.
|
||||
//! Types for the *m.typing* event.
|
||||
|
||||
use core::Event;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user