2022-06-25 16:12:23 +02:00
|
|
|
mod data;
|
2022-10-08 13:04:55 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2024-06-28 22:51:39 +00:00
|
|
|
use conduit::{Result, Server};
|
2024-05-26 21:29:19 +00:00
|
|
|
use data::Data;
|
2024-06-28 22:51:39 +00:00
|
|
|
use database::Database;
|
2022-10-09 17:25:06 +02:00
|
|
|
use ruma::{OwnedRoomId, RoomId};
|
2020-05-03 17:25:31 +02:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub struct Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
db: Data,
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|
2021-08-12 23:04:00 +02:00
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
impl Service {
|
2024-06-28 22:51:39 +00:00
|
|
|
pub fn build(_server: &Arc<Server>, db: &Arc<Database>) -> Result<Self> {
|
2024-05-27 03:17:20 +00:00
|
|
|
Ok(Self {
|
|
|
|
|
db: Data::new(db),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-25 16:12:23 +02:00
|
|
|
/// Checks if a room exists.
|
|
|
|
|
#[tracing::instrument(skip(self))]
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn exists(&self, room_id: &RoomId) -> Result<bool> { self.db.exists(room_id) }
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
#[must_use]
|
|
|
|
|
pub fn iter_ids<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> { self.db.iter_ids() }
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn is_disabled(&self, room_id: &RoomId) -> Result<bool> { self.db.is_disabled(room_id) }
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn disable_room(&self, room_id: &RoomId, disabled: bool) -> Result<()> {
|
2022-10-05 18:36:12 +02:00
|
|
|
self.db.disable_room(room_id, disabled)
|
|
|
|
|
}
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn is_banned(&self, room_id: &RoomId) -> Result<bool> { self.db.is_banned(room_id) }
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
pub fn ban_room(&self, room_id: &RoomId, banned: bool) -> Result<()> { self.db.ban_room(room_id, banned) }
|
2024-03-05 19:48:54 -05:00
|
|
|
|
2024-05-09 15:59:08 -07:00
|
|
|
#[must_use]
|
|
|
|
|
pub fn list_banned_rooms<'a>(&'a self) -> Box<dyn Iterator<Item = Result<OwnedRoomId>> + 'a> {
|
2024-02-18 18:57:17 -05:00
|
|
|
self.db.list_banned_rooms()
|
|
|
|
|
}
|
2022-06-25 16:12:23 +02:00
|
|
|
}
|