fix message sending

This commit is contained in:
Nikita Vilunov 2023-09-06 16:34:20 +02:00
parent 43ea27b655
commit 377d9c32d2
2 changed files with 7 additions and 3 deletions

View File

@ -78,7 +78,7 @@ impl Storage {
pub async fn insert_message(&mut self, room_id: u32, id: u32, content: &str) -> Result<()> {
let mut executor = self.conn.lock().await;
let (_,): (u32,) = sqlx::query_as(
sqlx::query(
"insert into messages(room_id, id, content)
values (?, ?, ?);
update rooms set message_count = message_count + 1 where id = ?;",
@ -87,7 +87,7 @@ impl Storage {
.bind(id)
.bind(content)
.bind(room_id)
.fetch_one(&mut *executor)
.execute(&mut *executor)
.await?;
Ok(())

View File

@ -140,7 +140,10 @@ impl RoomHandle {
pub async fn send_message(&self, player_id: PlayerId, body: Str) {
let mut lock = self.0.write().await;
lock.send_message(player_id, body).await;
let res = lock.send_message(player_id, body).await;
if let Err(err) = res {
log::warn!("Failed to send message: {err:?}");
}
}
pub async fn get_room_info(&self) -> RoomInfo {
@ -200,6 +203,7 @@ impl Room {
}
async fn broadcast_update(&self, update: Updates, except: &PlayerId) {
tracing::debug!("Broadcasting an update to {} subs", self.subscriptions.len());
for (player_id, sub) in &self.subscriptions {
if player_id == except {
continue;