pub enum Message {
Join {
id: String,
room: String,
user: String,
ts: DateTime<Utc>,
seq: Option<u64>,
},
Leave {
id: String,
room: String,
user: String,
ts: DateTime<Utc>,
seq: Option<u64>,
},
Message {
id: String,
room: String,
user: String,
ts: DateTime<Utc>,
seq: Option<u64>,
content: String,
},
Reply {
id: String,
room: String,
user: String,
ts: DateTime<Utc>,
seq: Option<u64>,
reply_to: String,
content: String,
},
Command {
id: String,
room: String,
user: String,
ts: DateTime<Utc>,
seq: Option<u64>,
cmd: String,
params: Vec<String>,
},
System {
id: String,
room: String,
user: String,
ts: DateTime<Utc>,
seq: Option<u64>,
content: String,
},
DirectMessage {
id: String,
room: String,
user: String,
ts: DateTime<Utc>,
seq: Option<u64>,
to: String,
content: String,
},
}Expand description
Wire format for all messages stored in the chat file and sent over the socket.
Uses #[serde(tag = "type")] internally-tagged enum without #[serde(flatten)]
to avoid the serde flatten + internally-tagged footgun that breaks deserialization.
Every variant carries its own id/room/user/ts fields.
Variants§
Join
Leave
Message
Reply
Fields
Command
Fields
System
DirectMessage
A private direct message. Delivered only to sender, recipient, and the broker host. Always written to the chat history file.
Implementations§
Source§impl Message
impl Message
pub fn id(&self) -> &str
pub fn room(&self) -> &str
pub fn user(&self) -> &str
pub fn ts(&self) -> &DateTime<Utc>
Sourcepub fn seq(&self) -> Option<u64>
pub fn seq(&self) -> Option<u64>
Returns the sequence number assigned by the broker, or None for
messages loaded from history files that predate this feature.
Sourcepub fn content(&self) -> Option<&str>
pub fn content(&self) -> Option<&str>
Returns the text content of this message, or None for variants without content
(Join, Leave, Command).
Sourcepub fn mentions(&self) -> Vec<String>
pub fn mentions(&self) -> Vec<String>
Extract @mentions from this message’s content.
Returns an empty vec for variants without content (Join, Leave, Command) or content with no @mentions.
Sourcepub fn is_visible_to(&self, viewer: &str, host: Option<&str>) -> bool
pub fn is_visible_to(&self, viewer: &str, host: Option<&str>) -> bool
Returns true if viewer is allowed to see this message.
All non-DM variants are visible to everyone. A Message::DirectMessage
is visible only to the sender (user), the recipient (to), and the
room host (when host == Some(viewer)).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Message
impl Serialize for Message
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more