fix crash trying to send message to offline user

This commit is contained in:
Adam 2024-08-27 15:04:10 -04:00
parent 90b647795a
commit 78d6486822

View file

@ -59,30 +59,20 @@ impl UserHandler {
// Determine lookup method // Determine lookup method
match method { match method {
Id(id) => { Id(id) => {
tx = self if let Some(user) = self.state.users_by_id.read().unwrap().get(&id) {
.state tx = user.read().unwrap().tx.clone();
.users_by_id } else {
.read() tracing::error!("Attempted to send message to invalid user id!");
.unwrap() return;
.get(&id) }
.unwrap()
.read()
.unwrap()
.tx
.clone();
} }
Addr(addr) => { Addr(addr) => {
tx = self if let Some(user) = self.state.online_users.read().unwrap().get(&addr) {
.state tx = user.read().unwrap().tx.clone();
.online_users } else {
.read() tracing::error!("Attempted to send message to offline user!");
.unwrap() return;
.get(&addr) }
.unwrap()
.read()
.unwrap()
.tx
.clone();
} }
} }
@ -90,15 +80,15 @@ impl UserHandler {
match message { match message {
SendUserUpdate(message) => { SendUserUpdate(message) => {
let msg = to_string::<UserUpdate>(&message).unwrap(); let msg = to_string::<UserUpdate>(&message).unwrap();
tx.send(msg).await.unwrap() let _ = tx.send(msg).await;
} }
SendChatMessage(message) => { SendChatMessage(message) => {
let msg = to_string::<ChatMessage>(&message).unwrap(); let msg = to_string::<ChatMessage>(&message).unwrap();
tx.send(msg).await.unwrap() let _ = tx.send(msg).await;
} }
SendJudgeRound(message) => { SendJudgeRound(message) => {
let msg = to_string::<JudgeRound>(&message).unwrap(); let msg = to_string::<JudgeRound>(&message).unwrap();
tx.send(msg).await.unwrap() // TODO: Fix explosion here when user disconnects let _ = tx.send(msg).await;
} }
} }
} }