forked from lavina/lavina
1
0
Fork 0

Compare commits

...

2 Commits

3 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,8 @@ use tokio::sync::Mutex;
use crate::prelude::*; use crate::prelude::*;
mod room;
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
pub struct StorageConfig { pub struct StorageConfig {
pub db_path: String, pub db_path: String,

View File

@ -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(())
}
}

View File

@ -150,7 +150,9 @@ impl RoomHandle {
pub async fn set_topic(&mut self, changer_id: PlayerId, new_topic: Str) { pub async fn set_topic(&mut self, changer_id: PlayerId, new_topic: Str) {
let mut lock = self.0.write().await; let mut lock = self.0.write().await;
let storage_id = lock.storage_id;
lock.topic = new_topic.clone(); lock.topic = new_topic.clone();
lock.storage.set_room_topic(storage_id, &new_topic).await.unwrap();
let update = Updates::RoomTopicChanged { let update = Updates::RoomTopicChanged {
room_id: lock.room_id.clone(), room_id: lock.room_id.clone(),
new_topic: new_topic.clone(), new_topic: new_topic.clone(),