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