From 757d7c56657f5ec6a291d2cbae5a7c7ee90b32bc Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Mon, 15 Apr 2024 09:12:23 +0000 Subject: [PATCH] persistent room topics (#50) Reviewed-on: https://git.vilunov.me/lavina/lavina/pulls/50 --- crates/lavina-core/src/repo/room.rs | 15 +++++++++++++++ crates/lavina-core/src/room.rs | 2 ++ 2 files changed, 17 insertions(+) diff --git a/crates/lavina-core/src/repo/room.rs b/crates/lavina-core/src/repo/room.rs index b568b9d..96b89f2 100644 --- a/crates/lavina-core/src/repo/room.rs +++ b/crates/lavina-core/src/repo/room.rs @@ -30,4 +30,19 @@ impl Storage { Ok(()) } + + pub async fn set_room_topic(&mut self, id: u32, topic: &str) -> Result<()> { + let mut executor = self.conn.lock().await; + sqlx::query( + "update rooms + set topic = ? + where id = ?;", + ) + .bind(topic) + .bind(id) + .fetch_optional(&mut *executor) + .await?; + + Ok(()) + } } diff --git a/crates/lavina-core/src/room.rs b/crates/lavina-core/src/room.rs index dbd14fd..a5e2dab 100644 --- a/crates/lavina-core/src/room.rs +++ b/crates/lavina-core/src/room.rs @@ -182,7 +182,9 @@ impl RoomHandle { pub async fn set_topic(&self, changer_id: &PlayerId, new_topic: Str) { let mut lock = self.0.write().await; + let storage_id = lock.storage_id; lock.topic = new_topic.clone(); + lock.storage.set_room_topic(storage_id, &new_topic).await.unwrap(); let update = Updates::RoomTopicChanged { room_id: lock.room_id.clone(), new_topic: new_topic.clone(),