forked from lavina/lavina
fix message sending
This commit is contained in:
parent
43ea27b655
commit
377d9c32d2
|
@ -78,7 +78,7 @@ impl Storage {
|
||||||
|
|
||||||
pub async fn insert_message(&mut self, room_id: u32, id: u32, content: &str) -> Result<()> {
|
pub async fn insert_message(&mut self, room_id: u32, id: u32, content: &str) -> Result<()> {
|
||||||
let mut executor = self.conn.lock().await;
|
let mut executor = self.conn.lock().await;
|
||||||
let (_,): (u32,) = sqlx::query_as(
|
sqlx::query(
|
||||||
"insert into messages(room_id, id, content)
|
"insert into messages(room_id, id, content)
|
||||||
values (?, ?, ?);
|
values (?, ?, ?);
|
||||||
update rooms set message_count = message_count + 1 where id = ?;",
|
update rooms set message_count = message_count + 1 where id = ?;",
|
||||||
|
@ -87,7 +87,7 @@ impl Storage {
|
||||||
.bind(id)
|
.bind(id)
|
||||||
.bind(content)
|
.bind(content)
|
||||||
.bind(room_id)
|
.bind(room_id)
|
||||||
.fetch_one(&mut *executor)
|
.execute(&mut *executor)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -140,7 +140,10 @@ impl RoomHandle {
|
||||||
|
|
||||||
pub async fn send_message(&self, player_id: PlayerId, body: Str) {
|
pub async fn send_message(&self, player_id: PlayerId, body: Str) {
|
||||||
let mut lock = self.0.write().await;
|
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 {
|
pub async fn get_room_info(&self) -> RoomInfo {
|
||||||
|
@ -200,6 +203,7 @@ impl Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn broadcast_update(&self, update: Updates, except: &PlayerId) {
|
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 {
|
for (player_id, sub) in &self.subscriptions {
|
||||||
if player_id == except {
|
if player_id == except {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue