diff --git a/server/src/messages.rs b/server/src/messages.rs index bfdea37..00f0060 100644 --- a/server/src/messages.rs +++ b/server/src/messages.rs @@ -1,20 +1,24 @@ -use std::collections::HashMap; +use std::borrow::Cow; use mysql_async::Pool; - -use hyper::{Response, Body, StatusCode}; +use mysql_async::error::Error; +use hyper::{Response, Body}; +use serde_json::Value; use crate::members::Member; +use crate::channels::{Channel, ChannelID}; struct Message { author: Member, date: u64, - content: String + content: String, + channel: Channel } enum MsgParam { Good, + Incomplete, Empty } impl MsgParam { @@ -33,19 +37,48 @@ impl MsgParam { } } -fn parse_send_params(p: &HashMap<&str, &str>, keys: Vec<&str>) -> MsgParam { - let mut cond = MsgParam::Good; - for k in keys.iter() { - if !p.contains_key(k) { - cond = MsgParam::Empty; +fn validate_params(p: &Value, keys: Vec<&str>) -> bool { + let mut fail = false; + for key in keys.iter() { + if let None = p.get(key) { + fail = true; + break; } } - cond + return fail == false; } -pub async fn send_message(pool: &Pool, response: &Response
, params: &HashMap<&str, &str>) { - match parse_send_params(params, vec!["content", "id"]) { - MsgParam::Good => {}, - MsgParam::Empty => {} +async fn update_messages_table(pool: &Pool, secret: &str, content: Option<&str>, id: Option