Add wrapper types for various kinds of id
This commit is contained in:
parent
01a442c1f0
commit
748d6b7ded
5 changed files with 54 additions and 21 deletions
|
|
@ -94,7 +94,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
event.from, event.id, event.to
|
||||
),
|
||||
Data::SendEvent(event) => {
|
||||
println!("Message {} was just sent", event.0.id);
|
||||
println!("Message {} was just sent", event.0.id.0);
|
||||
|
||||
let content = event.0.content.trim();
|
||||
let mut reply = None;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Snowflake;
|
||||
use super::AccountId;
|
||||
|
||||
/// Change the primary email address associated with the signed in account.
|
||||
///
|
||||
|
|
@ -88,7 +88,7 @@ pub struct LoginReply {
|
|||
pub reason: Option<String>,
|
||||
/// If [`Self::success`] was true, the id of the account the session logged
|
||||
/// into.
|
||||
pub account_id: Option<Snowflake>,
|
||||
pub account_id: Option<AccountId>,
|
||||
}
|
||||
|
||||
/// Log a session out of an account.
|
||||
|
|
@ -137,7 +137,7 @@ pub struct RegisterAccountReply {
|
|||
pub reason: Option<String>,
|
||||
/// If [`Self::success`] was true, the id of the account the session logged
|
||||
/// into.
|
||||
pub account_id: Option<Snowflake>,
|
||||
pub account_id: Option<AccountId>,
|
||||
}
|
||||
|
||||
/// Force a new email to be sent for verifying an accounts primary email
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{AuthOption, Message, PersonalAccountView, SessionView, Snowflake, Time, UserId};
|
||||
use super::{
|
||||
AccountId, AuthOption, Message, PersonalAccountView, PmId, SessionId, SessionView, Snowflake,
|
||||
Time, UserId,
|
||||
};
|
||||
|
||||
/// Indicates that access to a room is denied.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
|
@ -59,7 +62,7 @@ pub struct JoinEvent(pub SessionView);
|
|||
/// the session that issued the login command).
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct LoginEvent {
|
||||
pub account_id: Snowflake,
|
||||
pub account_id: AccountId,
|
||||
}
|
||||
|
||||
/// Sent to all sessions of an agent when that agent is logged out (except for
|
||||
|
|
@ -86,7 +89,7 @@ pub struct NetworkEvent {
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NickEvent {
|
||||
/// The id of the session this name applies to.
|
||||
pub session_id: String,
|
||||
pub session_id: SessionId,
|
||||
/// The id of the agent or account logged into the session.
|
||||
pub id: UserId,
|
||||
/// The previous name associated with the session.
|
||||
|
|
@ -137,7 +140,7 @@ pub struct PmInitiateEvent {
|
|||
/// The room where the invitation was sent from.
|
||||
pub from_room: String,
|
||||
/// The private chat can be accessed at `/room/pm:<pm_id>`.
|
||||
pub pm_id: Snowflake,
|
||||
pub pm_id: PmId,
|
||||
}
|
||||
|
||||
/// Indicates a message received by the room from another session.
|
||||
|
|
@ -152,7 +155,7 @@ pub struct SnapshotEvent {
|
|||
/// The id of the agent or account logged into this session.
|
||||
pub identity: UserId,
|
||||
/// The globally unique id of this session.
|
||||
pub session_id: String,
|
||||
pub session_id: SessionId,
|
||||
/// The server’s version identifier.
|
||||
pub version: String,
|
||||
/// The list of all other sessions joined to the room (excluding this
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{Message, SessionView, Snowflake, UserId};
|
||||
use super::{Message, MessageId, PmId, SessionId, SessionView, UserId};
|
||||
|
||||
/// Retrieve the full content of a single message in the room.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct GetMessage {
|
||||
/// The id of the message to retrieve.
|
||||
pub id: Snowflake,
|
||||
pub id: MessageId,
|
||||
}
|
||||
|
||||
/// The message retrieved by [`GetMessage`].
|
||||
|
|
@ -28,7 +28,7 @@ pub struct Log {
|
|||
/// Maximum number of messages to return (up to 1000).
|
||||
pub n: usize,
|
||||
/// Return messages prior to this snowflake.
|
||||
pub before: Option<Snowflake>,
|
||||
pub before: Option<MessageId>,
|
||||
}
|
||||
|
||||
/// List of messages from the room's message log.
|
||||
|
|
@ -37,7 +37,7 @@ pub struct LogReply {
|
|||
/// List of messages returned.
|
||||
pub log: Vec<Message>,
|
||||
/// Messages prior to this snowflake were returned.
|
||||
pub before: Option<Snowflake>,
|
||||
pub before: Option<MessageId>,
|
||||
}
|
||||
|
||||
/// Set the name you present to the room.
|
||||
|
|
@ -57,7 +57,7 @@ pub struct Nick {
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct NickReply {
|
||||
/// The id of the session this name applies to.
|
||||
pub session_id: String,
|
||||
pub session_id: SessionId,
|
||||
/// The id of the agent or account logged into the session.
|
||||
pub id: UserId,
|
||||
/// The previous name associated with the session.
|
||||
|
|
@ -78,7 +78,7 @@ pub struct PmInitiate {
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PmInitiateReply {
|
||||
/// The private chat can be accessed at `/room/pm:<pm_id>`.
|
||||
pub pm_id: Snowflake,
|
||||
pub pm_id: PmId,
|
||||
/// The nickname of the recipient of the invitation.
|
||||
pub to_nick: String,
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ pub struct Send {
|
|||
/// The content of the message (client-defined).
|
||||
pub content: String,
|
||||
/// The id of the parent message, if any.
|
||||
pub parent: Option<Snowflake>,
|
||||
pub parent: Option<MessageId>,
|
||||
}
|
||||
|
||||
/// The message that was sent.
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use time::OffsetDateTime;
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AccountView {
|
||||
/// The id of the account.
|
||||
pub id: Snowflake,
|
||||
pub id: AccountId,
|
||||
/// The name that the holder of the account goes by.
|
||||
pub name: String,
|
||||
}
|
||||
|
|
@ -39,10 +39,10 @@ pub enum AuthOption {
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
/// The id of the message (unique within a room).
|
||||
pub id: Snowflake,
|
||||
pub id: MessageId,
|
||||
/// The id of the message's parent, or null if top-level.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parent: Option<Snowflake>,
|
||||
pub parent: Option<MessageId>,
|
||||
/// The edit id of the most recent edit of this message, or null if it's
|
||||
/// never been edited.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
@ -253,7 +253,7 @@ impl fmt::Display for PacketType {
|
|||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PersonalAccountView {
|
||||
/// The id of the account.
|
||||
pub id: Snowflake,
|
||||
pub id: AccountId,
|
||||
/// The name that the holder of the account goes by.
|
||||
pub name: String,
|
||||
/// The account's email address.
|
||||
|
|
@ -272,7 +272,7 @@ pub struct SessionView {
|
|||
/// The era of the server that captured this view.
|
||||
pub server_era: String,
|
||||
/// Id of the session, unique across all sessions globally.
|
||||
pub session_id: String,
|
||||
pub session_id: SessionId,
|
||||
/// If true, this session belongs to a member of staff.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub is_staff: bool,
|
||||
|
|
@ -423,3 +423,33 @@ impl UserId {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Identifies an account.
|
||||
///
|
||||
/// This type is a wrapper around [`Snowflake`] meant for type safety. It is not
|
||||
/// specified in the euphoria API itself.
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub struct AccountId(pub Snowflake);
|
||||
|
||||
/// Identifies a message.
|
||||
///
|
||||
/// This type is a wrapper around [`Snowflake`] meant for type safety. It is not
|
||||
/// specified in the euphoria API itself.
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub struct MessageId(pub Snowflake);
|
||||
|
||||
/// Identifies a private room.
|
||||
///
|
||||
/// This type is a wrapper around [`Snowflake`] meant for type safety. It is not
|
||||
/// specified in the euphoria API itself.
|
||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub struct PmId(pub Snowflake);
|
||||
|
||||
/// Identifies a session.
|
||||
///
|
||||
/// This type is a wrapper around [`String`] meant for type safety. It is not
|
||||
/// specified in the euphoria API itself.
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
pub struct SessionId(pub String);
|
||||
|
||||
// TODO Find out if an edit id is a MessageId or if it deserves a wrapper
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue