You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.3 KiB
67 lines
1.3 KiB
//! Handles post and user identity.
|
|
use super::*;
|
|
use std::{
|
|
fmt,
|
|
};
|
|
use uuid::Uuid;
|
|
|
|
/// A globally unique post identifier.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct PostID(Uuid);
|
|
|
|
impl PostID
|
|
{
|
|
/// Generate a new `PostID`.
|
|
pub fn new() -> Self
|
|
{
|
|
Self(Uuid::new_v4())
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for PostID
|
|
{
|
|
#[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
self.0.fmt(f) //TODO: Change to use kana-hash.
|
|
}
|
|
}
|
|
|
|
/// A user's data, if set.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct User
|
|
{
|
|
pub name: Option<String>,
|
|
pub email: Option<String>,
|
|
pub tripcode: Option<tripcode::Tripcode>,
|
|
}
|
|
|
|
impl User
|
|
{
|
|
/// The name string of this instance, or the default name.
|
|
pub fn name_str(&self) -> &str
|
|
{
|
|
self.name.as_ref().map(|x| &x[..]).unwrap_or(&config::get().anon_name[..])
|
|
}
|
|
|
|
/// The email string of this instance, if it is set
|
|
pub fn email_str(&self) -> Option<&str>
|
|
{
|
|
self.email.as_ref().map(|x| &x[..])
|
|
}
|
|
|
|
// No str for tripcode because it's not just a string (yet)
|
|
|
|
/// Anon with no detials.
|
|
pub const fn anon() -> Self
|
|
{
|
|
Self {
|
|
name: None,
|
|
email: None,
|
|
tripcode: None,
|
|
}
|
|
}
|
|
}
|
|
|