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