forked from lavina/lavina
core: use members instead of subscribers in RoomInfo
This commit is contained in:
parent
e48a6d3b0b
commit
d0420ec834
|
@ -2,6 +2,7 @@ use anyhow::{anyhow, Result};
|
|||
use chrono::{DateTime, Utc};
|
||||
use sqlx::FromRow;
|
||||
|
||||
use crate::player::PlayerId;
|
||||
use crate::repo::Storage;
|
||||
use crate::room::{RoomId, StoredMessage};
|
||||
|
||||
|
@ -212,4 +213,18 @@ impl Storage {
|
|||
|
||||
res.into_iter().map(|(room_id,)| RoomId::try_from(room_id)).collect()
|
||||
}
|
||||
|
||||
pub async fn get_users_of_a_room(&self, room_id: u32) -> Result<Vec<PlayerId>> {
|
||||
let mut executor = self.conn.lock().await;
|
||||
let res: Vec<(String,)> = sqlx::query_as(
|
||||
"select u.name
|
||||
from memberships m inner join users u on m.user_id = u.id
|
||||
where m.room_id = ?;",
|
||||
)
|
||||
.bind(room_id)
|
||||
.fetch_all(&mut *executor)
|
||||
.await?;
|
||||
|
||||
Ok(res.into_iter()).and_then(|iter| iter.map(|(user_id,)| PlayerId::from(user_id)).collect())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,11 +112,12 @@ impl RoomRegistryInner {
|
|||
Ok(Some(room_handle.clone()))
|
||||
} else if let Some(stored_room) = services.storage.retrieve_room_by_name(&*room_id.0).await? {
|
||||
log::debug!("Loading room {}...", &room_id.0);
|
||||
let users = services.storage.get_users_of_a_room(stored_room.id).await?;
|
||||
let room = Room {
|
||||
storage_id: stored_room.id,
|
||||
room_id: room_id.clone(),
|
||||
subscriptions: HashMap::new(),
|
||||
members: HashSet::new(), // TODO load members from storage
|
||||
members: HashSet::from_iter(users.into_iter()),
|
||||
topic: stored_room.topic.into(),
|
||||
message_count: stored_room.message_count,
|
||||
};
|
||||
|
@ -198,7 +199,7 @@ impl RoomHandle {
|
|||
let lock = self.0.read().await;
|
||||
RoomInfo {
|
||||
id: lock.room_id.clone(),
|
||||
members: lock.subscriptions.keys().map(|x| x.clone()).collect::<Vec<_>>(),
|
||||
members: lock.members.iter().map(|x| x.clone()).collect::<Vec<_>>(),
|
||||
topic: lock.topic.clone(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue