remove unnecessary displayname requirement on making user admin

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-09-09 21:10:56 -04:00
parent 55f71d3912
commit 9de780b56c
3 changed files with 4 additions and 15 deletions

View File

@ -373,20 +373,12 @@ pub(super) async fn force_leave_room(
#[admin_command] #[admin_command]
pub(super) async fn make_user_admin(&self, user_id: String) -> Result<RoomMessageEventContent> { pub(super) async fn make_user_admin(&self, user_id: String) -> Result<RoomMessageEventContent> {
let user_id = parse_local_user_id(self.services, &user_id)?; let user_id = parse_local_user_id(self.services, &user_id)?;
let displayname = self
.services
.users
.displayname(&user_id)?
.unwrap_or_else(|| user_id.to_string());
assert!( assert!(
self.services.globals.user_is_local(&user_id), self.services.globals.user_is_local(&user_id),
"Parsed user_id must be a local user" "Parsed user_id must be a local user"
); );
self.services self.services.admin.make_user_admin(&user_id).await?;
.admin
.make_user_admin(&user_id, displayname)
.await?;
Ok(RoomMessageEventContent::notice_markdown(format!( Ok(RoomMessageEventContent::notice_markdown(format!(
"{user_id} has been granted admin privileges.", "{user_id} has been granted admin privileges.",

View File

@ -347,10 +347,7 @@ pub(crate) async fn register_route(
if !is_guest { if !is_guest {
if let Some(admin_room) = services.admin.get_admin_room()? { if let Some(admin_room) = services.admin.get_admin_room()? {
if services.rooms.state_cache.room_joined_count(&admin_room)? == Some(1) { if services.rooms.state_cache.room_joined_count(&admin_room)? == Some(1) {
services services.admin.make_user_admin(&user_id).await?;
.admin
.make_user_admin(&user_id, displayname)
.await?;
warn!("Granting {user_id} admin privileges as the first user"); warn!("Granting {user_id} admin privileges as the first user");
} }

View File

@ -21,7 +21,7 @@ impl super::Service {
/// Invite the user to the conduit admin room. /// Invite the user to the conduit admin room.
/// ///
/// In conduit, this is equivalent to granting admin privileges. /// In conduit, this is equivalent to granting admin privileges.
pub async fn make_user_admin(&self, user_id: &UserId, displayname: String) -> Result<()> { pub async fn make_user_admin(&self, user_id: &UserId) -> Result<()> {
let Some(room_id) = self.get_admin_room()? else { let Some(room_id) = self.get_admin_room()? else {
return Ok(()); return Ok(());
}; };
@ -65,7 +65,7 @@ impl super::Service {
event_type: TimelineEventType::RoomMember, event_type: TimelineEventType::RoomMember,
content: to_raw_value(&RoomMemberEventContent { content: to_raw_value(&RoomMemberEventContent {
membership: MembershipState::Join, membership: MembershipState::Join,
displayname: Some(displayname), displayname: None,
avatar_url: None, avatar_url: None,
is_direct: None, is_direct: None,
third_party_invite: None, third_party_invite: None,