Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chathistory: Fix order of entries on LATEST/BEFORE/AROUND subcommand #111

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions sable_ircd/src/command/handlers/chathistory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Item = &'a HistoryLogEntry>,
) -> CommandResult {
if entries.is_empty() {
if entries.len() == 0 {
into.send(message::Fail::new(
"CHATHISTORY",
"INVALID_TARGET",
Expand Down
Loading