persistent room topics (#50)

Reviewed-on: lavina/lavina#50
This commit is contained in:
Nikita Vilunov 2024-04-15 09:12:23 +00:00
parent 0105a5b710
commit 757d7c5665
2 changed files with 17 additions and 0 deletions

View File

@ -30,4 +30,19 @@ impl Storage {
Ok(()) 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(())
}
} }

View File

@ -182,7 +182,9 @@ impl RoomHandle {
pub async fn set_topic(&self, changer_id: &PlayerId, new_topic: Str) { pub async fn set_topic(&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(),