mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
refactor: Fix errors in admin/user/
This commit is contained in:
+37
-38
@@ -16,13 +16,11 @@ use conduwuit::{
|
|||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
use lettre::Address;
|
use lettre::Address;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, UserId,
|
OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName, OwnedUserId, ServerName,
|
||||||
|
UserId, assign,
|
||||||
events::{
|
events::{
|
||||||
RoomAccountDataEventType, StateEventType,
|
RoomAccountDataEventType,
|
||||||
room::{
|
room::{power_levels::RoomPowerLevelsEventContent, redaction::RoomRedactionEventContent},
|
||||||
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
|
|
||||||
redaction::RoomRedactionEventContent,
|
|
||||||
},
|
|
||||||
tag::{TagEvent, TagEventContent, TagInfo},
|
tag::{TagEvent, TagEventContent, TagInfo},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -41,7 +39,7 @@ pub(super) async fn list_users(&self) -> Result {
|
|||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
.list_local_users()
|
.list_local_users()
|
||||||
.map(ToString::to_string)
|
.map(|id| id.as_str().to_owned())
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -103,11 +101,12 @@ pub(super) async fn create_user(&self, username: String, password: Option<String
|
|||||||
ruma::events::GlobalAccountDataEventType::PushRules
|
ruma::events::GlobalAccountDataEventType::PushRules
|
||||||
.to_string()
|
.to_string()
|
||||||
.into(),
|
.into(),
|
||||||
&serde_json::to_value(ruma::events::push_rules::PushRulesEvent {
|
&serde_json::to_value(ruma::events::push_rules::PushRulesEvent::new(
|
||||||
content: ruma::events::push_rules::PushRulesEventContent {
|
ruma::events::push_rules::PushRulesEventContent::new(
|
||||||
global: ruma::push::Ruleset::server_default(&user_id),
|
ruma::push::Ruleset::server_default(&user_id),
|
||||||
},
|
),
|
||||||
})?,
|
))
|
||||||
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -292,7 +291,12 @@ pub(super) async fn reset_password(
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.all_device_ids(&user_id)
|
.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;
|
.await;
|
||||||
write!(self, "\nAll existing sessions have been logged out.").await?;
|
write!(self, "\nAll existing sessions have been logged out.").await?;
|
||||||
}
|
}
|
||||||
@@ -437,7 +441,7 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.rooms_joined(&user_id)
|
.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()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -633,7 +637,6 @@ pub(super) async fn force_join_all_local_users(
|
|||||||
.services
|
.services
|
||||||
.users
|
.users
|
||||||
.list_local_users()
|
.list_local_users()
|
||||||
.map(UserId::to_owned)
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await
|
.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"
|
"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
|
let mut room_power_levels = self
|
||||||
.services
|
.services
|
||||||
@@ -755,8 +758,7 @@ pub(super) async fn force_demote(&self, user_id: String, room_id: OwnedRoomOrAli
|
|||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu::state(
|
PartialPdu::state(
|
||||||
String::new(),
|
String::new(),
|
||||||
room_power_levels
|
&RoomPowerLevelsEventContent::try_from(room_power_levels)
|
||||||
.try_into()
|
|
||||||
.expect("PLs should be valid for room version"),
|
.expect("PLs should be valid for room version"),
|
||||||
),
|
),
|
||||||
&user_id,
|
&user_id,
|
||||||
@@ -804,9 +806,7 @@ pub(super) async fn put_room_tag(
|
|||||||
.account_data
|
.account_data
|
||||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(TagEvent {
|
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||||
content: TagEventContent { tags: BTreeMap::new() },
|
|
||||||
});
|
|
||||||
|
|
||||||
tags_event
|
tags_event
|
||||||
.content
|
.content
|
||||||
@@ -843,9 +843,7 @@ pub(super) async fn delete_room_tag(
|
|||||||
.account_data
|
.account_data
|
||||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(TagEvent {
|
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||||
content: TagEventContent { tags: BTreeMap::new() },
|
|
||||||
});
|
|
||||||
|
|
||||||
tags_event.content.tags.remove(&tag.clone().into());
|
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
|
.account_data
|
||||||
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
.get_room(&room_id, &user_id, RoomAccountDataEventType::Tag)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(TagEvent {
|
.unwrap_or(TagEvent::new(TagEventContent::new(BTreeMap::new())));
|
||||||
content: TagEventContent { tags: BTreeMap::new() },
|
|
||||||
});
|
|
||||||
|
|
||||||
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
|
self.write_str(&format!("```\n{:#?}\n```", tags_event.content.tags))
|
||||||
.await
|
.await
|
||||||
@@ -914,7 +910,7 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
|
|||||||
.rooms
|
.rooms
|
||||||
.state
|
.state
|
||||||
.mutex
|
.mutex
|
||||||
.lock(&event.room_id_or_hash())
|
.lock(event.room_id_or_hash().as_str())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.services
|
self.services
|
||||||
@@ -923,10 +919,10 @@ pub(super) async fn redact_event(&self, event_id: OwnedEventId) -> Result {
|
|||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PartialPdu {
|
PartialPdu {
|
||||||
redacts: Some(event.event_id().to_owned()),
|
redacts: Some(event.event_id().to_owned()),
|
||||||
..PartialPdu::timeline(&RoomRedactionEventContent {
|
..PartialPdu::timeline(&assign!(RoomRedactionEventContent::new_v1(), {
|
||||||
redacts: Some(event.event_id().to_owned()),
|
redacts: Some(event.event_id().to_owned()),
|
||||||
reason: Some(reason),
|
reason: Some(reason),
|
||||||
})
|
}))
|
||||||
},
|
},
|
||||||
event.sender(),
|
event.sender(),
|
||||||
Some(&event.room_id_or_hash()),
|
Some(&event.room_id_or_hash()),
|
||||||
@@ -956,7 +952,7 @@ pub(super) async fn force_leave_remote_room(
|
|||||||
.resolve_with_servers(
|
.resolve_with_servers(
|
||||||
&room_id,
|
&room_id,
|
||||||
if let Some(v) = via.clone() {
|
if let Some(v) = via.clone() {
|
||||||
Some(vec![OwnedServerName::parse(v)?])
|
Some(vec![ServerName::parse(v)?])
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
@@ -969,7 +965,7 @@ pub(super) async fn force_leave_remote_room(
|
|||||||
);
|
);
|
||||||
let mut vias: HashSet<OwnedServerName> = HashSet::new();
|
let mut vias: HashSet<OwnedServerName> = HashSet::new();
|
||||||
if let Some(via) = via {
|
if let Some(via) = via {
|
||||||
vias.insert(OwnedServerName::parse(via)?);
|
vias.insert(ServerName::parse(via)?);
|
||||||
}
|
}
|
||||||
for server in vias_raw {
|
for server in vias_raw {
|
||||||
vias.insert(server);
|
vias.insert(server);
|
||||||
@@ -1044,7 +1040,12 @@ pub(super) async fn logout(&self, user_id: String) -> Result {
|
|||||||
self.services
|
self.services
|
||||||
.users
|
.users
|
||||||
.all_device_ids(&user_id)
|
.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;
|
.await;
|
||||||
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
self.write_str(&format!("User {user_id} has been logged out from all devices."))
|
||||||
.await
|
.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 {
|
match self.services.threepid.get_localpart_for_email(&email).await {
|
||||||
| Some(localpart) => {
|
| Some(localpart) => {
|
||||||
let user_id = OwnedUserId::parse(format!(
|
let user_id =
|
||||||
"@{localpart}:{}",
|
UserId::parse(format!("@{localpart}:{}", self.services.globals.server_name()))
|
||||||
self.services.globals.server_name()
|
.unwrap();
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
self.write_str(&format!("{email} belongs to {user_id}."))
|
self.write_str(&format!("{email} belongs to {user_id}."))
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user