Add date info to message

pull/5/head
~erin 2021-07-22 16:20:49 -04:00
parent 70f604e4f0
commit 6328e05b16
Signed by: erin
GPG Key ID: DA70E064A8C70F44
5 changed files with 30 additions and 4 deletions

View File

@ -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

View File

@ -1,6 +1,6 @@
[package]
name = "pogchat"
version = "0.5.0"
version = "0.5.1"
authors = ["Erin Nova <erin@the-system.eu.org>"]
edition = "2018"

View File

@ -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?

View File

@ -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<Mutex<Vec<Message>>> = Lazy::new(|| Mutex::new(Vec::new()));
@ -35,9 +36,10 @@ fn create_message(message: Json<MessageInput>, 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<MessageInput<'_>>, mut cookies: Cookies) -> Js
};
check_token(token, message)
}
// Delete a message
/*
#[post("/message/delete", format = "json", data = "<message>")]
pub fn delete_message(message: Json<MessageInput<'_>>, 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,
};
}
*/

View File

@ -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)]