diff --git a/crates/lavina-core/src/repo/mod.rs b/crates/lavina-core/src/repo/mod.rs index e9eee6c..d8af5f7 100644 --- a/crates/lavina-core/src/repo/mod.rs +++ b/crates/lavina-core/src/repo/mod.rs @@ -11,6 +11,8 @@ use tokio::sync::Mutex; use crate::prelude::*; +mod room; + #[derive(Deserialize, Debug, Clone)] pub struct StorageConfig { pub db_path: String, diff --git a/crates/lavina-core/src/repo/room.rs b/crates/lavina-core/src/repo/room.rs new file mode 100644 index 0000000..b3ffc0f --- /dev/null +++ b/crates/lavina-core/src/repo/room.rs @@ -0,0 +1,20 @@ +use anyhow::Result; + +use crate::repo::Storage; + +impl Storage { + 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 04fdbb1..2173dff 100644 --- a/crates/lavina-core/src/room.rs +++ b/crates/lavina-core/src/room.rs @@ -150,7 +150,9 @@ impl RoomHandle { pub async fn set_topic(&mut 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(),