88 getTimelineItemKey ,
99} from "./timelineItems.ts" ;
1010
11- function dayAt ( year , month , day , hour = 12 ) {
11+ function dayAt ( year , month , day , hour = 12 , minute = 0 ) {
1212 return Math . floor (
13- new Date ( year , month - 1 , day , hour , 0 , 0 ) . getTime ( ) / 1_000 ,
13+ new Date ( year , month - 1 , day , hour , minute , 0 ) . getTime ( ) / 1_000 ,
1414 ) ;
1515}
1616
@@ -90,11 +90,19 @@ test("buildTimelineItems: system messages flatten to a 'system' item", () => {
9090 assert . deepEqual ( kinds ( items ) , [ "day-divider" , "message" , "system" ] ) ;
9191} ) ;
9292
93- test ( "buildTimelineItems: consecutive messages from the same author are grouped" , ( ) => {
93+ test ( "buildTimelineItems: consecutive same-author messages within the window are grouped" , ( ) => {
9494 const entries = [
9595 entry ( { id : "a" , pubkey : "author-a" , createdAt : dayAt ( 2026 , 6 , 14 ) } ) ,
96- entry ( { id : "b" , pubkey : "AUTHOR-A" , createdAt : dayAt ( 2026 , 6 , 14 , 13 ) } ) ,
97- entry ( { id : "c" , pubkey : "author-b" , createdAt : dayAt ( 2026 , 6 , 14 , 14 ) } ) ,
96+ entry ( {
97+ id : "b" ,
98+ pubkey : "AUTHOR-A" ,
99+ createdAt : dayAt ( 2026 , 6 , 14 , 12 , 2 ) ,
100+ } ) ,
101+ entry ( {
102+ id : "c" ,
103+ pubkey : "author-b" ,
104+ createdAt : dayAt ( 2026 , 6 , 14 , 12 , 3 ) ,
105+ } ) ,
98106 ] ;
99107
100108 const messageItems = buildTimelineItems ( entries , null ) . items . filter (
@@ -111,6 +119,53 @@ test("buildTimelineItems: consecutive messages from the same author are grouped"
111119 ) ;
112120} ) ;
113121
122+ test ( "buildTimelineItems: same-author messages past the window start a new group" , ( ) => {
123+ const author = "author-a" ;
124+ const entries = [
125+ entry ( { id : "a" , pubkey : author , createdAt : dayAt ( 2026 , 6 , 14 , 12 , 0 ) } ) ,
126+ // 8 min later — within the 10-min window, groups as a continuation.
127+ entry ( { id : "b" , pubkey : author , createdAt : dayAt ( 2026 , 6 , 14 , 12 , 8 ) } ) ,
128+ // 12 min after "b" — past the window, breaks into a new thought.
129+ entry ( { id : "c" , pubkey : author , createdAt : dayAt ( 2026 , 6 , 14 , 12 , 20 ) } ) ,
130+ // 5 min after "c" — within the window again, groups onto "c".
131+ entry ( { id : "d" , pubkey : author , createdAt : dayAt ( 2026 , 6 , 14 , 12 , 25 ) } ) ,
132+ ] ;
133+
134+ const messageItems = buildTimelineItems ( entries , null ) . items . filter (
135+ ( item ) => item . kind === "message" ,
136+ ) ;
137+
138+ assert . deepEqual (
139+ messageItems . map ( ( item ) => item . isContinuation ) ,
140+ [ false , true , false , true ] ,
141+ ) ;
142+ assert . deepEqual (
143+ messageItems . map ( ( item ) => item . isFollowedByContinuation ) ,
144+ [ true , false , true , false ] ,
145+ ) ;
146+ } ) ;
147+
148+ test ( "buildTimelineItems: window is measured against the previous message, not the group start" , ( ) => {
149+ const author = "author-a" ;
150+ // Each message is 8 min after the one above it — a steady stream that never
151+ // gaps out, so grouping continues even though the span (16 min) exceeds the
152+ // 10-min window.
153+ const entries = [
154+ entry ( { id : "a" , pubkey : author , createdAt : dayAt ( 2026 , 6 , 14 , 12 , 0 ) } ) ,
155+ entry ( { id : "b" , pubkey : author , createdAt : dayAt ( 2026 , 6 , 14 , 12 , 8 ) } ) ,
156+ entry ( { id : "c" , pubkey : author , createdAt : dayAt ( 2026 , 6 , 14 , 12 , 16 ) } ) ,
157+ ] ;
158+
159+ const messageItems = buildTimelineItems ( entries , null ) . items . filter (
160+ ( item ) => item . kind === "message" ,
161+ ) ;
162+
163+ assert . deepEqual (
164+ messageItems . map ( ( item ) => item . isContinuation ) ,
165+ [ false , true , true ] ,
166+ ) ;
167+ } ) ;
168+
114169test ( "buildTimelineItems: dividers break grouping while thread summaries do not" , ( ) => {
115170 const sameAuthor = "author-a" ;
116171 const entries = [
@@ -119,16 +174,20 @@ test("buildTimelineItems: dividers break grouping while thread summaries do not"
119174 ...entry ( {
120175 id : "b" ,
121176 pubkey : sameAuthor ,
122- createdAt : dayAt ( 2026 , 6 , 14 , 13 ) ,
177+ createdAt : dayAt ( 2026 , 6 , 14 , 12 , 1 ) ,
123178 } ) ,
124179 summary : {
125180 threadHeadId : "b" ,
126181 replyCount : 1 ,
127- lastReplyAt : dayAt ( 2026 , 6 , 14 , 13 ) ,
182+ lastReplyAt : dayAt ( 2026 , 6 , 14 , 12 , 1 ) ,
128183 participants : [ ] ,
129184 } ,
130185 } ,
131- entry ( { id : "c" , pubkey : sameAuthor , createdAt : dayAt ( 2026 , 6 , 14 , 14 ) } ) ,
186+ entry ( {
187+ id : "c" ,
188+ pubkey : sameAuthor ,
189+ createdAt : dayAt ( 2026 , 6 , 14 , 12 , 2 ) ,
190+ } ) ,
132191 entry ( { id : "d" , pubkey : sameAuthor , createdAt : dayAt ( 2026 , 6 , 15 ) } ) ,
133192 ] ;
134193
0 commit comments