@@ -2998,6 +2998,8 @@ describe("MatrixClient", function () {
29982998 replacedByDynamicPredecessor2 ,
29992999 room2 ,
30003000 ] ;
3001+ client . store . getRoom = ( roomId : string ) =>
3002+ client . store . getRooms ( ) . find ( ( r ) => r . roomId === roomId ) || null ;
30013003 room1 . addLiveEvents (
30023004 [
30033005 roomCreateEvent ( room1 . roomId , replacedByCreate1 . roomId ) ,
@@ -3036,6 +3038,7 @@ describe("MatrixClient", function () {
30363038 replacedByDynamicPredecessor2,
30373039 } ;
30383040 }
3041+
30393042 it ( "Returns an empty list if there are no rooms" , ( ) => {
30403043 client . store = new StubStore ( ) ;
30413044 client . store . getRooms = ( ) => [ ] ;
@@ -3062,6 +3065,8 @@ describe("MatrixClient", function () {
30623065 const room2 = new Room ( "room2" , client , "@daryl:alexandria.example.com" ) ;
30633066 client . store = new StubStore ( ) ;
30643067 client . store . getRooms = ( ) => [ room1 , replacedRoom1 , replacedRoom2 , room2 ] ;
3068+ client . store . getRoom = ( roomId : string ) =>
3069+ client . store . getRooms ( ) . find ( ( r ) => r . roomId === roomId ) || null ;
30653070 room1 . addLiveEvents ( [ roomCreateEvent ( room1 . roomId , replacedRoom1 . roomId ) ] , { addToState : true } ) ;
30663071 room2 . addLiveEvents ( [ roomCreateEvent ( room2 . roomId , replacedRoom2 . roomId ) ] , { addToState : true } ) ;
30673072 replacedRoom1 . addLiveEvents ( [ tombstoneEvent ( room1 . roomId , replacedRoom1 . roomId ) ] , { addToState : true } ) ;
@@ -3127,6 +3132,24 @@ describe("MatrixClient", function () {
31273132 expect ( rooms ) . toContain ( room1 ) ;
31283133 expect ( rooms ) . toContain ( room2 ) ;
31293134 } ) ;
3135+
3136+ it ( "should ignore room replacements which are not reciprocated by the predecessor" , ( ) => {
3137+ const room1 = new Room ( "room1" , client , "@carol:alexandria.example.com" ) ;
3138+ // Room 2 claims to replace room 1 but room 1 does not agree
3139+ const room2 = new Room ( "replacedRoom1" , client , "@daryl:alexandria.example.com" ) ;
3140+
3141+ client . store = new StubStore ( ) ;
3142+ client . store . getRooms = ( ) => [ room1 , room2 ] ;
3143+ client . store . getRoom = ( roomId : string ) =>
3144+ client . store . getRooms ( ) . find ( ( r ) => r . roomId === roomId ) || null ;
3145+
3146+ room2 . addLiveEvents ( [ roomCreateEvent ( room2 . roomId , room1 . roomId ) ] , { addToState : true } ) ;
3147+
3148+ // When we ask for the visible rooms
3149+ const rooms = client . getVisibleRooms ( ) ;
3150+ expect ( rooms ) . toContain ( room1 ) ;
3151+ expect ( rooms ) . toContain ( room2 ) ;
3152+ } ) ;
31303153 } ) ;
31313154
31323155 describe ( "getRoomUpgradeHistory" , ( ) => {
0 commit comments