+ rtc::new_message now takes a Pool ref to make the second call for the user name
! Start taking public user params like this in the JWT to reduce on network hits It's cheap and reliable enough but the idea just now came to me so do that at some point
This commit is contained in:
parent
894a5bae34
commit
522890fa00
@ -116,7 +116,7 @@ pub async fn send_message(pool: &Pool, response: &mut Response<Body>, body: Body
|
||||
match db::Message::send(pool, &content, ctype.unwrap(), channel_id.unwrap(), uid).await {
|
||||
Ok(Row(msg)) => {
|
||||
use crate::rtc;
|
||||
rtc::new_message(msg).await;
|
||||
rtc::new_message(pool, msg).await;
|
||||
},
|
||||
Ok(Empty) => { }, // idk anymore
|
||||
Ok(RestrictedInput(_msg)) => *response.status_mut() = StatusCode::BAD_REQUEST,
|
||||
|
@ -5,22 +5,21 @@ use hyper::{Response, Body};
|
||||
use serde_json::to_string;
|
||||
use serde::Serialize;
|
||||
|
||||
|
||||
#[derive( Serialize)]
|
||||
pub struct Config {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub hostname: String,
|
||||
pub port: u16,
|
||||
pub protocol: String,
|
||||
pub url: String,
|
||||
pub wsurl: String,
|
||||
}
|
||||
|
||||
pub fn get_config() -> Config {
|
||||
Config {
|
||||
name: var("SERVER_NAME").unwrap_or("No name".into()),
|
||||
description: var("SERVER_DESCRIPTION").unwrap_or("No description".into()),
|
||||
hostname: var("SERVER_HOSTNAME").expect("Couldn't get url from environment"),
|
||||
port: var("SERVER_PORT").expect("Couldn't get port from environment").parse::<u16>().unwrap(),
|
||||
protocol: var("SERVER_PROTOCOL").expect("Couldn't get protocol from environment")
|
||||
url: var("PUBLIC_URL").unwrap(),
|
||||
wsurl: var("PUBLIC_WS_URL").unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use mysql_async::Pool;
|
||||
use tokio_tungstenite::connect_async;
|
||||
use tokio_tungstenite::tungstenite::{Error, Message};
|
||||
use futures::{StreamExt, SinkExt};
|
||||
@ -65,7 +66,6 @@ P: Serialize
|
||||
{
|
||||
// Flow: Connect -> Pick out stream -> Send Data over stream
|
||||
// The stream/connection is destroyed by the end of this call
|
||||
println!("NOTIFYING WSS");
|
||||
let (ws, _) = connect_async(make_url()).await?;
|
||||
let (mut write, _) = ws.split();
|
||||
let event = event!(event_name, &payload);
|
||||
@ -75,7 +75,28 @@ P: Serialize
|
||||
}
|
||||
|
||||
|
||||
pub async fn new_message(message: db::Message) {
|
||||
pub async fn new_message(p: &Pool, message: db::Message) {
|
||||
let uname = match db::Member::get(p, message.author_id).await {
|
||||
Ok(response) => {
|
||||
match response {
|
||||
db::Response::Row(user) => user.name,
|
||||
_ => String::new()
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("[HTTP-RTC] Couldn't fetch username {}", e);
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
let message = db::UserMessage {
|
||||
id: message.id,
|
||||
time: message.time,
|
||||
content: message.content,
|
||||
content_type: message.content_type,
|
||||
author_id: message.author_id,
|
||||
channel_id: message.channel_id,
|
||||
name: uname,
|
||||
};
|
||||
if let Err(e) = notify("new-message", message).await {
|
||||
eprintln!("[API-RTC] Unable to connect to RTC server: {}", e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user