fix: Handle the websocet in handle_socket itself
All checks were successful
DCO checker / DCO checker (pull_request) Successful in 4s
Rust CI / Rust CI (pull_request) Successful in 4m16s

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-27 12:25:51 +03:00
parent b4cac39157
commit cc59b02b2d
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -148,38 +148,33 @@ async fn handle_socket(
// TODO: Send the incoming chat request to the user, while they are offline. // TODO: Send the incoming chat request to the user, while they are offline.
// This after adding last_login col to the user table // This after adding last_login col to the user table
let fut = async move { while let Some(Ok(msg)) = user_ws_receiver.next().await {
while let Some(Ok(msg)) = user_ws_receiver.next().await { match handle_ws_msg(msg, &nonce_cache, &user_shared_secret).await {
match handle_ws_msg(msg, &nonce_cache, &user_shared_secret).await { Ok(event) => {
Ok(event) => { if let Some(server_event) =
if let Some(server_event) = handle_events(event, &db_conn, &conn_id, user.as_ref()).await
handle_events(event, &db_conn, &conn_id, user.as_ref()).await {
{ if let Err(err) = sender
if let Err(err) = sender.unbounded_send(Ok(server_event .unbounded_send(Ok(server_event.sign(&user_shared_secret).as_ref().into()))
.sign(&user_shared_secret)
.as_ref()
.into()))
{
log::error!("Websocket Error: {err}");
break;
}
};
}
Err(err) => {
if let Err(err) = sender.unbounded_send(Ok(ServerEvent::from(err)
.sign(&user_shared_secret)
.as_ref()
.into()))
{ {
log::error!("Websocket Error: {err}"); log::error!("Websocket Error: {err}");
break; break;
}; }
} };
}; }
} Err(err) => {
user_disconnected(&db_conn, &conn_id, &user_public_key, user).await; if let Err(err) = sender.unbounded_send(Ok(ServerEvent::from(err)
}; .sign(&user_shared_secret)
tokio_spawn(fut); .as_ref()
.into()))
{
log::error!("Websocket Error: {err}");
break;
};
}
};
}
user_disconnected(&db_conn, &conn_id, &user_public_key, user).await;
} }
/// Handle websocket msg /// Handle websocket msg