mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-28 05:45:48 +00:00
refactor: restore src/service/rooms/directory/mod.rs
This commit is contained in:
parent
9e1ab74bb4
commit
0071a9cbf4
29
src/service/rooms/directory/mod.rs
Normal file
29
src/service/rooms/directory/mod.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn set_public(&self, room_id: &RoomId, public: bool) -> Result<()> {
|
||||
if public {
|
||||
self.publicroomids.insert(room_id.as_bytes(), &[])?;
|
||||
} else {
|
||||
self.publicroomids.remove(room_id.as_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn is_public_room(&self, room_id: &RoomId) -> Result<bool> {
|
||||
Ok(self.publicroomids.get(room_id.as_bytes())?.is_some())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn public_rooms(&self) -> impl Iterator<Item = Result<Box<RoomId>>> + '_ {
|
||||
self.publicroomids.iter().map(|(bytes, _)| {
|
||||
RoomId::parse(
|
||||
utils::string_from_bytes(&bytes).map_err(|_| {
|
||||
Error::bad_database("Room ID in publicroomids is invalid unicode.")
|
||||
})?,
|
||||
)
|
||||
.map_err(|_| Error::bad_database("Room ID in publicroomids is invalid."))
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in a new issue