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.
65 lines
1.3 KiB
65 lines
1.3 KiB
//! Structure for updating posts in-place
|
|
use super::*;
|
|
use std::{
|
|
fmt,
|
|
hash::{
|
|
Hash,Hasher,
|
|
},
|
|
};
|
|
use chrono::prelude::*;
|
|
|
|
/// Represents all valid timestamps for a post.
|
|
///
|
|
/// Usually in UTC, pls keep it in Utc...
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct PostTimestamp<T = Utc>
|
|
where T: TimeZone,
|
|
{
|
|
pub opened: DateTime<T>,
|
|
pub closed: Option<DateTime<T>>,
|
|
pub last_edit: DateTime<T>,
|
|
}
|
|
|
|
impl<Tz: TimeZone> Hash for PostTimestamp<Tz> {
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
self.opened.hash(state);
|
|
self.closed.hash(state);
|
|
self.last_edit.hash(state);
|
|
}
|
|
}
|
|
|
|
impl<T> fmt::Display for PostTimestamp<T>
|
|
where T: TimeZone,
|
|
T::Offset: fmt::Display
|
|
{
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
writeln!(f, " Opened - {}", self.opened)?;
|
|
writeln!(f, " Edited - {}", self.last_edit)?;
|
|
write!(f, " Closed - ")?;
|
|
if let Some(closed) = &self.closed {
|
|
writeln!(f, "{}", closed)?;
|
|
} else {
|
|
writeln!(f, "Stil open")?;
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
/// A closed and finished post. The inverse of `Imouto`.
|
|
pub struct Static
|
|
{
|
|
id: identity::PostID,
|
|
|
|
user: identity::User,
|
|
|
|
title: Option<String>,
|
|
karada: String,
|
|
|
|
timestamp: PostTimestamp,
|
|
|
|
/// Hash of the rest of the post data. . . .
|
|
hash: crypto::sha256::Sha256Hash,
|
|
}
|