@@ -20,7 +20,7 @@ import { Thread, THREAD_RELATION_TYPE, ThreadEvent } from "../../../src/models/t
20
20
import { mkThread } from "../../test-utils/thread" ;
21
21
import { TestClient } from "../../TestClient" ;
22
22
import { emitPromise , mkMessage , mock } from "../../test-utils/test-utils" ;
23
- import { EventStatus , MatrixEvent } from "../../../src" ;
23
+ import { Direction , EventStatus , MatrixEvent } from "../../../src" ;
24
24
import { ReceiptType } from "../../../src/@types/read_receipts" ;
25
25
import { getMockClientWithEventEmitter , mockClientMethodsUser } from "../../test-utils/client" ;
26
26
import { ReEmitter } from "../../../src/ReEmitter" ;
@@ -283,4 +283,106 @@ describe("Thread", () => {
283
283
expect ( thread2 . getEventReadUpTo ( myUserId ) ) . toBe ( null ) ;
284
284
} ) ;
285
285
} ) ;
286
+
287
+ describe ( "resetLiveTimeline" , ( ) => {
288
+ it ( "correctly resets the live timeline" , async ( ) => {
289
+ const myUserId = "@bob:example.org" ;
290
+ const testClient = new TestClient ( myUserId , "DEVICE" , "ACCESS_TOKEN" , undefined , {
291
+ timelineSupport : false ,
292
+ } ) ;
293
+ const client = testClient . client ;
294
+ const room = new Room ( "123" , client , myUserId , {
295
+ pendingEventOrdering : PendingEventOrdering . Detached ,
296
+ } ) ;
297
+
298
+ jest . spyOn ( client , "getRoom" ) . mockReturnValue ( room ) ;
299
+
300
+ const { thread } = mkThread ( {
301
+ room,
302
+ client,
303
+ authorId : myUserId ,
304
+ participantUserIds : [ "@alice:example.org" ] ,
305
+ length : 3 ,
306
+ } ) ;
307
+ await emitPromise ( thread , ThreadEvent . Update ) ;
308
+ expect ( thread . length ) . toBe ( 2 ) ;
309
+
310
+ jest . spyOn ( client , "createMessagesRequest" ) . mockImplementation ( ( _ , token ) =>
311
+ Promise . resolve ( {
312
+ chunk : [ ] ,
313
+ start : `${ token } -new` ,
314
+ end : `${ token } -new` ,
315
+ } ) ,
316
+ ) ;
317
+
318
+ function timelines ( ) : [ string | null , string | null ] [ ] {
319
+ return thread . timelineSet
320
+ . getTimelines ( )
321
+ . map ( ( it ) => [ it . getPaginationToken ( Direction . Backward ) , it . getPaginationToken ( Direction . Forward ) ] ) ;
322
+ }
323
+
324
+ expect ( timelines ( ) ) . toEqual ( [ [ null , null ] ] ) ;
325
+ const promise = thread . resetLiveTimeline ( "b1" , "f1" ) ;
326
+ expect ( timelines ( ) ) . toEqual ( [
327
+ [ null , "f1" ] ,
328
+ [ "b1" , null ] ,
329
+ ] ) ;
330
+ await promise ;
331
+ expect ( timelines ( ) ) . toEqual ( [
332
+ [ null , "f1-new" ] ,
333
+ [ "b1-new" , null ] ,
334
+ ] ) ;
335
+ } ) ;
336
+
337
+ it ( "does not modify changed tokens" , async ( ) => {
338
+ const myUserId = "@bob:example.org" ;
339
+ const testClient = new TestClient ( myUserId , "DEVICE" , "ACCESS_TOKEN" , undefined , {
340
+ timelineSupport : false ,
341
+ } ) ;
342
+ const client = testClient . client ;
343
+ const room = new Room ( "123" , client , myUserId , {
344
+ pendingEventOrdering : PendingEventOrdering . Detached ,
345
+ } ) ;
346
+
347
+ jest . spyOn ( client , "getRoom" ) . mockReturnValue ( room ) ;
348
+
349
+ const { thread } = mkThread ( {
350
+ room,
351
+ client,
352
+ authorId : myUserId ,
353
+ participantUserIds : [ "@alice:example.org" ] ,
354
+ length : 3 ,
355
+ } ) ;
356
+ await emitPromise ( thread , ThreadEvent . Update ) ;
357
+ expect ( thread . length ) . toBe ( 2 ) ;
358
+
359
+ jest . spyOn ( client , "createMessagesRequest" ) . mockImplementation ( ( _ , token ) =>
360
+ Promise . resolve ( {
361
+ chunk : [ ] ,
362
+ start : `${ token } -new` ,
363
+ end : `${ token } -new` ,
364
+ } ) ,
365
+ ) ;
366
+
367
+ function timelines ( ) : [ string | null , string | null ] [ ] {
368
+ return thread . timelineSet
369
+ . getTimelines ( )
370
+ . map ( ( it ) => [ it . getPaginationToken ( Direction . Backward ) , it . getPaginationToken ( Direction . Forward ) ] ) ;
371
+ }
372
+
373
+ expect ( timelines ( ) ) . toEqual ( [ [ null , null ] ] ) ;
374
+ const promise = thread . resetLiveTimeline ( "b1" , "f1" ) ;
375
+ expect ( timelines ( ) ) . toEqual ( [
376
+ [ null , "f1" ] ,
377
+ [ "b1" , null ] ,
378
+ ] ) ;
379
+ thread . timelineSet . getTimelines ( ) [ 0 ] . setPaginationToken ( "f2" , Direction . Forward ) ;
380
+ thread . timelineSet . getTimelines ( ) [ 1 ] . setPaginationToken ( "b2" , Direction . Backward ) ;
381
+ await promise ;
382
+ expect ( timelines ( ) ) . toEqual ( [
383
+ [ null , "f2" ] ,
384
+ [ "b2" , null ] ,
385
+ ] ) ;
386
+ } ) ;
387
+ } ) ;
286
388
} ) ;
0 commit comments