forked from lavina/lavina
				
			persist topics of rooms on change
This commit is contained in:
		
							parent
							
								
									0944c449ca
								
							
						
					
					
						commit
						18a4a3f187
					
				| 
						 | 
				
			
			@ -11,6 +11,8 @@ use tokio::sync::Mutex;
 | 
			
		|||
 | 
			
		||||
use crate::prelude::*;
 | 
			
		||||
 | 
			
		||||
mod room;
 | 
			
		||||
 | 
			
		||||
#[derive(Deserialize, Debug, Clone)]
 | 
			
		||||
pub struct StorageConfig {
 | 
			
		||||
    pub db_path: String,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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(())
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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(),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue