From 3f1dfbf824d28ec85bd17691226d20ece6b2ceee Mon Sep 17 00:00:00 2001 From: shockrah Date: Fri, 2 Apr 2021 13:56:44 -0700 Subject: [PATCH] Adding rtc notifications to relevant endpoints ! Still need a feature flag to compile this optionally instead of all the time - Removed warning in main's auth::login_get_jwt call --- json-api/src/channels.rs | 6 +++++- json-api/src/main.rs | 2 +- json-api/src/members.rs | 6 +++++- json-api/src/messages.rs | 5 ++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/json-api/src/channels.rs b/json-api/src/channels.rs index 29ab0b5..fd3fb28 100644 --- a/json-api/src/channels.rs +++ b/json-api/src/channels.rs @@ -10,6 +10,7 @@ use db::{ self, Channel}; use crate::http::set_json_body; use crate::qs_param; +use crate::rtc; pub async fn list_channels(pool: &Pool, response: &mut Response, params: HashMap) { @@ -58,6 +59,7 @@ pub async fn create_channel(pool: &Pool, response: &mut Response, params: match resp { Row(channel) => { set_json_body(response, json!(channel)); + rtc::create_channel(channel).await; StatusCode::OK }, @@ -112,7 +114,9 @@ pub async fn delete_channel(pool: &Pool, response: &mut Response, params: if let Some(id) = channel_id { match Channel::delete(pool, id).await { - Ok(Success) => {/* nothing to do on sucess */}, + Ok(Success) => { + rtc::delete_channel(id).await; + }, Ok(_) => {/* can't actually happen */} Err(e) => { // ngmi eprintln!("{}", e); diff --git a/json-api/src/main.rs b/json-api/src/main.rs index 988713c..a0c6e8c 100644 --- a/json-api/src/main.rs +++ b/json-api/src/main.rs @@ -117,7 +117,7 @@ async fn main_responder(request: Request) -> Result, hyper: route_dispatcher(&DB_POOL, &mut response, &method, path, body, params, headers).await; }, LoginValid => { - auth::login_get_jwt(&DB_POOL, &mut response, params).await; + auth::login_get_jwt(&mut response, params).await; }, NoKey | BadKey => { println!("[DEBUG] NoKey | BadKey"); diff --git a/json-api/src/members.rs b/json-api/src/members.rs index 84b5556..1939b97 100644 --- a/json-api/src/members.rs +++ b/json-api/src/members.rs @@ -9,6 +9,7 @@ use db::Response::*; use crate::http::set_json_body; use crate::qs_param; +use crate::rtc; pub async fn get_online_members(p: &Pool, response: &mut Response) { @@ -69,7 +70,10 @@ pub async fn post_self_nickname(p: &Pool, response: &mut Response, params: let uid = qs_param!(params, "id", u64).unwrap(); match Member::update_nick(p, uid, nick.as_ref()).await { - Ok(_) => StatusCode::OK, + Ok(_) => { + rtc::update_nickname(uid, nick.as_str()).await; + StatusCode::OK + }, Err(e) => { eprintln!("{}", e); StatusCode::INTERNAL_SERVER_ERROR diff --git a/json-api/src/messages.rs b/json-api/src/messages.rs index 50a0df1..20d9744 100644 --- a/json-api/src/messages.rs +++ b/json-api/src/messages.rs @@ -81,7 +81,10 @@ pub async fn send_message(pool: &Pool, response: &mut Response, body: Body Row(user) => user.permissions, _ => 0 }, - Err(e) => 0 + Err(e) => { + eprintln!("[DB-SQL] {}",e ); + 0 + } }; if perms::has_perm(permissions, perms::SEND_MESSAGES) == false { *response.status_mut() = StatusCode::BAD_REQUEST;