@@ -22,7 +22,11 @@ import { logger } from "matrix-js-sdk/src/logger";
22
22
import { haveRendererForEvent } from "../src/events/EventTileFactory" ;
23
23
import { makeBeaconEvent , mkEvent , stubClient } from "./test-utils" ;
24
24
import { mkThread } from "./test-utils/threads" ;
25
- import { doesRoomHaveUnreadMessages , eventTriggersUnreadCount } from "../src/Unread" ;
25
+ import {
26
+ doesRoomHaveUnreadMessages ,
27
+ doesRoomOrThreadHaveUnreadMessages ,
28
+ eventTriggersUnreadCount ,
29
+ } from "../src/Unread" ;
26
30
import { MatrixClientPeg } from "../src/MatrixClientPeg" ;
27
31
28
32
jest . mock ( "../src/events/EventTileFactory" , ( ) => ( {
@@ -122,7 +126,7 @@ describe("Unread", () => {
122
126
let room : Room ;
123
127
let event : MatrixEvent ;
124
128
const roomId = "!abc:server.org" ;
125
- const myId = client . getUserId ( ) ! ;
129
+ const myId = client . getSafeUserId ( ) ;
126
130
127
131
beforeAll ( ( ) => {
128
132
client . supportsThreads = ( ) => true ;
@@ -429,4 +433,73 @@ describe("Unread", () => {
429
433
) ;
430
434
} ) ;
431
435
} ) ;
436
+
437
+ describe ( "doesRoomOrThreadHaveUnreadMessages()" , ( ) => {
438
+ let room : Room ;
439
+ let event : MatrixEvent ;
440
+ const roomId = "!abc:server.org" ;
441
+ const myId = client . getSafeUserId ( ) ;
442
+
443
+ beforeAll ( ( ) => {
444
+ client . supportsThreads = ( ) => true ;
445
+ } ) ;
446
+
447
+ beforeEach ( ( ) => {
448
+ room = new Room ( roomId , client , myId ) ;
449
+ jest . spyOn ( logger , "warn" ) ;
450
+ event = mkEvent ( {
451
+ event : true ,
452
+ type : "m.room.message" ,
453
+ user : aliceId ,
454
+ room : roomId ,
455
+ content : { } ,
456
+ } ) ;
457
+ room . addLiveEvents ( [ event ] ) ;
458
+
459
+ // Don't care about the code path of hidden events.
460
+ mocked ( haveRendererForEvent ) . mockClear ( ) . mockReturnValue ( true ) ;
461
+ } ) ;
462
+
463
+ it ( "should consider unthreaded read receipts for main timeline" , ( ) => {
464
+ // Send unthreaded receipt into room pointing at the latest event
465
+ room . addReceipt (
466
+ new MatrixEvent ( {
467
+ type : "m.receipt" ,
468
+ room_id : "!foo:bar" ,
469
+ content : {
470
+ [ event . getId ( ) ! ] : {
471
+ [ ReceiptType . Read ] : {
472
+ [ myId ] : { ts : 1 } ,
473
+ } ,
474
+ } ,
475
+ } ,
476
+ } ) ,
477
+ ) ;
478
+
479
+ expect ( doesRoomOrThreadHaveUnreadMessages ( room ) ) . toBe ( false ) ;
480
+ } ) ;
481
+
482
+ it ( "should consider unthreaded read receipts for thread timelines" , ( ) => {
483
+ // Provide an unthreaded read receipt with ts greater than the latest thread event
484
+ const receipt = new MatrixEvent ( {
485
+ type : "m.receipt" ,
486
+ room_id : "!foo:bar" ,
487
+ content : {
488
+ [ event . getId ( ) ! ] : {
489
+ [ ReceiptType . Read ] : {
490
+ [ myId ] : { ts : 10000000000 } ,
491
+ } ,
492
+ } ,
493
+ } ,
494
+ } ) ;
495
+ room . addReceipt ( receipt ) ;
496
+
497
+ const { thread } = mkThread ( { room, client, authorId : myId , participantUserIds : [ aliceId ] } ) ;
498
+
499
+ expect ( thread . replyToEvent ! . getTs ( ) ) . toBeLessThan (
500
+ receipt . getContent ( ) [ event . getId ( ) ! ] [ ReceiptType . Read ] [ myId ] . ts ,
501
+ ) ;
502
+ expect ( doesRoomOrThreadHaveUnreadMessages ( thread ) ) . toBe ( false ) ;
503
+ } ) ;
504
+ } ) ;
432
505
} ) ;
0 commit comments