From fe337a036c3ab5f8548e2578b65568e628f4c32f Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Fri, 12 Apr 2024 21:43:48 +0200 Subject: [PATCH] chathistory: Fix order of entries on LATEST/BEFORE/AROUND subcommand --- sable_ircd/src/command/handlers/chathistory.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sable_ircd/src/command/handlers/chathistory.rs b/sable_ircd/src/command/handlers/chathistory.rs index db42cf2..55f2bc1 100644 --- a/sable_ircd/src/command/handlers/chathistory.rs +++ b/sable_ircd/src/command/handlers/chathistory.rs @@ -370,7 +370,7 @@ fn send_history_for_target_forward( } } - send_history_entries(into, subcommand, target, entries) + send_history_entries(into, subcommand, target, entries.into_iter()) } // As above, but work backwards @@ -408,16 +408,19 @@ fn send_history_for_target_reverse( } } - send_history_entries(into, subcommand, target, entries) + // "The order of returned messages within the batch is implementation-defined, but SHOULD be + // ascending time order or some approximation thereof, regardless of the subcommand used." + // -- https://ircv3.net/specs/extensions/chathistory#returned-message-notes + send_history_entries(into, subcommand, target, entries.into_iter().rev()) } -fn send_history_entries( +fn send_history_entries<'a>( into: impl MessageSink, subcommand: &str, target: &str, - entries: Vec<&HistoryLogEntry>, + entries: impl ExactSizeIterator, ) -> CommandResult { - if entries.is_empty() { + if entries.len() == 0 { into.send(message::Fail::new( "CHATHISTORY", "INVALID_TARGET",