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
|
event.from, event.id, event.to
|
||||||
),
|
),
|
||||||
Data::SendEvent(event) => {
|
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 content = event.0.content.trim();
|
||||||
let mut reply = None;
|
let mut reply = None;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::Snowflake;
|
use super::AccountId;
|
||||||
|
|
||||||
/// Change the primary email address associated with the signed in account.
|
/// Change the primary email address associated with the signed in account.
|
||||||
///
|
///
|
||||||
|
|
@ -88,7 +88,7 @@ pub struct LoginReply {
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
/// If [`Self::success`] was true, the id of the account the session logged
|
/// If [`Self::success`] was true, the id of the account the session logged
|
||||||
/// into.
|
/// into.
|
||||||
pub account_id: Option<Snowflake>,
|
pub account_id: Option<AccountId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log a session out of an account.
|
/// Log a session out of an account.
|
||||||
|
|
@ -137,7 +137,7 @@ pub struct RegisterAccountReply {
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
/// If [`Self::success`] was true, the id of the account the session logged
|
/// If [`Self::success`] was true, the id of the account the session logged
|
||||||
/// into.
|
/// into.
|
||||||
pub account_id: Option<Snowflake>,
|
pub account_id: Option<AccountId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Force a new email to be sent for verifying an accounts primary email
|
/// Force a new email to be sent for verifying an accounts primary email
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
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.
|
/// Indicates that access to a room is denied.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|
@ -59,7 +62,7 @@ pub struct JoinEvent(pub SessionView);
|
||||||
/// the session that issued the login command).
|
/// the session that issued the login command).
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct LoginEvent {
|
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
|
/// 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)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct NickEvent {
|
pub struct NickEvent {
|
||||||
/// The id of the session this name applies to.
|
/// 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.
|
/// The id of the agent or account logged into the session.
|
||||||
pub id: UserId,
|
pub id: UserId,
|
||||||
/// The previous name associated with the session.
|
/// The previous name associated with the session.
|
||||||
|
|
@ -137,7 +140,7 @@ pub struct PmInitiateEvent {
|
||||||
/// The room where the invitation was sent from.
|
/// The room where the invitation was sent from.
|
||||||
pub from_room: String,
|
pub from_room: String,
|
||||||
/// The private chat can be accessed at `/room/pm:<pm_id>`.
|
/// 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.
|
/// 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.
|
/// The id of the agent or account logged into this session.
|
||||||
pub identity: UserId,
|
pub identity: UserId,
|
||||||
/// The globally unique id of this session.
|
/// The globally unique id of this session.
|
||||||
pub session_id: String,
|
pub session_id: SessionId,
|
||||||
/// The server’s version identifier.
|
/// The server’s version identifier.
|
||||||
pub version: String,
|
pub version: String,
|
||||||
/// The list of all other sessions joined to the room (excluding this
|
/// The list of all other sessions joined to the room (excluding this
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
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.
|
/// Retrieve the full content of a single message in the room.
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct GetMessage {
|
pub struct GetMessage {
|
||||||
/// The id of the message to retrieve.
|
/// The id of the message to retrieve.
|
||||||
pub id: Snowflake,
|
pub id: MessageId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The message retrieved by [`GetMessage`].
|
/// The message retrieved by [`GetMessage`].
|
||||||
|
|
@ -28,7 +28,7 @@ pub struct Log {
|
||||||
/// Maximum number of messages to return (up to 1000).
|
/// Maximum number of messages to return (up to 1000).
|
||||||
pub n: usize,
|
pub n: usize,
|
||||||
/// Return messages prior to this snowflake.
|
/// Return messages prior to this snowflake.
|
||||||
pub before: Option<Snowflake>,
|
pub before: Option<MessageId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List of messages from the room's message log.
|
/// List of messages from the room's message log.
|
||||||
|
|
@ -37,7 +37,7 @@ pub struct LogReply {
|
||||||
/// List of messages returned.
|
/// List of messages returned.
|
||||||
pub log: Vec<Message>,
|
pub log: Vec<Message>,
|
||||||
/// Messages prior to this snowflake were returned.
|
/// Messages prior to this snowflake were returned.
|
||||||
pub before: Option<Snowflake>,
|
pub before: Option<MessageId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the name you present to the room.
|
/// Set the name you present to the room.
|
||||||
|
|
@ -57,7 +57,7 @@ pub struct Nick {
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct NickReply {
|
pub struct NickReply {
|
||||||
/// The id of the session this name applies to.
|
/// 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.
|
/// The id of the agent or account logged into the session.
|
||||||
pub id: UserId,
|
pub id: UserId,
|
||||||
/// The previous name associated with the session.
|
/// The previous name associated with the session.
|
||||||
|
|
@ -78,7 +78,7 @@ pub struct PmInitiate {
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PmInitiateReply {
|
pub struct PmInitiateReply {
|
||||||
/// The private chat can be accessed at `/room/pm:<pm_id>`.
|
/// 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.
|
/// The nickname of the recipient of the invitation.
|
||||||
pub to_nick: String,
|
pub to_nick: String,
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +99,7 @@ pub struct Send {
|
||||||
/// The content of the message (client-defined).
|
/// The content of the message (client-defined).
|
||||||
pub content: String,
|
pub content: String,
|
||||||
/// The id of the parent message, if any.
|
/// The id of the parent message, if any.
|
||||||
pub parent: Option<Snowflake>,
|
pub parent: Option<MessageId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The message that was sent.
|
/// The message that was sent.
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ use time::OffsetDateTime;
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AccountView {
|
pub struct AccountView {
|
||||||
/// The id of the account.
|
/// The id of the account.
|
||||||
pub id: Snowflake,
|
pub id: AccountId,
|
||||||
/// The name that the holder of the account goes by.
|
/// The name that the holder of the account goes by.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
@ -39,10 +39,10 @@ pub enum AuthOption {
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
/// The id of the message (unique within a room).
|
/// 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.
|
/// The id of the message's parent, or null if top-level.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[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
|
/// The edit id of the most recent edit of this message, or null if it's
|
||||||
/// never been edited.
|
/// never been edited.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
|
@ -253,7 +253,7 @@ impl fmt::Display for PacketType {
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct PersonalAccountView {
|
pub struct PersonalAccountView {
|
||||||
/// The id of the account.
|
/// The id of the account.
|
||||||
pub id: Snowflake,
|
pub id: AccountId,
|
||||||
/// The name that the holder of the account goes by.
|
/// The name that the holder of the account goes by.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// The account's email address.
|
/// The account's email address.
|
||||||
|
|
@ -272,7 +272,7 @@ pub struct SessionView {
|
||||||
/// The era of the server that captured this view.
|
/// The era of the server that captured this view.
|
||||||
pub server_era: String,
|
pub server_era: String,
|
||||||
/// Id of the session, unique across all sessions globally.
|
/// 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.
|
/// If true, this session belongs to a member of staff.
|
||||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||||
pub is_staff: bool,
|
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