mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-13 20:26:52 +00:00
style: Document & refactor rooms/directory service
This commit is contained in:
1 file changed
+22
-19
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use conduwuit::{Result, implement, utils::stream::TryIgnore};
|
||||
use conduwuit::{Result, utils::stream::TryIgnore};
|
||||
use database::Map;
|
||||
use futures::Stream;
|
||||
use ruma::{OwnedRoomId, RoomId, api::client::room::Visibility};
|
||||
@@ -25,27 +25,30 @@ impl crate::Service for Service {
|
||||
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
pub fn set_public(&self, room_id: &RoomId) { self.db.publicroomids.insert(room_id, []); }
|
||||
impl Service {
|
||||
/// Marks a room as public, adding it to the room directory. Has no relation
|
||||
/// to the join rule.
|
||||
pub fn set_public(&self, room_id: &RoomId) { self.db.publicroomids.insert(room_id, []); }
|
||||
|
||||
#[implement(Service)]
|
||||
pub fn set_not_public(&self, room_id: &RoomId) { self.db.publicroomids.remove(room_id); }
|
||||
/// Removes a room from the public room directory.
|
||||
pub fn set_not_public(&self, room_id: &RoomId) { self.db.publicroomids.remove(room_id); }
|
||||
|
||||
#[implement(Service)]
|
||||
pub fn public_rooms(&self) -> impl Stream<Item = OwnedRoomId> + Send {
|
||||
self.db.publicroomids.keys().ignore_err()
|
||||
}
|
||||
/// Lists all public rooms in the directory.
|
||||
pub fn public_rooms(&self) -> impl Stream<Item = OwnedRoomId> + Send {
|
||||
self.db.publicroomids.keys().ignore_err()
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
pub async fn is_public_room(&self, room_id: &RoomId) -> bool {
|
||||
self.visibility(room_id).await == Visibility::Public
|
||||
}
|
||||
/// Checks if a room is public (per visibility, not join rule).
|
||||
pub async fn is_public_room(&self, room_id: &RoomId) -> bool {
|
||||
self.visibility(room_id).await == Visibility::Public
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
pub async fn visibility(&self, room_id: &RoomId) -> Visibility {
|
||||
if self.db.publicroomids.get(room_id).await.is_ok() {
|
||||
Visibility::Public
|
||||
} else {
|
||||
Visibility::Private
|
||||
/// Fetches the visibility of a specific room ID.
|
||||
pub async fn visibility(&self, room_id: &RoomId) -> Visibility {
|
||||
if self.db.publicroomids.get(room_id).await.is_ok() {
|
||||
Visibility::Public
|
||||
} else {
|
||||
Visibility::Private
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user