Files
continuwuity/src/service/rooms/directory/mod.rs
T

44 lines
1.1 KiB
Rust
Raw Normal View History

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};
use database::{Ignore, Map};
use futures::{Stream, StreamExt};
use ruma::RoomId;
2024-05-09 15:59:08 -07:00
pub struct Service {
2024-05-27 03:17:20 +00:00
db: Data,
}
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)]
pub fn set_public(&self, room_id: &RoomId) { self.db.publicroomids.insert(room_id.as_bytes(), &[]); }
2020-05-25 23:24:13 +02:00
2024-08-08 17:18:30 +00:00
#[implement(Service)]
pub fn set_not_public(&self, room_id: &RoomId) { self.db.publicroomids.remove(room_id.as_bytes()); }
2020-05-25 23:24:13 +02:00
2024-08-08 17:18:30 +00:00
#[implement(Service)]
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)]
pub fn public_rooms(&self) -> impl Stream<Item = &RoomId> + Send {
self.db
.publicroomids
.keys()
.ignore_err()
.map(|(room_id, _): (&RoomId, Ignore)| room_id)
}