Convert between Packet and individual packet structs

This commit is contained in:
Joscha 2022-06-22 10:47:26 +02:00
parent 21010fc48a
commit 49169a1b62
8 changed files with 341 additions and 187 deletions

View file

@ -2,7 +2,7 @@
use serde::{Deserialize, Serialize};
use super::{Message, SessionView, Snowflake, UserId};
use super::{has_packet_type, HasPacketType, Message, PacketType, SessionView, Snowflake, UserId};
/// Retrieve the full content of a single message in the room.
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -11,10 +11,14 @@ pub struct GetMessage {
pub id: Snowflake,
}
has_packet_type!(GetMessage);
/// The message retrieved by [`GetMessage`].
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetMessageReply(pub Message);
has_packet_type!(GetMessageReply);
/// Request messages from the room's message log.
///
/// This can be used to supplement the log provided by snapshot-event (for
@ -27,6 +31,8 @@ pub struct Log {
pub before: Option<Snowflake>,
}
has_packet_type!(Log);
/// List of messages from the room's message log.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogReply {
@ -36,6 +42,8 @@ pub struct LogReply {
pub before: Option<Snowflake>,
}
has_packet_type!(LogReply);
/// Set the name you present to the room.
///
/// This name applies to all messages sent during this session, until the nick
@ -46,6 +54,8 @@ pub struct Nick {
pub name: String,
}
has_packet_type!(Nick);
/// Confirms the [`Nick`] command.
///
/// Returns the session's former and new names (the server may modify the
@ -62,6 +72,8 @@ pub struct NickReply {
pub to: String,
}
has_packet_type!(NickReply);
/// Constructs a virtual room for private messaging between the client and the
/// given [`UserId`].
#[derive(Debug, Clone, Serialize, Deserialize)]
@ -70,6 +82,8 @@ pub struct PmInitiate {
pub user_id: UserId,
}
has_packet_type!(PmInitiate);
/// Provides the PMID for the requested private messaging room.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PmInitiateReply {
@ -79,6 +93,8 @@ pub struct PmInitiateReply {
pub to_nick: String,
}
has_packet_type!(PmInitiateReply);
/// Send a message to a room.
///
/// The session must be successfully joined with the room. This message will be
@ -98,19 +114,27 @@ pub struct Send {
pub parent: Option<Snowflake>,
}
has_packet_type!(Send);
/// The message that was sent.
///
/// this includes the message id, which was populated by the server.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SendReply(pub Message);
has_packet_type!(SendReply);
/// Request a list of sessions currently joined in the room.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Who;
has_packet_type!(Who);
/// Lists the sessions currently joined in the room.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WhoReply {
/// A list of session views.
listing: Vec<SessionView>,
}
has_packet_type!(WhoReply);