mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-06-27 16:35:59 +00:00
chore: Remove the Service::send_message
function
- Remove `Service::send_message` function and rename `Service::send_message_with_result` to `Service::send_message` - Log the `Service::send_message` error - Remove `AdminRoomEvent::SendMessage` variant Based-on: e09e55dba31523007b51521a1ab6552099a0118f Suggested-by: Timo Kösters <timo@koesters.xyz> Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
3e4d85fcee
commit
a8f57f0621
4 changed files with 39 additions and 34 deletions
|
@ -249,11 +249,15 @@ pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<registe
|
|||
|
||||
info!("New user {} registered on this server.", user_id);
|
||||
if !body.from_appservice && !is_guest {
|
||||
services()
|
||||
if let Err(err) = services()
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
.send_message(&RoomMessageEventContent::notice_plain(format!(
|
||||
"New user {user_id} registered on this server."
|
||||
)));
|
||||
)))
|
||||
.await
|
||||
{
|
||||
tracing::error!("Failed to send a message to admin room: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
// If this is the first real user, grant them admin privileges
|
||||
|
@ -351,11 +355,15 @@ pub async fn change_password_route(
|
|||
}
|
||||
|
||||
info!("User {} changed their password.", sender_user);
|
||||
services()
|
||||
if let Err(err) = services()
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
.send_message(&RoomMessageEventContent::notice_plain(format!(
|
||||
"User {sender_user} changed their password."
|
||||
)));
|
||||
)))
|
||||
.await
|
||||
{
|
||||
tracing::error!("Failed to send a message to admin room: {err}");
|
||||
}
|
||||
|
||||
Ok(change_password::v3::Response {})
|
||||
}
|
||||
|
@ -428,11 +436,15 @@ pub async fn deactivate_route(
|
|||
services().users.deactivate_account(sender_user)?;
|
||||
|
||||
info!("User {} deactivated their account.", sender_user);
|
||||
services()
|
||||
if let Err(err) = services()
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
||||
.send_message(&RoomMessageEventContent::notice_plain(format!(
|
||||
"User {sender_user} deactivated their account."
|
||||
)));
|
||||
)))
|
||||
.await
|
||||
{
|
||||
tracing::error!("Failed to send a message to admin room: {err}");
|
||||
}
|
||||
|
||||
Ok(deactivate::v3::Response {
|
||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
||||
|
|
|
@ -38,8 +38,8 @@ pub async fn report_event_route(
|
|||
));
|
||||
};
|
||||
|
||||
services().admin
|
||||
.send_message(message::RoomMessageEventContent::text_html(
|
||||
if let Err(err) = services().admin
|
||||
.send_message(&message::RoomMessageEventContent::text_html(
|
||||
format!(
|
||||
"Report received from: {}\n\n\
|
||||
Event ID: {:?}\n\
|
||||
|
@ -63,7 +63,9 @@ pub async fn report_event_route(
|
|||
body.score,
|
||||
HtmlEscape(body.reason.as_deref().unwrap_or(""))
|
||||
),
|
||||
));
|
||||
)).await {
|
||||
tracing::error!("Failed to send a message to admin room: {err}");
|
||||
}
|
||||
|
||||
Ok(report_content::v3::Response {})
|
||||
}
|
||||
|
|
|
@ -972,7 +972,11 @@ impl KeyValueDatabase {
|
|||
Ok(pwd_set) => {
|
||||
if pwd_set {
|
||||
warn!("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!");
|
||||
services().admin.send_message(RoomMessageEventContent::text_plain("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!"));
|
||||
if let Err(err) = services().admin.send_message(
|
||||
&RoomMessageEventContent::text_plain("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!")
|
||||
).await {
|
||||
tracing::error!("Failed to send a message to admin room: {err}");
|
||||
};
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
|
@ -1043,12 +1047,14 @@ impl KeyValueDatabase {
|
|||
last_update_id = last_update_id.max(update.id);
|
||||
if update.id > services().globals.last_check_for_updates_id()? {
|
||||
println!("{}", update.message);
|
||||
services()
|
||||
if let Err(err) = services()
|
||||
.admin
|
||||
.send_message(RoomMessageEventContent::text_plain(format!(
|
||||
.send_message(&RoomMessageEventContent::text_plain(format!(
|
||||
"@room: The following is a message from the Conduit developers. It was sent on '{}':\n\n{}",
|
||||
update.date, update.message
|
||||
)))
|
||||
))).await {
|
||||
tracing::error!("Failed to send a message to admin room: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
services()
|
||||
|
|
|
@ -184,7 +184,6 @@ enum AdminCommand {
|
|||
#[derive(Debug)]
|
||||
pub enum AdminRoomEvent {
|
||||
ProcessMessage(String, ruma::OwnedEventId),
|
||||
SendMessage(RoomMessageEventContent),
|
||||
}
|
||||
|
||||
pub struct Service {
|
||||
|
@ -221,7 +220,6 @@ impl Service {
|
|||
tokio::select! {
|
||||
Some(event) = receiver.recv() => {
|
||||
let message_content = match event {
|
||||
AdminRoomEvent::SendMessage(content) => Some(content),
|
||||
AdminRoomEvent::ProcessMessage(room_message, event_id) => self.process_admin_message(room_message, &event_id).await
|
||||
};
|
||||
if let Some(message_content) = message_content {
|
||||
|
@ -269,12 +267,6 @@ impl Service {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn send_message(&self, message_content: RoomMessageEventContent) {
|
||||
self.sender
|
||||
.send(AdminRoomEvent::SendMessage(message_content))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// Delete user message in the conduit admin room.
|
||||
pub async fn delete_user_message(
|
||||
&self,
|
||||
|
@ -322,15 +314,8 @@ impl Service {
|
|||
|
||||
/// Send the message content and return it's result
|
||||
///
|
||||
/// Note: This is different from send_message, as it sends the message
|
||||
/// and returns the sending result, unlike [`send_message`], which will send
|
||||
/// the message via [`handler`] and ignore the sending result.
|
||||
///
|
||||
/// Note: Will return Ok(None) if there is no admin room
|
||||
///
|
||||
/// [`send_message`]: Self::send_message()
|
||||
/// [`handler`]: Self::handler()
|
||||
pub async fn send_message_with_result(
|
||||
pub async fn send_message(
|
||||
&self,
|
||||
message_content: &RoomMessageEventContent,
|
||||
) -> Result<Option<Arc<EventId>>> {
|
||||
|
@ -715,7 +700,7 @@ impl Service {
|
|||
// need it's event id to delete it after 60s
|
||||
let Some(sended_message_event_id) = services()
|
||||
.admin
|
||||
.send_message_with_result(&RoomMessageEventContent::text_plain(format!(
|
||||
.send_message(&RoomMessageEventContent::text_plain(format!(
|
||||
"Successfully reset the password for user {user_id}: {new_password} (This message will be deleted after 60s)"
|
||||
)))
|
||||
.await?
|
||||
|
@ -816,7 +801,7 @@ impl Service {
|
|||
// need it's event id to delete it after 60s
|
||||
let Some(sended_message_event_id) = services()
|
||||
.admin
|
||||
.send_message_with_result(&RoomMessageEventContent::text_plain(format!(
|
||||
.send_message(&RoomMessageEventContent::text_plain(format!(
|
||||
"Created user with user_id: {user_id} and password: {password} (This message will be deleted after 60s)"
|
||||
)))
|
||||
.await?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue