@@ -14,17 +14,17 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import { MatrixClient , PendingEventOrdering } from "../../../src/client" ;
18
- import { Room } from "../../../src/models/room" ;
19
- import { Thread , THREAD_RELATION_TYPE , ThreadEvent } from "../../../src/models/thread" ;
20
- import { mkThread } from "../../test-utils/thread" ;
21
- import { TestClient } from "../../TestClient" ;
22
- import { emitPromise , mkMessage , mock } from "../../test-utils/test-utils" ;
23
- import { EventStatus , MatrixEvent } from "../../../src" ;
24
- import { ReceiptType } from "../../../src/@types/read_receipts" ;
25
- import { getMockClientWithEventEmitter , mockClientMethodsUser } from "../../test-utils/client" ;
26
- import { ReEmitter } from "../../../src/ReEmitter" ;
27
- import { Feature , ServerSupport } from "../../../src/feature" ;
17
+ import { MatrixClient , PendingEventOrdering } from "../../../src/client" ;
18
+ import { Room } from "../../../src/models/room" ;
19
+ import { Thread , THREAD_RELATION_TYPE , ThreadEvent } from "../../../src/models/thread" ;
20
+ import { mkThread } from "../../test-utils/thread" ;
21
+ import { TestClient } from "../../TestClient" ;
22
+ import { emitPromise , mkMessage , mock } from "../../test-utils/test-utils" ;
23
+ import { Direction , EventStatus , MatrixEvent } from "../../../src" ;
24
+ import { ReceiptType } from "../../../src/@types/read_receipts" ;
25
+ import { getMockClientWithEventEmitter , mockClientMethodsUser } from "../../test-utils/client" ;
26
+ import { ReEmitter } from "../../../src/ReEmitter" ;
27
+ import { Feature , ServerSupport } from "../../../src/feature" ;
28
28
29
29
describe ( "Thread" , ( ) => {
30
30
describe ( "constructor" , ( ) => {
@@ -283,4 +283,84 @@ 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 , { timelineSupport : false } ) ;
291
+ const client = testClient . client ;
292
+ const room = new Room ( "123" , client , myUserId , {
293
+ pendingEventOrdering : PendingEventOrdering . Detached ,
294
+ } ) ;
295
+
296
+ jest . spyOn ( client , "getRoom" ) . mockReturnValue ( room ) ;
297
+
298
+ const { thread } = mkThread ( {
299
+ room,
300
+ client,
301
+ authorId : myUserId ,
302
+ participantUserIds : [ "@alice:example.org" ] ,
303
+ length : 3 ,
304
+ } ) ;
305
+ await emitPromise ( thread , ThreadEvent . Update ) ;
306
+ expect ( thread . length ) . toBe ( 2 ) ;
307
+
308
+ jest . spyOn ( client , "createMessagesRequest" ) . mockImplementation ( ( _ , token ) => Promise . resolve ( {
309
+ chunk : [ ] ,
310
+ start : `${ token } -new` ,
311
+ end : `${ token } -new` ,
312
+ } ) ) ;
313
+
314
+ function timelines ( ) : [ string | null , string | null ] [ ] {
315
+ return thread . timelineSet . getTimelines ( )
316
+ . map ( it => [ it . getPaginationToken ( Direction . Backward ) , it . getPaginationToken ( Direction . Forward ) ] ) ;
317
+ }
318
+
319
+ expect ( timelines ( ) ) . toEqual ( [ [ null , null ] ] ) ;
320
+ const promise = thread . resetLiveTimeline ( "b1" , "f1" ) ;
321
+ expect ( timelines ( ) ) . toEqual ( [ [ null , "f1" ] , [ "b1" , null ] ] ) ;
322
+ await promise ;
323
+ expect ( timelines ( ) ) . toEqual ( [ [ null , "f1-new" ] , [ "b1-new" , null ] ] ) ;
324
+ } ) ;
325
+
326
+ it ( "does not modify changed tokens" , async ( ) => {
327
+ const myUserId = "@bob:example.org" ;
328
+ const testClient = new TestClient ( myUserId , "DEVICE" , "ACCESS_TOKEN" , undefined , { timelineSupport : false } ) ;
329
+ const client = testClient . client ;
330
+ const room = new Room ( "123" , client , myUserId , {
331
+ pendingEventOrdering : PendingEventOrdering . Detached ,
332
+ } ) ;
333
+
334
+ jest . spyOn ( client , "getRoom" ) . mockReturnValue ( room ) ;
335
+
336
+ const { thread } = mkThread ( {
337
+ room,
338
+ client,
339
+ authorId : myUserId ,
340
+ participantUserIds : [ "@alice:example.org" ] ,
341
+ length : 3 ,
342
+ } ) ;
343
+ await emitPromise ( thread , ThreadEvent . Update ) ;
344
+ expect ( thread . length ) . toBe ( 2 ) ;
345
+
346
+ jest . spyOn ( client , "createMessagesRequest" ) . mockImplementation ( ( _ , token ) => Promise . resolve ( {
347
+ chunk : [ ] ,
348
+ start : `${ token } -new` ,
349
+ end : `${ token } -new` ,
350
+ } ) ) ;
351
+
352
+ function timelines ( ) : [ string | null , string | null ] [ ] {
353
+ return thread . timelineSet . getTimelines ( )
354
+ . map ( it => [ it . getPaginationToken ( Direction . Backward ) , it . getPaginationToken ( Direction . Forward ) ] ) ;
355
+ }
356
+
357
+ expect ( timelines ( ) ) . toEqual ( [ [ null , null ] ] ) ;
358
+ const promise = thread . resetLiveTimeline ( "b1" , "f1" ) ;
359
+ expect ( timelines ( ) ) . toEqual ( [ [ null , "f1" ] , [ "b1" , null ] ] ) ;
360
+ thread . timelineSet . getTimelines ( ) [ 0 ] . setPaginationToken ( "f2" , Direction . Forward ) ;
361
+ thread . timelineSet . getTimelines ( ) [ 1 ] . setPaginationToken ( "b2" , Direction . Backward ) ;
362
+ await promise ;
363
+ expect ( timelines ( ) ) . toEqual ( [ [ null , "f2" ] , [ "b2" , null ] ] ) ;
364
+ } ) ;
365
+ } ) ;
286
366
} ) ;
0 commit comments