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

Fix timestamp matching for BEFORE and AROUND #124

Merged
merged 1 commit into from
May 4, 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
22 changes: 15 additions & 7 deletions sable_ircd/src/command/handlers/chathistory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn handle_chathistory(
}
"LATEST" => {
let target = arg_1;
let from_ts = match arg_2 {
let to_ts = match arg_2 {
"*" => None,
_ => Some(parse_msgref(subcommand, Some(target), arg_2)?),
};
Expand All @@ -97,15 +97,15 @@ fn handle_chathistory(
source,
subcommand,
&target,
from_ts,
None,
to_ts,
limit,
Some(0), // forward limit
)?;
}
"BEFORE" => {
let target = arg_1;
let end_ts = parse_msgref(subcommand, Some(target), arg_2)?;
let from_ts = parse_msgref(subcommand, Some(target), arg_2)?;

let limit = arg_3.parse().ok();
if limit.is_none() {
Expand All @@ -123,9 +123,9 @@ fn handle_chathistory(
&response,
source,
subcommand,
&target,
target,
Some(from_ts),
None,
Some(end_ts),
limit,
Some(0), // forward limit
)?;
Expand Down Expand Up @@ -308,12 +308,20 @@ fn send_history_for_target(
let mut forward_entries = Vec::new();

if backward_limit != Some(0) {
let from_ts = if forward_limit == Some(0) {
from_ts
} else {
// HACK: This is AROUND so we want to capture messages whose timestamp matches exactly
// (it's a message in the middle of the range)
from_ts.map(|from_ts| from_ts + 1)
};

for entry in log.entries_for_user_reverse(source.id()) {
if matches!(from_ts, Some(ts) if entry.timestamp <= ts) {
if matches!(from_ts, Some(ts) if entry.timestamp >= ts) {
// Skip over until we hit the timestamp window we're interested in
continue;
}
if matches!(to_ts, Some(ts) if entry.timestamp >= ts) {
if matches!(to_ts, Some(ts) if entry.timestamp <= ts) {
// If we hit this then we've passed the requested window and should stop
break;
}
Expand Down
Loading