From 6328e05b161399c1b6f7ca03f8759972fafc1d5e Mon Sep 17 00:00:00 2001 From: Erin Nova Date: Thu, 22 Jul 2021 16:20:49 -0400 Subject: [PATCH] Add date info to message --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- README.md | 4 ++-- src/chat.rs | 21 ++++++++++++++++++++- src/message.rs | 1 + 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 593c527..dcf02de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### 0.5.1 +- `/api/logout` API to delete session token +- Add basic support for different message types +- Messages now use unix timestamps + - Backend finds timestamp + ## 0.5.0 - Most actions should now fail on a NULL token - Cookie should now expire after a week diff --git a/Cargo.toml b/Cargo.toml index 26d401a..33c85f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pogchat" -version = "0.5.0" +version = "0.5.1" authors = ["Erin Nova "] edition = "2018" diff --git a/README.md b/README.md index 6cd6bdd..d8f40de 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Returns status & reason json. ## Chat Documentation -`POST /api/message/send {"name":"username","body":"message body","date":"yyy-mm-dd","token":"USER_TOKEN"}` Post a json message. +`POST /api/message/send {"name":"username","body":"message body"}` Post a json message. Returns status & reason json. `GET /api/message/messages.json` Get a json file of all the messages @@ -83,5 +83,5 @@ Whenever user sends a message, client will send message & token and backend will - [ ] User management (banning, etc.) - [ ] Blacklist words from chat/names - [ ] More advanced chat features - - [ ] Different types of message events? eg. default, announcement, command + - [x] Different types of message events? eg. default, announcement, command - [ ] Emote support? diff --git a/src/chat.rs b/src/chat.rs index 3d650dc..fcc2d9c 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -9,6 +9,7 @@ use rocket_contrib::json::{Json, JsonValue}; use chrono::prelude::*; use uuid::Uuid; use crate::user::User; +use std::time::{Duration, SystemTime}; static MESSAGES: Lazy>> = Lazy::new(|| Mutex::new(Vec::new())); @@ -35,9 +36,10 @@ fn create_message(message: Json, file: &str, user: &User) -> JsonV user: user.name.to_owned(), body: message.body.to_string(), event_type: event_type, - created_at: Utc.timestamp(1_500_000_000, 0), + created_at: Utc::now(), }; info!("created mesage: {:?}", message_obj); + info!("Date is: {}", message_obj.created_at.to_rfc2822()); // append message to file let mut messages = MESSAGES.lock().unwrap(); @@ -95,3 +97,20 @@ pub fn send_message(message: Json>, mut cookies: Cookies) -> Js }; check_token(token, message) } + +// Delete a message +/* +#[post("/message/delete", format = "json", data = "")] +pub fn delete_message(message: Json>, mut cookies: Cookies) -> JsonValue { + let token = match cookies.get_private("token") { + None => { + warn!("couldn't get token cookie!"); + return json!({ + "status": "fail", + "reason": "could not read cookie", + }); + }, + Some(token) => token, + }; +} +*/ diff --git a/src/message.rs b/src/message.rs index d7159ab..58f1af3 100644 --- a/src/message.rs +++ b/src/message.rs @@ -7,6 +7,7 @@ use uuid::Uuid; pub struct MessageInput<'r> { pub name: &'r str, pub body: &'r str, + pub date: i64, } #[derive(Clone, Debug, Serialize, Deserialize)]