Split disable_room, ban_room functions

This commit is contained in:
dasha_uwu
2025-08-22 20:17:44 +05:00
parent a4f589f475
commit 4884c55be7
3 changed files with 20 additions and 34 deletions

View File

@@ -6,17 +6,13 @@ use crate::{admin_command, get_room_info};
#[admin_command]
pub(super) async fn disable_room(&self, room_id: OwnedRoomId) -> Result {
self.services
.metadata
.disable_room(&room_id, true);
self.services.metadata.disable_room(&room_id);
self.write_str("Room disabled.").await
}
#[admin_command]
pub(super) async fn enable_room(&self, room_id: OwnedRoomId) -> Result {
self.services
.metadata
.disable_room(&room_id, false);
self.services.metadata.enable_room(&room_id);
self.write_str("Room enabled.").await
}

View File

@@ -70,7 +70,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
};
debug!("Room specified is a room ID, banning room ID");
self.services.metadata.ban_room(room_id, true);
self.services.metadata.ban_room(room_id);
room_id.to_owned()
} else if room.is_room_alias_id() {
@@ -126,7 +126,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
},
};
self.services.metadata.ban_room(&room_id, true);
self.services.metadata.ban_room(&room_id);
room_id
} else {
@@ -180,9 +180,7 @@ async fn ban_room(&self, room: OwnedRoomOrAliasId) -> Result {
// unpublish from room directory
self.services.directory.set_not_public(&room_id);
self.services
.metadata
.disable_room(&room_id, true);
self.services.metadata.disable_room(&room_id);
self.write_str(
"Room banned, removed all our local users, and disabled incoming federation with room.",
@@ -302,7 +300,7 @@ async fn ban_list_of_rooms(&self) -> Result {
}
for room_id in room_ids {
self.services.metadata.ban_room(&room_id, true);
self.services.metadata.ban_room(&room_id);
debug!("Banned {room_id} successfully");
room_ban_count = room_ban_count.saturating_add(1);
@@ -351,9 +349,7 @@ async fn ban_list_of_rooms(&self) -> Result {
// unpublish from room directory, ignore errors
self.services.directory.set_not_public(&room_id);
self.services
.metadata
.disable_room(&room_id, true);
self.services.metadata.disable_room(&room_id);
}
self.write_str(&format!(
@@ -378,7 +374,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
};
debug!("Room specified is a room ID, unbanning room ID");
self.services.metadata.ban_room(room_id, false);
self.services.metadata.unban_room(room_id);
room_id.to_owned()
} else if room.is_room_alias_id() {
@@ -432,7 +428,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
},
};
self.services.metadata.ban_room(&room_id, false);
self.services.metadata.unban_room(&room_id);
room_id
} else {
@@ -443,9 +439,7 @@ async fn unban_room(&self, room: OwnedRoomOrAliasId) -> Result {
);
};
self.services
.metadata
.disable_room(&room_id, false);
self.services.metadata.enable_room(&room_id);
self.write_str("Room unbanned and federation re-enabled.")
.await
}

View File

@@ -94,23 +94,19 @@ pub async fn is_public(&self, room_id: &RoomId) -> bool {
#[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);
}
}
pub fn disable_room(&self, room_id: &RoomId) { self.db.disabledroomids.insert(room_id, []); }
#[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);
}
}
pub fn enable_room(&self, room_id: &RoomId) { self.db.disabledroomids.remove(room_id); }
#[implement(Service)]
#[inline]
pub fn ban_room(&self, room_id: &RoomId) { self.db.bannedroomids.insert(room_id, []); }
#[implement(Service)]
#[inline]
pub fn unban_room(&self, room_id: &RoomId) { self.db.bannedroomids.remove(room_id); }
#[implement(Service)]
pub fn list_banned_rooms(&self) -> impl Stream<Item = &RoomId> + Send + '_ {