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);
|
info!("New user {} registered on this server.", user_id);
|
||||||
if !body.from_appservice && !is_guest {
|
if !body.from_appservice && !is_guest {
|
||||||
services()
|
if let Err(err) = services()
|
||||||
.admin
|
.admin
|
||||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
.send_message(&RoomMessageEventContent::notice_plain(format!(
|
||||||
"New user {user_id} registered on this server."
|
"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
|
// 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);
|
info!("User {} changed their password.", sender_user);
|
||||||
services()
|
if let Err(err) = services()
|
||||||
.admin
|
.admin
|
||||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
.send_message(&RoomMessageEventContent::notice_plain(format!(
|
||||||
"User {sender_user} changed their password."
|
"User {sender_user} changed their password."
|
||||||
)));
|
)))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
tracing::error!("Failed to send a message to admin room: {err}");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(change_password::v3::Response {})
|
Ok(change_password::v3::Response {})
|
||||||
}
|
}
|
||||||
|
@ -428,11 +436,15 @@ pub async fn deactivate_route(
|
||||||
services().users.deactivate_account(sender_user)?;
|
services().users.deactivate_account(sender_user)?;
|
||||||
|
|
||||||
info!("User {} deactivated their account.", sender_user);
|
info!("User {} deactivated their account.", sender_user);
|
||||||
services()
|
if let Err(err) = services()
|
||||||
.admin
|
.admin
|
||||||
.send_message(RoomMessageEventContent::notice_plain(format!(
|
.send_message(&RoomMessageEventContent::notice_plain(format!(
|
||||||
"User {sender_user} deactivated their account."
|
"User {sender_user} deactivated their account."
|
||||||
)));
|
)))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
tracing::error!("Failed to send a message to admin room: {err}");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(deactivate::v3::Response {
|
Ok(deactivate::v3::Response {
|
||||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
||||||
|
|
|
@ -38,8 +38,8 @@ pub async fn report_event_route(
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
services().admin
|
if let Err(err) = services().admin
|
||||||
.send_message(message::RoomMessageEventContent::text_html(
|
.send_message(&message::RoomMessageEventContent::text_html(
|
||||||
format!(
|
format!(
|
||||||
"Report received from: {}\n\n\
|
"Report received from: {}\n\n\
|
||||||
Event ID: {:?}\n\
|
Event ID: {:?}\n\
|
||||||
|
@ -63,7 +63,9 @@ pub async fn report_event_route(
|
||||||
body.score,
|
body.score,
|
||||||
HtmlEscape(body.reason.as_deref().unwrap_or(""))
|
HtmlEscape(body.reason.as_deref().unwrap_or(""))
|
||||||
),
|
),
|
||||||
));
|
)).await {
|
||||||
|
tracing::error!("Failed to send a message to admin room: {err}");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(report_content::v3::Response {})
|
Ok(report_content::v3::Response {})
|
||||||
}
|
}
|
||||||
|
|
|
@ -972,7 +972,11 @@ impl KeyValueDatabase {
|
||||||
Ok(pwd_set) => {
|
Ok(pwd_set) => {
|
||||||
if pwd_set {
|
if pwd_set {
|
||||||
warn!("The Conduit account emergency password is set! Please unset it as soon as you finish admin account recovery!");
|
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) => {
|
Err(e) => {
|
||||||
|
@ -1043,12 +1047,14 @@ impl KeyValueDatabase {
|
||||||
last_update_id = last_update_id.max(update.id);
|
last_update_id = last_update_id.max(update.id);
|
||||||
if update.id > services().globals.last_check_for_updates_id()? {
|
if update.id > services().globals.last_check_for_updates_id()? {
|
||||||
println!("{}", update.message);
|
println!("{}", update.message);
|
||||||
services()
|
if let Err(err) = services()
|
||||||
.admin
|
.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{}",
|
"@room: The following is a message from the Conduit developers. It was sent on '{}':\n\n{}",
|
||||||
update.date, update.message
|
update.date, update.message
|
||||||
)))
|
))).await {
|
||||||
|
tracing::error!("Failed to send a message to admin room: {err}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
services()
|
services()
|
||||||
|
|
|
@ -184,7 +184,6 @@ enum AdminCommand {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AdminRoomEvent {
|
pub enum AdminRoomEvent {
|
||||||
ProcessMessage(String, ruma::OwnedEventId),
|
ProcessMessage(String, ruma::OwnedEventId),
|
||||||
SendMessage(RoomMessageEventContent),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
|
@ -221,7 +220,6 @@ impl Service {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
Some(event) = receiver.recv() => {
|
Some(event) = receiver.recv() => {
|
||||||
let message_content = match event {
|
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
|
AdminRoomEvent::ProcessMessage(room_message, event_id) => self.process_admin_message(room_message, &event_id).await
|
||||||
};
|
};
|
||||||
if let Some(message_content) = message_content {
|
if let Some(message_content) = message_content {
|
||||||
|
@ -269,12 +267,6 @@ impl Service {
|
||||||
.unwrap();
|
.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.
|
/// Delete user message in the conduit admin room.
|
||||||
pub async fn delete_user_message(
|
pub async fn delete_user_message(
|
||||||
&self,
|
&self,
|
||||||
|
@ -322,15 +314,8 @@ impl Service {
|
||||||
|
|
||||||
/// Send the message content and return it's result
|
/// 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
|
/// Note: Will return Ok(None) if there is no admin room
|
||||||
///
|
pub async fn send_message(
|
||||||
/// [`send_message`]: Self::send_message()
|
|
||||||
/// [`handler`]: Self::handler()
|
|
||||||
pub async fn send_message_with_result(
|
|
||||||
&self,
|
&self,
|
||||||
message_content: &RoomMessageEventContent,
|
message_content: &RoomMessageEventContent,
|
||||||
) -> Result<Option<Arc<EventId>>> {
|
) -> Result<Option<Arc<EventId>>> {
|
||||||
|
@ -715,7 +700,7 @@ impl Service {
|
||||||
// need it's event id to delete it after 60s
|
// need it's event id to delete it after 60s
|
||||||
let Some(sended_message_event_id) = services()
|
let Some(sended_message_event_id) = services()
|
||||||
.admin
|
.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)"
|
"Successfully reset the password for user {user_id}: {new_password} (This message will be deleted after 60s)"
|
||||||
)))
|
)))
|
||||||
.await?
|
.await?
|
||||||
|
@ -816,7 +801,7 @@ impl Service {
|
||||||
// need it's event id to delete it after 60s
|
// need it's event id to delete it after 60s
|
||||||
let Some(sended_message_event_id) = services()
|
let Some(sended_message_event_id) = services()
|
||||||
.admin
|
.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)"
|
"Created user with user_id: {user_id} and password: {password} (This message will be deleted after 60s)"
|
||||||
)))
|
)))
|
||||||
.await?
|
.await?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue