forked from lavina/lavina
persist room leaves
This commit is contained in:
parent
79d626330c
commit
b3af10a70a
|
@ -412,7 +412,7 @@ impl Player {
|
|||
let room = self.my_rooms.remove(&room_id);
|
||||
if let Some(room) = room {
|
||||
room.unsubscribe(&self.player_id).await;
|
||||
room.remove_member(&self.player_id).await;
|
||||
room.remove_member(&self.player_id, self.storage_id).await;
|
||||
}
|
||||
let update = Updates::RoomLeft {
|
||||
room_id,
|
||||
|
|
|
@ -3,7 +3,7 @@ use anyhow::Result;
|
|||
use crate::repo::Storage;
|
||||
|
||||
impl Storage {
|
||||
pub async fn add_room_member(&mut self, room_id: &u32, player_id: &u32) -> Result<()> {
|
||||
pub async fn add_room_member(&self, room_id: &u32, player_id: &u32) -> Result<()> {
|
||||
let mut executor = self.conn.lock().await;
|
||||
sqlx::query(
|
||||
"insert into memberships(user_id, room_id, status)
|
||||
|
@ -16,4 +16,18 @@ impl Storage {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn remove_room_member(&self, room_id: &u32, player_id: &u32) -> Result<()> {
|
||||
let mut executor = self.conn.lock().await;
|
||||
sqlx::query(
|
||||
"delete from memberships
|
||||
where user_id = ? and room_id = ?;",
|
||||
)
|
||||
.bind(player_id)
|
||||
.bind(room_id)
|
||||
.execute(&mut *executor)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,10 +162,12 @@ impl RoomHandle {
|
|||
lock.subscriptions.remove(player_id);
|
||||
}
|
||||
|
||||
pub async fn remove_member(&self, player_id: &PlayerId) {
|
||||
pub async fn remove_member(&self, player_id: &PlayerId, player_storage_id: u32) {
|
||||
let mut lock = self.0.write().await;
|
||||
tracing::info!("Removing a member from a room");
|
||||
let storage_id = lock.storage_id;
|
||||
lock.members.remove(player_id);
|
||||
lock.storage.remove_room_member(&storage_id, &player_storage_id).await.unwrap();
|
||||
let update = Updates::RoomLeft {
|
||||
room_id: lock.room_id.clone(),
|
||||
former_member_id: player_id.clone(),
|
||||
|
|
Loading…
Reference in New Issue