seperated ident info from post to struct

new-idea
Avril 4 years ago
parent 4e813abed5
commit d72df0c9b2
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -25,17 +25,25 @@ pub type PostBodyString = hard_format::FormattedString<PostBodyFormat>;
/// A size limited PEM string /// A size limited PEM string
pub type PostBodyStr = hard_format::FormattedStr<PostBodyFormat>; pub type PostBodyStr = hard_format::FormattedStr<PostBodyFormat>;
/// Identifiers for a post
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Ident
{
name: Option<IDMaxString>,
tripcode: Option<Tripcode>,
email: Option<IDMaxString>,
}
/// A single completed post /// A single completed post
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct Post pub struct Post
{ {
/// Unique ID for each post /// Unique ID for each post
id: PostID, id: PostID,
name: Option<IDMaxString>,
tripcode: Option<Tripcode>,
email: Option<IDMaxString>,
/// Identifiers for this post
ident: Ident,
/// The client-side encrypted body string /// The client-side encrypted body string
body: PostBodyString, body: PostBodyString,
@ -47,6 +55,7 @@ pub struct Post
/// When the post was created /// When the post was created
created: PostTimestamp, created: PostTimestamp,
/// When the post was last edited. /// When the post was last edited.
/// ///
/// # Notes /// # Notes
@ -80,7 +89,7 @@ impl Post
/// The user-set name for this post if there is one. /// The user-set name for this post if there is one.
#[inline] pub fn own_name(&self) -> Option<&str> #[inline] pub fn own_name(&self) -> Option<&str>
{ {
self.name.as_ref().map(|x| x.as_str()) self.ident.name.as_ref().map(|x| x.as_str())
} }
/// The name for this post. /// The name for this post.
/// ///
@ -93,13 +102,13 @@ impl Post
/// The email set for this post, if there is one. /// The email set for this post, if there is one.
pub fn email(&self) -> Option<&str> pub fn email(&self) -> Option<&str>
{ {
self.email.as_ref().map(|x| x.as_str()) self.ident.email.as_ref().map(|x| x.as_str())
} }
/// Get the tripcode of this post, if there is one. /// Get the tripcode of this post, if there is one.
pub fn tripcode(&self) -> Option<&Tripcode> pub fn tripcode(&self) -> Option<&Tripcode>
{ {
self.tripcode.as_ref() self.ident.tripcode.as_ref()
} }
/// The body of this post /// The body of this post
@ -123,9 +132,11 @@ mod tests
use std::convert::TryInto; use std::convert::TryInto;
let post = super::Post { let post = super::Post {
id: super::PostID::id_new(), id: super::PostID::id_new(),
name: Some("Some name".to_owned().try_into().unwrap()), ident: super::Ident {
email: None, name: Some("Some name".to_owned().try_into().unwrap()),
tripcode: Some(super::Tripcode::generate("uhh hello").unwrap()), email: None,
tripcode: Some(super::Tripcode::generate("uhh hello").unwrap()),
},
body: unsafe { super::PostBodyStr::new_unchecked("test").to_owned() }, //temporary body: unsafe { super::PostBodyStr::new_unchecked("test").to_owned() }, //temporary
signature: None, signature: None,
hash: Default::default(), hash: Default::default(),

Loading…
Cancel
Save