2024-05-09 15:59:08 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
use conduit::{implement, utils::stream::TryIgnore, Result};
|
2024-10-02 09:26:28 -04:00
|
|
|
use database::Map;
|
|
|
|
|
use futures::Stream;
|
2024-08-08 17:18:30 +00:00
|
|
|
use ruma::RoomId;
|
2022-06-25 16:12:23 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-05-27 03:17:20 +00:00
|
|
|
db: Data,
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
struct Data {
|
|
|
|
|
publicroomids: Arc<Map>,
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 03:26:19 +00:00
|
|
|
impl crate::Service for Service {
|
|
|
|
|
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
|
|
|
|
|
Ok(Arc::new(Self {
|
2024-08-08 17:18:30 +00:00
|
|
|
db: Data {
|
|
|
|
|
publicroomids: args.db["publicroomids"].clone(),
|
|
|
|
|
},
|
2024-07-04 03:26:19 +00:00
|
|
|
}))
|
2024-05-27 03:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2024-07-04 03:26:19 +00:00
|
|
|
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[implement(Service)]
|
2024-10-07 17:54:27 +00:00
|
|
|
pub fn set_public(&self, room_id: &RoomId) { self.db.publicroomids.insert(room_id, []); }
|
2020-05-24 08:30:57 +02:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[implement(Service)]
|
2024-10-07 17:54:27 +00:00
|
|
|
pub fn set_not_public(&self, room_id: &RoomId) { self.db.publicroomids.remove(room_id); }
|
2020-05-25 23:24:13 +02:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[implement(Service)]
|
2024-09-29 13:13:09 +00:00
|
|
|
pub async fn is_public_room(&self, room_id: &RoomId) -> bool { self.db.publicroomids.get(room_id).await.is_ok() }
|
2020-05-25 23:24:13 +02:00
|
|
|
|
2024-08-08 17:18:30 +00:00
|
|
|
#[implement(Service)]
|
2024-10-02 09:26:28 -04:00
|
|
|
pub fn public_rooms(&self) -> impl Stream<Item = &RoomId> + Send { self.db.publicroomids.keys().ignore_err() }
|