Add more messaging funcionality
parent
117ee9935e
commit
e95022e994
12
README.md
12
README.md
|
@ -27,8 +27,18 @@ Whenever user sends a message, client will send message & token and backend will
|
||||||
|
|
||||||
- [x] Basic auth api
|
- [x] Basic auth api
|
||||||
- [ ] Basic messaging system
|
- [ ] Basic messaging system
|
||||||
|
- [ ] Finish up `chat::create_message()`
|
||||||
|
- [ ] Create `chat::read_messages()`
|
||||||
|
- [ ] Create `chat::delete_message()`
|
||||||
|
- [ ] Different types of message events? eg. default, announcement, command
|
||||||
|
- [ ] Emote support?
|
||||||
- [ ] Token generation & storage
|
- [ ] Token generation & storage
|
||||||
|
- [ ] API to refresh token
|
||||||
|
- [ ] Store token in json
|
||||||
|
- [ ] API to check token?
|
||||||
- [x] Pronouns
|
- [x] Pronouns
|
||||||
- [ ] Change pronouns
|
- [ ] Change pronouns
|
||||||
|
- [ ] Multiple sets of pronouns
|
||||||
|
- [ ] Some form of plural support?
|
||||||
- [ ] User management (banning, etc.)
|
- [ ] User management (banning, etc.)
|
||||||
- [ ] Blacklist words from chat/names
|
- [ ] Blacklist words from chat/names
|
||||||
|
|
33
src/chat.rs
33
src/chat.rs
|
@ -1,12 +1,39 @@
|
||||||
/* Contains Rocket code for chat/message functionality */
|
/* Contains Rocket code for chat/message functionality */
|
||||||
extern crate log;
|
extern crate log;
|
||||||
use crate::message::Message;
|
use crate::file_io::{read_json};
|
||||||
|
use crate::message::{Message, MessageInput};
|
||||||
use rocket_contrib::json::{Json, JsonValue};
|
use rocket_contrib::json::{Json, JsonValue};
|
||||||
|
use chrono::prelude::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
use crate::user::User;
|
||||||
|
|
||||||
|
// Check if user can create the message, and then create more info about the message
|
||||||
|
fn create_message(message: Json<MessageInput>, file: &str, token: &str) {
|
||||||
|
// check if token is correct for name given
|
||||||
|
// create full message object
|
||||||
|
// append message to file
|
||||||
|
|
||||||
|
let date_split: Vec<&str> = message.date.split("-").collect();
|
||||||
|
let year: i32 = match date_split[0].trim().parse() {
|
||||||
|
Err(why) => panic!("could not extract year from given date: {}", why),
|
||||||
|
Ok(year) => year,
|
||||||
|
};
|
||||||
|
let date: DateTime<Utc> = Utc.ymd(year, 7, 7).and_hms(9, 10, 11);
|
||||||
|
let message_obj: Message = Message {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
user: User { name: message.name.to_string(), pin_hashed: "no".to_string(), pronouns: "she/her".to_string(), session_token: "NULL".to_string() },
|
||||||
|
body: message.body.to_string(),
|
||||||
|
created_at: Utc.ymd(2005, 7, 8).and_hms(9, 10, 11),
|
||||||
|
};
|
||||||
|
println!("{:?}", message_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receive a basic message
|
||||||
#[post("/api/message/send", format = "json", data = "<message>")]
|
#[post("/api/message/send", format = "json", data = "<message>")]
|
||||||
pub fn send_message(message: Json<Message<'_>>) -> JsonValue {
|
pub fn send_message(message: Json<MessageInput<'_>>) -> JsonValue {
|
||||||
|
create_message(message, "messages.json", "token");
|
||||||
json!({
|
json!({
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"reason": "bruh"
|
"reason": ""
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,16 @@ use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct Message<'r> {
|
pub struct MessageInput<'r> {
|
||||||
|
pub name: &'r str,
|
||||||
|
pub body: &'r str,
|
||||||
|
pub date: &'r str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Message {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub user: User,
|
pub user: User,
|
||||||
pub body: &'r str,
|
pub body: String,
|
||||||
pub created_at: DateTime<Utc>,
|
pub created_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// Struct to store basic user data
|
// Struct to store basic user data
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub pin_hashed: String,
|
pub pin_hashed: String,
|
||||||
|
|
Loading…
Reference in New Issue