From 81909a168180bf2fe208199fbbf6736548bbf8ba Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Fri, 28 Jun 2024 12:28:47 +0200 Subject: [PATCH] Add support for backward CHATHISTORY BETWEEN https://ircv3.net/specs/extensions/chathistory#between says "This may be forwards or backwards in time." --- sable_history/src/local_history.rs | 34 ++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/sable_history/src/local_history.rs b/sable_history/src/local_history.rs index 7b22e955..6081c3b4 100644 --- a/sable_history/src/local_history.rs +++ b/sable_history/src/local_history.rs @@ -109,15 +109,31 @@ impl HistoryService for NetworkHistoryLog { start_ts, end_ts, limit, - } => get_history_for_target( - self, - user, - target, - Some(start_ts), - Some(end_ts), - 0, // Backward limit - limit, - ), + } => { + if start_ts <= end_ts { + get_history_for_target( + self, + user, + target, + Some(start_ts), + Some(end_ts), + 0, // Backward limit + limit, + ) + } else { + // Search backward from start_ts instead of swapping start_ts and end_ts, + // because we want to match the last messages first in case we reach the limit + get_history_for_target( + self, + user, + target, + Some(start_ts), + Some(end_ts), + limit, + 0, // Forward limit + ) + } + } } } }