diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 8e0325c73..cd866a474 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -16,13 +16,11 @@ use conduwuit::{ use futures::{FutureExt, StreamExt}; use lettre::Address; use ruma::{ - OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, UserId, + OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, ServerName, + UserId, assign, events::{ - RoomAccountDataEventType, StateEventType, - room::{ - power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent}, - redaction::RoomRedactionEventContent, - }, + RoomAccountDataEventType, + room::{power_levels::RoomPowerLevelsEventContent, redaction::RoomRedactionEventContent}, tag::{TagEvent, TagEventContent, TagInfo}, }, }; @@ -41,7 +39,7 @@ pub(super) async fn list_users(&self) -> Result { .services .users .list_local_users() - .map(ToString::to_string) + .map(|id| id.as_str().to_owned()) .collect() .await; @@ -103,11 +101,12 @@ pub(super) async fn create_user(&self, username: String, password: Option Result { .rooms .state_cache .rooms_joined(&user_id) - .then(|room_id| get_room_info(self.services, room_id)) + .then(async |room_id| get_room_info(self.services, &room_id).await) .collect() .await; @@ -633,7 +637,6 @@ pub(super) async fn force_join_all_local_users( .services .users .list_local_users() - .map(UserId::to_owned) .collect::>() .await { @@ -730,7 +733,7 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli "Parsed user_id must be a local user" ); - let state_lock = self.services.rooms.state.mutex.lock(&room_id).await; + let state_lock = self.services.rooms.state.mutex.lock(room_id.as_str()).await; let mut room_power_levels = self .services @@ -755,8 +758,7 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli .build_and_append_pdu( PartialPdu::state( String::new(), - room_power_levels - .try_into() + &RoomPowerLevelsEventContent::try_from(room_power_levels) .expect("PLs should be valid for room version"), ), &user_id, @@ -804,9 +806,7 @@ pub(super) async fn put_room_tag( .account_data .get_room(&room_id, &user_id, RoomAccountDataEventType::Tag) .await - .unwrap_or(TagEvent { - content: TagEventContent { tags: BTreeMap::new() }, - }); + .unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new()))); tags_event .content @@ -843,9 +843,7 @@ pub(super) async fn delete_room_tag( .account_data .get_room(&room_id, &user_id, RoomAccountDataEventType::Tag) .await - .unwrap_or(TagEvent { - content: TagEventContent { tags: BTreeMap::new() }, - }); + .unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new()))); tags_event.content.tags.remove(&tag.clone().into()); @@ -875,9 +873,7 @@ pub(super) async fn get_room_tags(&self, user_id: String, room_id: OwnedRoomId) .account_data .get_room(&room_id, &user_id, RoomAccountDataEventType::Tag) .await - .unwrap_or(TagEvent { - content: TagEventContent { tags: BTreeMap::new() }, - }); + .unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new()))); self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags)) .await @@ -914,7 +910,7 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result { .rooms .state .mutex - .lock(&event.room_id_or_hash()) + .lock(event.room_id_or_hash().as_str()) .await; self.services @@ -923,10 +919,10 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result { .build_and_append_pdu( PartialPdu { redacts: Some(event.event_id().to_owned()), - ..PartialPdu::timeline(&RoomRedactionEventContent { + ..PartialPdu::timeline(&assign!(RoomRedactionEventContent::new_v1(), { redacts: Some(event.event_id().to_owned()), reason: Some(reason), - }) + })) }, event.sender(), Some(&event.room_id_or_hash()), @@ -956,7 +952,7 @@ pub(super) async fn force_leave_remote_room( .resolve_with_servers( &room_id, if let Some(v) = via.clone() { - Some(vec![OwnedServerName::parse(v)?]) + Some(vec![ServerName::parse(v)?]) } else { None }, @@ -969,7 +965,7 @@ pub(super) async fn force_leave_remote_room( ); let mut vias: HashSet = HashSet::new(); if let Some(via) = via { - vias.insert(OwnedServerName::parse(via)?); + vias.insert(ServerName::parse(via)?); } for server in vias_raw { vias.insert(server); @@ -1044,7 +1040,12 @@ pub(super) async fn logout(&self, user_id: String) -> Result { self.services .users .all_device_ids(&user_id) - .for_each(|device_id| self.services.users.remove_device(&user_id, device_id)) + .for_each(async |device_id| { + self.services + .users + .remove_device(&user_id, &device_id) + .await + }) .await; self.write_str(&format!("User {user_id} has been logged out from all devices.")) .await @@ -1122,11 +1123,9 @@ pub(super) async fn get_user_by_email(&self, email: String) -> Result { match self.services.threepid.get_localpart_for_email(&email).await { | Some(localpart) => { - let user_id = OwnedUserId::parse(format!( - "@{localpart}:{}", - self.services.globals.server_name() - )) - .unwrap(); + let user_id = + UserId::parse(format!("@{localpart}:{}", self.services.globals.server_name())) + .unwrap(); self.write_str(&format!("{email} belongs to {user_id}.")) .await