diff --git a/sable_ircd/src/command/handlers/chathistory.rs b/sable_ircd/src/command/handlers/chathistory.rs index 148e7e13..db42cf24 100644 --- a/sable_ircd/src/command/handlers/chathistory.rs +++ b/sable_ircd/src/command/handlers/chathistory.rs @@ -83,7 +83,7 @@ fn handle_chathistory( } send_history_for_target_reverse( - server, &response, source, &target, from_ts, None, limit, + server, &response, source, subcommand, &target, from_ts, None, limit, )?; } "BEFORE" => { @@ -116,6 +116,7 @@ fn handle_chathistory( server, &response, source, + subcommand, &target, None, Some(end_ts), @@ -152,6 +153,7 @@ fn handle_chathistory( server, &response, source, + subcommand, &target, Some(start_ts), None, @@ -190,6 +192,7 @@ fn handle_chathistory( server, &response, source, + subcommand, &target, Some(around_ts), None, @@ -199,6 +202,7 @@ fn handle_chathistory( server, &response, source, + subcommand, &target, Some(around_ts), None, @@ -247,6 +251,7 @@ fn handle_chathistory( server, &response, source, + subcommand, &target, Some(start_ts), Some(end_ts), @@ -335,6 +340,7 @@ fn send_history_for_target_forward( server: &ClientServer, into: impl MessageSink, source: &wrapper::User, + subcommand: &str, target: &str, from_ts: Option, to_ts: Option, @@ -364,16 +370,7 @@ fn send_history_for_target_forward( } } - let batch = into - .batch("chathistory", ClientCapability::Batch) - .with_arguments(&[target]) - .start(); - - for entry in entries { - entry.send_to(&batch, entry)?; - } - - Ok(()) + send_history_entries(into, subcommand, target, entries) } // As above, but work backwards @@ -381,6 +378,7 @@ fn send_history_for_target_reverse( server: &ClientServer, into: impl MessageSink, source: &wrapper::User, + subcommand: &str, target: &str, from_ts: Option, to_ts: Option, @@ -410,13 +408,31 @@ fn send_history_for_target_reverse( } } - let batch = into - .batch("chathistory", ClientCapability::Batch) - .with_arguments(&[target]) - .start(); + send_history_entries(into, subcommand, target, entries) +} - for entry in entries.into_iter().rev() { - entry.send_to(&batch, entry)?; +fn send_history_entries( + into: impl MessageSink, + subcommand: &str, + target: &str, + entries: Vec<&HistoryLogEntry>, +) -> CommandResult { + if entries.is_empty() { + into.send(message::Fail::new( + "CHATHISTORY", + "INVALID_TARGET", + &format!("{} {}", subcommand, target), + &format!("Cannot fetch history from {}", target), + )); + } else { + let batch = into + .batch("chathistory", ClientCapability::Batch) + .with_arguments(&[target]) + .start(); + + for entry in entries { + entry.send_to(&batch, entry)?; + } } Ok(())