@@ -9,7 +9,7 @@ extern crate conduit_service as service;
9
9
10
10
use conduit:: Result ;
11
11
pub ( crate ) use service:: admin:: { Command , Service } ;
12
- use service:: admin:: { CommandResult , HandlerResult } ;
12
+ use service:: admin:: { CommandOutput , CommandResult , HandlerResult } ;
13
13
14
14
use self :: { fsck:: FsckCommand , tester:: TesterCommands } ;
15
15
use crate :: {
@@ -68,7 +68,10 @@ pub fn handle(command: Command) -> HandlerResult { Box::pin(handle_command(comma
68
68
69
69
#[ tracing:: instrument( skip_all, name = "admin" ) ]
70
70
async fn handle_command ( command : Command ) -> CommandResult {
71
- let mut content = process_admin_message ( command. command ) . await ;
71
+ let Some ( mut content) = process_admin_message ( command. command ) . await else {
72
+ return Ok ( None ) ;
73
+ } ;
74
+
72
75
content. relates_to = command. reply_id . map ( |event_id| Reply {
73
76
in_reply_to : InReplyTo {
74
77
event_id,
@@ -79,7 +82,7 @@ async fn handle_command(command: Command) -> CommandResult {
79
82
}
80
83
81
84
// Parse and process a message from the admin room
82
- async fn process_admin_message ( msg : String ) -> RoomMessageEventContent {
85
+ async fn process_admin_message ( msg : String ) -> CommandOutput {
83
86
let mut lines = msg. lines ( ) . filter ( |l| !l. trim ( ) . is_empty ( ) ) ;
84
87
let command_line = lines. next ( ) . expect ( "each string has at least one line" ) ;
85
88
let body = lines. collect :: < Vec < _ > > ( ) ;
@@ -89,15 +92,15 @@ async fn process_admin_message(msg: String) -> RoomMessageEventContent {
89
92
Err ( error) => {
90
93
let server_name = services ( ) . globals . server_name ( ) ;
91
94
let message = error. replace ( "server.name" , server_name. as_str ( ) ) ;
92
- return RoomMessageEventContent :: notice_markdown ( message) ;
95
+ return Some ( RoomMessageEventContent :: notice_markdown ( message) ) ;
93
96
} ,
94
97
} ;
95
98
96
99
match process_admin_command ( admin_command, body) . await {
97
- Ok ( reply_message) => reply_message,
100
+ Ok ( reply_message) => Some ( reply_message) ,
98
101
Err ( error) => {
99
102
let markdown_message = format ! ( "Encountered an error while handling the command:\n ```\n {error}\n ```" , ) ;
100
- RoomMessageEventContent :: notice_markdown ( markdown_message)
103
+ Some ( RoomMessageEventContent :: notice_markdown ( markdown_message) )
101
104
} ,
102
105
}
103
106
}
0 commit comments