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
This commit is contained in:
shockrah 2021-04-02 13:56:44 -07:00
parent be54ce6a57
commit 3f1dfbf824
4 changed files with 15 additions and 4 deletions

View File

@ -10,6 +10,7 @@ use db::{ self, Channel};
use crate::http::set_json_body; use crate::http::set_json_body;
use crate::qs_param; use crate::qs_param;
use crate::rtc;
pub async fn list_channels(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) { pub async fn list_channels(pool: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
@ -58,6 +59,7 @@ pub async fn create_channel(pool: &Pool, response: &mut Response<Body>, params:
match resp { match resp {
Row(channel) => { Row(channel) => {
set_json_body(response, json!(channel)); set_json_body(response, json!(channel));
rtc::create_channel(channel).await;
StatusCode::OK StatusCode::OK
}, },
@ -112,7 +114,9 @@ pub async fn delete_channel(pool: &Pool, response: &mut Response<Body>, params:
if let Some(id) = channel_id { if let Some(id) = channel_id {
match Channel::delete(pool, id).await { 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 */} Ok(_) => {/* can't actually happen */}
Err(e) => { // ngmi Err(e) => { // ngmi
eprintln!("{}", e); eprintln!("{}", e);

View File

@ -117,7 +117,7 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
route_dispatcher(&DB_POOL, &mut response, &method, path, body, params, headers).await; route_dispatcher(&DB_POOL, &mut response, &method, path, body, params, headers).await;
}, },
LoginValid => { LoginValid => {
auth::login_get_jwt(&DB_POOL, &mut response, params).await; auth::login_get_jwt(&mut response, params).await;
}, },
NoKey | BadKey => { NoKey | BadKey => {
println!("[DEBUG] NoKey | BadKey"); println!("[DEBUG] NoKey | BadKey");

View File

@ -9,6 +9,7 @@ use db::Response::*;
use crate::http::set_json_body; use crate::http::set_json_body;
use crate::qs_param; use crate::qs_param;
use crate::rtc;
pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) { pub async fn get_online_members(p: &Pool, response: &mut Response<Body>) {
@ -69,7 +70,10 @@ pub async fn post_self_nickname(p: &Pool, response: &mut Response<Body>, params:
let uid = qs_param!(params, "id", u64).unwrap(); let uid = qs_param!(params, "id", u64).unwrap();
match Member::update_nick(p, uid, nick.as_ref()).await { 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) => { Err(e) => {
eprintln!("{}", e); eprintln!("{}", e);
StatusCode::INTERNAL_SERVER_ERROR StatusCode::INTERNAL_SERVER_ERROR

View File

@ -81,7 +81,10 @@ pub async fn send_message(pool: &Pool, response: &mut Response<Body>, body: Body
Row(user) => user.permissions, Row(user) => user.permissions,
_ => 0 _ => 0
}, },
Err(e) => 0 Err(e) => {
eprintln!("[DB-SQL] {}",e );
0
}
}; };
if perms::has_perm(permissions, perms::SEND_MESSAGES) == false { if perms::has_perm(permissions, perms::SEND_MESSAGES) == false {
*response.status_mut() = StatusCode::BAD_REQUEST; *response.status_mut() = StatusCode::BAD_REQUEST;