Add date info to message
parent
70f604e4f0
commit
6328e05b16
|
@ -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
|
## 0.5.0
|
||||||
- Most actions should now fail on a NULL token
|
- Most actions should now fail on a NULL token
|
||||||
- Cookie should now expire after a week
|
- Cookie should now expire after a week
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pogchat"
|
name = "pogchat"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
authors = ["Erin Nova <erin@the-system.eu.org>"]
|
authors = ["Erin Nova <erin@the-system.eu.org>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ Returns status & reason json.
|
||||||
|
|
||||||
## Chat Documentation
|
## 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.
|
Returns status & reason json.
|
||||||
|
|
||||||
`GET /api/message/messages.json` Get a json file of all the messages
|
`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.)
|
- [ ] User management (banning, etc.)
|
||||||
- [ ] Blacklist words from chat/names
|
- [ ] Blacklist words from chat/names
|
||||||
- [ ] More advanced chat features
|
- [ ] 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?
|
- [ ] Emote support?
|
||||||
|
|
21
src/chat.rs
21
src/chat.rs
|
@ -9,6 +9,7 @@ use rocket_contrib::json::{Json, JsonValue};
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use crate::user::User;
|
use crate::user::User;
|
||||||
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
static MESSAGES: Lazy<Mutex<Vec<Message>>> = Lazy::new(|| Mutex::new(Vec::new()));
|
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(),
|
user: user.name.to_owned(),
|
||||||
body: message.body.to_string(),
|
body: message.body.to_string(),
|
||||||
event_type: event_type,
|
event_type: event_type,
|
||||||
created_at: Utc.timestamp(1_500_000_000, 0),
|
created_at: Utc::now(),
|
||||||
};
|
};
|
||||||
info!("created mesage: {:?}", message_obj);
|
info!("created mesage: {:?}", message_obj);
|
||||||
|
info!("Date is: {}", message_obj.created_at.to_rfc2822());
|
||||||
|
|
||||||
// append message to file
|
// append message to file
|
||||||
let mut messages = MESSAGES.lock().unwrap();
|
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)
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -7,6 +7,7 @@ use uuid::Uuid;
|
||||||
pub struct MessageInput<'r> {
|
pub struct MessageInput<'r> {
|
||||||
pub name: &'r str,
|
pub name: &'r str,
|
||||||
pub body: &'r str,
|
pub body: &'r str,
|
||||||
|
pub date: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
|
Loading…
Reference in New Issue