mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-13 20:26:52 +00:00
style: Document & refactor rooms/metadata service
This commit is contained in:
1 file changed
+53
-52
@@ -41,60 +41,61 @@ impl crate::Service for Service {
|
||||
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
pub async fn exists(&self, room_id: &RoomId) -> bool {
|
||||
let Ok(prefix) = self.services.short.get_shortroomid(room_id).await else {
|
||||
return false;
|
||||
};
|
||||
impl Service {
|
||||
/// Checks if a room exists by checking if there are any PDUs in that room.
|
||||
/// If the short room ID is not found or there are no PDUs in the room, it
|
||||
/// does not exist.
|
||||
pub async fn exists(&self, room_id: &RoomId) -> bool {
|
||||
let Ok(prefix) = self.services.short.get_shortroomid(room_id).await else {
|
||||
return false;
|
||||
};
|
||||
|
||||
// Look for PDUs in that room.
|
||||
self.db
|
||||
.pduid_pdu
|
||||
.keys_prefix_raw(&prefix)
|
||||
.ignore_err()
|
||||
.next()
|
||||
.await
|
||||
.is_some()
|
||||
}
|
||||
// Look for PDUs in that room.
|
||||
self.db
|
||||
.pduid_pdu
|
||||
.keys_prefix_raw(&prefix)
|
||||
.ignore_err()
|
||||
.next()
|
||||
.await
|
||||
.is_some()
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
pub fn iter_ids(&self) -> impl Stream<Item = OwnedRoomId> + Send + '_ {
|
||||
self.db.roomid_shortroomid.keys().ignore_err()
|
||||
}
|
||||
/// Returns a stream of every room ID in the database.
|
||||
pub fn iter_ids(&self) -> impl Stream<Item = OwnedRoomId> + Send + '_ {
|
||||
self.db.roomid_shortroomid.keys().ignore_err()
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
#[inline]
|
||||
pub fn disable_room(&self, room_id: &RoomId, disabled: bool) {
|
||||
if disabled {
|
||||
self.db.disabledroomids.insert(room_id, []);
|
||||
} else {
|
||||
self.db.disabledroomids.remove(room_id);
|
||||
/// Disables a room, preventing it from engaging in federation, but still
|
||||
/// allowing it to be used locally.
|
||||
pub fn disable_room(&self, room_id: &RoomId, disabled: bool) {
|
||||
if disabled {
|
||||
self.db.disabledroomids.insert(room_id, []);
|
||||
} else {
|
||||
self.db.disabledroomids.remove(room_id);
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn is_disabled(&self, room_id: &RoomId) -> bool {
|
||||
self.db.disabledroomids.get(room_id).await.is_ok()
|
||||
}
|
||||
|
||||
/// Bans a room, ensuring it cannot be used neither locally nor over
|
||||
/// federation.
|
||||
pub fn ban_room(&self, room_id: &RoomId, banned: bool) {
|
||||
if banned {
|
||||
self.db.bannedroomids.insert(room_id, []);
|
||||
} else {
|
||||
self.db.bannedroomids.remove(room_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if a room is currently banned.
|
||||
pub async fn is_banned(&self, room_id: &RoomId) -> bool {
|
||||
self.db.bannedroomids.get(room_id).await.is_ok()
|
||||
}
|
||||
|
||||
/// Lists all rooms that are currently banned.
|
||||
pub fn list_banned_rooms(&self) -> impl Stream<Item = OwnedRoomId> + Send + '_ {
|
||||
self.db.bannedroomids.keys().ignore_err()
|
||||
}
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
#[inline]
|
||||
pub fn ban_room(&self, room_id: &RoomId, banned: bool) {
|
||||
if banned {
|
||||
self.db.bannedroomids.insert(room_id, []);
|
||||
} else {
|
||||
self.db.bannedroomids.remove(room_id);
|
||||
}
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
pub fn list_banned_rooms(&self) -> impl Stream<Item = OwnedRoomId> + Send + '_ {
|
||||
self.db.bannedroomids.keys().ignore_err()
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
#[inline]
|
||||
pub async fn is_disabled(&self, room_id: &RoomId) -> bool {
|
||||
self.db.disabledroomids.get(room_id).await.is_ok()
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
#[inline]
|
||||
pub async fn is_banned(&self, room_id: &RoomId) -> bool {
|
||||
self.db.bannedroomids.get(room_id).await.is_ok()
|
||||
}
|
||||
Reference in new issue
Block a user