From 43018e579327c8d2df9b0f0e94a5f8ff68d4a7c3 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Fri, 27 Sep 2024 17:31:18 -0700 Subject: [PATCH] refactor server_name check --- src/service/globals.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/service/globals.rs b/src/service/globals.rs index a1662c9e..1189bb13 100644 --- a/src/service/globals.rs +++ b/src/service/globals.rs @@ -317,20 +317,19 @@ impl Service { ) -> Result<(), crate::error::ServerNameChanged> { use crate::error::ServerNameChanged as Error; - if services() + let non_zero_users = services() .users .count() .map(|x| x > 0) - .map_err(Error::NonZeroUsers)? - { - let admin_bot = self.admin_bot_user_id.as_ref(); - if !services() - .users - .exists(admin_bot) - .map_err(Error::AdminBotExists)? - { - return Err(Error::Renamed); - } + .map_err(Error::NonZeroUsers)?; + + let admin_bot_exists = services() + .users + .exists(&self.admin_bot_user_id) + .map_err(Error::AdminBotExists)?; + + if non_zero_users && !admin_bot_exists { + return Err(Error::Renamed); } Ok(())