fix(search): apply the date range to server results client-side
from_ts/to_ts are not Matrix filter fields; the server dropped them, so the range only worked for the local encrypted-room search. Stop sending them and post-filter server results by origin_server_ts with the same inclusive predicate. Unit-tested; docs corrected. Fixes #13 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { filterGroupsByMsgType, filterGroupsByPinned, ResultGroup } from './useMessageSearch';
|
||||
import {
|
||||
filterGroupsByDateRange,
|
||||
filterGroupsByMsgType,
|
||||
filterGroupsByPinned,
|
||||
ResultGroup,
|
||||
} from './useMessageSearch';
|
||||
|
||||
// Minimal ResultGroup/ResultItem fixtures — only the fields the filters read
|
||||
// (event.content.msgtype, event.event_id, group.roomId).
|
||||
@@ -9,6 +14,11 @@ const item = (msgtype: string | undefined, eventId: string) => ({
|
||||
event: { event_id: eventId, content: msgtype === undefined ? {} : { msgtype } },
|
||||
context: {},
|
||||
});
|
||||
const tsItem = (eventId: string, ts: number) => ({
|
||||
rank: 1,
|
||||
event: { event_id: eventId, origin_server_ts: ts, content: {} },
|
||||
context: {},
|
||||
});
|
||||
const mkGroups = (
|
||||
...groups: { roomId: string; items: ReturnType<typeof item>[] }[]
|
||||
): ResultGroup[] => groups as unknown as ResultGroup[];
|
||||
@@ -48,6 +58,33 @@ test('filterGroupsByMsgType: ignores items with a non-string msgtype', () => {
|
||||
assert.equal(out[0].items[0].event.event_id, '$2');
|
||||
});
|
||||
|
||||
test('filterGroupsByDateRange: no bounds returns groups unchanged', () => {
|
||||
const groups = mkGroups({ roomId: '!r1', items: [tsItem('$1', 100)] });
|
||||
assert.equal(filterGroupsByDateRange(groups, undefined, undefined), groups);
|
||||
});
|
||||
|
||||
test('filterGroupsByDateRange: keeps only items within an inclusive range', () => {
|
||||
const groups = mkGroups({
|
||||
roomId: '!r1',
|
||||
items: [tsItem('$1', 50), tsItem('$2', 100), tsItem('$3', 150), tsItem('$4', 200)],
|
||||
});
|
||||
const out = filterGroupsByDateRange(groups, 100, 150);
|
||||
assert.deepEqual(
|
||||
out[0].items.map((i) => i.event.event_id),
|
||||
['$2', '$3'],
|
||||
);
|
||||
});
|
||||
|
||||
test('filterGroupsByDateRange: drops groups left empty and supports one-sided bounds', () => {
|
||||
const groups = mkGroups(
|
||||
{ roomId: '!r1', items: [tsItem('$1', 50)] },
|
||||
{ roomId: '!r2', items: [tsItem('$2', 500)] },
|
||||
);
|
||||
const out = filterGroupsByDateRange(groups, 100, undefined);
|
||||
assert.equal(out.length, 1);
|
||||
assert.equal(out[0].roomId, '!r2');
|
||||
});
|
||||
|
||||
test('filterGroupsByPinned: disabled returns groups unchanged', () => {
|
||||
const groups = mkGroups({ roomId: '!r1', items: [item('m.text', '$1')] });
|
||||
assert.equal(
|
||||
|
||||
Reference in New Issue
Block a user