Add more messaging funcionality

pull/5/head
~erin 2021-07-17 22:27:05 -04:00
parent 117ee9935e
commit e95022e994
Signed by: erin
GPG Key ID: DA70E064A8C70F44
4 changed files with 51 additions and 7 deletions

View File

@ -27,8 +27,18 @@ Whenever user sends a message, client will send message & token and backend will
- [x] Basic auth api
- [ ] 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
- [ ] API to refresh token
- [ ] Store token in json
- [ ] API to check token?
- [x] Pronouns
- [ ] Change pronouns
- [ ] Change pronouns
- [ ] Multiple sets of pronouns
- [ ] Some form of plural support?
- [ ] User management (banning, etc.)
- [ ] Blacklist words from chat/names

View File

@ -1,12 +1,39 @@
/* Contains Rocket code for chat/message functionality */
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 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>")]
pub fn send_message(message: Json<Message<'_>>) -> JsonValue {
pub fn send_message(message: Json<MessageInput<'_>>) -> JsonValue {
create_message(message, "messages.json", "token");
json!({
"status": "ok",
"reason": "bruh"
"reason": ""
})
}

View File

@ -4,9 +4,16 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[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 user: User,
pub body: &'r str,
pub body: String,
pub created_at: DateTime<Utc>,
}

View File

@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
// Struct to store basic user data
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct User {
pub name: String,
pub pin_hashed: String,