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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
1009 B
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};
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;
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)]
2024-10-02 09:26:28 -04:00
pub fn public_rooms(&self) -> impl Stream<Item = &RoomId> + Send { self.db.publicroomids.keys().ignore_err() }