Skip to main content

ChatMessage

Struct ChatMessage 

Source
#[non_exhaustive]
pub struct ChatMessage { pub id: MessageId, pub room: RoomId, pub sender: UserId, pub sender_name: Option<String>, pub text: String, pub sent_at: UnixMillis, pub nonce: Option<String>, }
Expand description

A chat message: the chat.message push, and the items of a history page.

JSON: {"id":981,"room":12,"sender":42,"sender_name":"Ada","text":"hello","sent_at":1790000000000}.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: MessageId

The message id.

§room: RoomId

The room.

§sender: UserId

Who sent it.

§sender_name: Option<String>

The sender’s display name at sending time, if any.

§text: String

The text (after the server’s hooks).

§sent_at: UnixMillis

When it was stored.

§nonce: Option<String>

The sender’s SendMessage::nonce, if it set one (a public or group room’s push carries it to every member; a DM’s push and the history show it to the sender only).

Implementations§

Source§

impl ChatMessage

Source

pub fn new( id: MessageId, room: RoomId, sender: UserId, text: impl Into<String>, sent_at: UnixMillis, ) -> Self

A message.

Examples found in repository?
examples/print_frames.rs (line 34)
23fn main() {
24    let now = UnixMillis(1_790_000_000_000);
25    println!("WebSocket");
26    println!("{:<22} {}", "auth (client)", WsAuth::new("example-access-token").to_message());
27    show("auth.ok", &WsServerFrame::AuthOk(Some(WsAuthOk::new(UserId(42)))));
28    show("auth.failed", &WsServerFrame::AuthFailed(ApiError::new(codes::TOKEN_EXPIRED, "the token expired")));
29    show("request chat.join", &WsRequestFrame::call(1, JoinRoom::new("world")));
30    show("answer", &WsResponseFrame::ok(1, RoomInfo::new(RoomId(12), RoomKind::Room).with_key("world")));
31    show("request chat.send", &WsRequestFrame::call(2, SendMessage::new(RoomId(12), "hello")));
32    show("answer", &WsResponseFrame::ok(2, SendAck::new(MessageId(981), now)));
33    show("refused", &WsResponseFrame::<()>::error(3, ApiError::new(codes::NOT_A_MEMBER, "join the room first")));
34    show("push chat.message", &WsPushFrame::push(ChatMessage::new(MessageId(981), RoomId(12), UserId(42), "hello", now).with_sender_name("Ada")));
35    let codes: Vec<String> = CloseCode::ALL.iter().map(|c| format!("{c}{}", if c.is_permanent() { " (permanent)" } else { "" })).collect();
36    println!("{:<22} {}", "close codes", codes.join(", "));
37
38    println!();
39    println!("HTTP");
40    show("POST login", &LoginRequest::new("ada@example.com", "example password"));
41    let tokens = TokenPair::new(
42        AccessToken::new("example-access"),
43        now.saturating_add_millis(3_600_000),
44        RefreshToken::new("example-refresh"),
45        now.saturating_add_millis(30 * 86_400_000),
46    );
47    show("  → 200", &AuthSession::new(Account::new(UserId(42), now).with_email("ada@example.com", true), tokens));
48    show("PUT storage object", &PutObject::new(serde_json::json!({"level": 3})).if_version(ObjectVersion(2)));
49    show("  → 409", &ErrorBody::new(ApiError::new(codes::VERSION_CONFLICT, "the object changed").with_details(serde_json::json!({"current_version": 3}))));
50}
Source

pub fn with_nonce(self, nonce: impl Into<String>) -> Self

The same message with the sender’s nonce.

Source

pub fn with_sender_name(self, name: impl Into<String>) -> Self

The same message with the sender’s name.

Examples found in repository?
examples/print_frames.rs (line 34)
23fn main() {
24    let now = UnixMillis(1_790_000_000_000);
25    println!("WebSocket");
26    println!("{:<22} {}", "auth (client)", WsAuth::new("example-access-token").to_message());
27    show("auth.ok", &WsServerFrame::AuthOk(Some(WsAuthOk::new(UserId(42)))));
28    show("auth.failed", &WsServerFrame::AuthFailed(ApiError::new(codes::TOKEN_EXPIRED, "the token expired")));
29    show("request chat.join", &WsRequestFrame::call(1, JoinRoom::new("world")));
30    show("answer", &WsResponseFrame::ok(1, RoomInfo::new(RoomId(12), RoomKind::Room).with_key("world")));
31    show("request chat.send", &WsRequestFrame::call(2, SendMessage::new(RoomId(12), "hello")));
32    show("answer", &WsResponseFrame::ok(2, SendAck::new(MessageId(981), now)));
33    show("refused", &WsResponseFrame::<()>::error(3, ApiError::new(codes::NOT_A_MEMBER, "join the room first")));
34    show("push chat.message", &WsPushFrame::push(ChatMessage::new(MessageId(981), RoomId(12), UserId(42), "hello", now).with_sender_name("Ada")));
35    let codes: Vec<String> = CloseCode::ALL.iter().map(|c| format!("{c}{}", if c.is_permanent() { " (permanent)" } else { "" })).collect();
36    println!("{:<22} {}", "close codes", codes.join(", "));
37
38    println!();
39    println!("HTTP");
40    show("POST login", &LoginRequest::new("ada@example.com", "example password"));
41    let tokens = TokenPair::new(
42        AccessToken::new("example-access"),
43        now.saturating_add_millis(3_600_000),
44        RefreshToken::new("example-refresh"),
45        now.saturating_add_millis(30 * 86_400_000),
46    );
47    show("  → 200", &AuthSession::new(Account::new(UserId(42), now).with_email("ada@example.com", true), tokens));
48    show("PUT storage object", &PutObject::new(serde_json::json!({"level": 3})).if_version(ObjectVersion(2)));
49    show("  → 409", &ErrorBody::new(ApiError::new(codes::VERSION_CONFLICT, "the object changed").with_details(serde_json::json!({"current_version": 3}))));
50}

Trait Implementations§

Source§

impl Clone for ChatMessage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChatMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ChatMessage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ChatMessage

Source§

impl PartialEq for ChatMessage

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ChatMessage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ServerPush for ChatMessage

Source§

const KIND: &'static str = kinds::CHAT_MESSAGE

The type on the wire (one of kinds).
Source§

impl StructuralPartialEq for ChatMessage

Source§

impl WsPushMessage for ChatMessage

Available on crate feature bevy_net_backend only.
Source§

const KIND: &'static str = <ChatMessage as ServerPush>::KIND

The push kind on the wire (with JsonEnvelope: "type").

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more