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(),