refactor chat timestamp to u64

This commit is contained in:
nworbnhoj 2023-08-04 09:17:43 +10:00
parent 29d06e18bf
commit 9db7a3c2c5
5 changed files with 13 additions and 13 deletions

View file

@ -35,7 +35,7 @@ pub const POST_TEXT_MAX: usize = 3072;
#[derive(Archive, Serialize, Deserialize, Debug)] #[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Find { pub struct Find {
pub author: xous_ipc::String<128>, pub author: xous_ipc::String<128>,
pub timestamp: u32, pub timestamp: u64,
pub key: Option<usize>, // the return post key if found. pub key: Option<usize>, // the return post key if found.
} }
@ -48,7 +48,7 @@ pub struct Dialogue {
#[derive(Archive, Serialize, Deserialize, Debug)] #[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Post { pub struct Post {
pub author: xous_ipc::String<128>, pub author: xous_ipc::String<128>,
pub timestamp: u32, pub timestamp: u64,
pub text: xous_ipc::String<POST_TEXT_MAX>, pub text: xous_ipc::String<POST_TEXT_MAX>,
pub attach_url: Option<xous_ipc::String<128>>, pub attach_url: Option<xous_ipc::String<128>>,
} }

View file

@ -21,7 +21,7 @@ pub struct Dialogue {
posts: Vec<Post>, posts: Vec<Post>,
authors: HashMap<u16, Author>, authors: HashMap<u16, Author>,
author_lookup: HashMap<String, u16>, author_lookup: HashMap<String, u16>,
last_timestamp: u32, last_timestamp: u64,
last_author_id: u16, last_author_id: u16,
} }
@ -48,7 +48,7 @@ impl Dialogue {
pub fn post_add( pub fn post_add(
&mut self, &mut self,
author: &str, author: &str,
timestamp: u32, timestamp: u64,
text: &str, text: &str,
_attach_url: Option<&str>, _attach_url: Option<&str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -82,7 +82,7 @@ impl Dialogue {
} }
} }
pub fn post_find(&self, author: &str, timestamp: u32) -> Option<usize> { pub fn post_find(&self, author: &str, timestamp: u64) -> Option<usize> {
if let Some(author_id) = self.author_lookup.get(author) { if let Some(author_id) = self.author_lookup.get(author) {
match self match self
.posts .posts

View file

@ -7,7 +7,7 @@ use rkyv::{Archive, Deserialize, Serialize};
#[derive(Archive, Serialize, Deserialize, Debug)] #[derive(Archive, Serialize, Deserialize, Debug)]
pub struct Post { pub struct Post {
author_id: u16, author_id: u16,
timestamp: u32, timestamp: u64,
text: String, text: String,
attach: Option<Attach>, attach: Option<Attach>,
pub flags: u16, pub flags: u16,
@ -15,7 +15,7 @@ pub struct Post {
#[allow(dead_code)] #[allow(dead_code)]
impl Post { impl Post {
pub fn new(author_id: u16, timestamp: u32, text: &str, attach: Option<Attach>) -> Self { pub fn new(author_id: u16, timestamp: u64, text: &str, attach: Option<Attach>) -> Self {
Self { Self {
author_id: author_id, author_id: author_id,
timestamp: timestamp, timestamp: timestamp,
@ -45,7 +45,7 @@ impl Post {
self.text.as_str() self.text.as_str()
} }
pub fn timestamp(&self) -> u32 { pub fn timestamp(&self) -> u64 {
self.timestamp self.timestamp
} }
} }

View file

@ -62,7 +62,7 @@ impl Chat {
pub fn post_add( pub fn post_add(
&self, &self,
author: &str, author: &str,
timestamp: u32, timestamp: u64,
text: &str, text: &str,
attach_url: Option<&str>, attach_url: Option<&str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -90,7 +90,7 @@ impl Chat {
} }
// get a Post from the current Dialogue // get a Post from the current Dialogue
pub fn post_find(&self, author: &str, timestamp: u32) -> Result<Option<usize>, Error> { pub fn post_find(&self, author: &str, timestamp: u64) -> Result<Option<usize>, Error> {
let mut find = Find { let mut find = Find {
author: xous_ipc::String::new(), author: xous_ipc::String::new(),
timestamp: timestamp, timestamp: timestamp,
@ -266,7 +266,7 @@ pub fn server(
xous::terminate_process(0) xous::terminate_process(0)
} }
pub fn now() -> u32 { pub fn now() -> u64 {
SystemTime::now() SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.unwrap() .unwrap()

View file

@ -238,7 +238,7 @@ impl Ui {
pub fn post_add( pub fn post_add(
&mut self, &mut self,
author: &str, author: &str,
timestamp: u32, timestamp: u64,
text: &str, text: &str,
attach_url: Option<&str>, attach_url: Option<&str>,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -264,7 +264,7 @@ impl Ui {
} }
// get a Post from the current Dialogue // get a Post from the current Dialogue
pub fn post_find(&self, author: &str, timestamp: u32) -> Option<usize> { pub fn post_find(&self, author: &str, timestamp: u64) -> Option<usize> {
match &self.dialogue { match &self.dialogue {
Some(dialogue) => dialogue.post_find(author, timestamp), Some(dialogue) => dialogue.post_find(author, timestamp),
None => None, None => None,