refactor server_name check

This commit is contained in:
Charles Hall 2024-09-27 17:31:18 -07:00
parent 12f2f89f81
commit 43018e5793
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -317,21 +317,20 @@ 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()
.map_err(Error::NonZeroUsers)?;
let admin_bot_exists = services()
.users
.exists(admin_bot)
.map_err(Error::AdminBotExists)?
{
.exists(&self.admin_bot_user_id)
.map_err(Error::AdminBotExists)?;
if non_zero_users && !admin_bot_exists {
return Err(Error::Renamed);
}
}
Ok(())
}