@@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import { EventType , MatrixEvent , Room } from "matrix-js-sdk/src/matrix" ;
17+ import { EventType , MatrixEvent , PendingEventOrdering , Room } from "matrix-js-sdk/src/matrix" ;
1818
1919import { MatrixDispatcher } from "../../../src/dispatcher/dispatcher" ;
2020import SettingsStore from "../../../src/settings/SettingsStore" ;
2121import { ListAlgorithm , SortAlgorithm } from "../../../src/stores/room-list/algorithms/models" ;
2222import { OrderedDefaultTagIDs , RoomUpdateCause } from "../../../src/stores/room-list/models" ;
2323import RoomListStore , { RoomListStoreClass } from "../../../src/stores/room-list/RoomListStore" ;
24+ import DMRoomMap from "../../../src/utils/DMRoomMap" ;
2425import { stubClient , upsertRoomStateEvents } from "../../test-utils" ;
2526
2627describe ( "RoomListStore" , ( ) => {
@@ -62,7 +63,9 @@ describe("RoomListStore", () => {
6263 upsertRoomStateEvents ( roomWithPredecessorEvent , [ predecessor ] ) ;
6364 const roomWithCreatePredecessor = new Room ( newRoomId , client , userId , { } ) ;
6465 upsertRoomStateEvents ( roomWithCreatePredecessor , [ createWithPredecessor ] ) ;
65- const roomNoPredecessor = new Room ( roomNoPredecessorId , client , userId , { } ) ;
66+ const roomNoPredecessor = new Room ( roomNoPredecessorId , client , userId , {
67+ pendingEventOrdering : PendingEventOrdering . Detached ,
68+ } ) ;
6669 upsertRoomStateEvents ( roomNoPredecessor , [ createNoPredecessor ] ) ;
6770 const oldRoom = new Room ( oldRoomId , client , userId , { } ) ;
6871 client . getRoom = jest . fn ( ) . mockImplementation ( ( roomId ) => {
@@ -138,6 +141,31 @@ describe("RoomListStore", () => {
138141 expect ( handleRoomUpdate ) . toHaveBeenCalledTimes ( 1 ) ;
139142 } ) ;
140143
144+ it ( "Lists all rooms that the client says are visible" , ( ) => {
145+ // Given 3 rooms that are visible according to the client
146+ const room1 = new Room ( "!r1:e.com" , client , userId , { pendingEventOrdering : PendingEventOrdering . Detached } ) ;
147+ const room2 = new Room ( "!r2:e.com" , client , userId , { pendingEventOrdering : PendingEventOrdering . Detached } ) ;
148+ const room3 = new Room ( "!r3:e.com" , client , userId , { pendingEventOrdering : PendingEventOrdering . Detached } ) ;
149+ room1 . updateMyMembership ( "join" ) ;
150+ room2 . updateMyMembership ( "join" ) ;
151+ room3 . updateMyMembership ( "join" ) ;
152+ DMRoomMap . makeShared ( ) ;
153+ const { store } = createStore ( ) ;
154+ client . getVisibleRooms = jest . fn ( ) . mockReturnValue ( [ room1 , room2 , room3 ] ) ;
155+
156+ // When we make the list of rooms
157+ store . regenerateAllLists ( { trigger : false } ) ;
158+
159+ // Then the list contains all 3
160+ expect ( store . orderedLists ) . toMatchObject ( {
161+ "im.vector.fake.recent" : [ room1 , room2 , room3 ] ,
162+ } ) ;
163+
164+ // We asked not to use MSC3946 when we asked the client for the visible rooms
165+ expect ( client . getVisibleRooms ) . toHaveBeenCalledWith ( false ) ;
166+ expect ( client . getVisibleRooms ) . toHaveBeenCalledTimes ( 1 ) ;
167+ } ) ;
168+
141169 describe ( "When feature_dynamic_room_predecessors = true" , ( ) => {
142170 beforeEach ( ( ) => {
143171 jest . spyOn ( SettingsStore , "getValue" ) . mockImplementation (
@@ -168,5 +196,19 @@ describe("RoomListStore", () => {
168196 // And the new room is added
169197 expect ( handleRoomUpdate ) . toHaveBeenCalledWith ( roomWithPredecessorEvent , RoomUpdateCause . NewRoom ) ;
170198 } ) ;
199+
200+ it ( "Passes the feature flag on to the client when asking for visible rooms" , ( ) => {
201+ // Given a store that we can ask for a room list
202+ DMRoomMap . makeShared ( ) ;
203+ const { store } = createStore ( ) ;
204+ client . getVisibleRooms = jest . fn ( ) . mockReturnValue ( [ ] ) ;
205+
206+ // When we make the list of rooms
207+ store . regenerateAllLists ( { trigger : false } ) ;
208+
209+ // We asked to use MSC3946 when we asked the client for the visible rooms
210+ expect ( client . getVisibleRooms ) . toHaveBeenCalledWith ( true ) ;
211+ expect ( client . getVisibleRooms ) . toHaveBeenCalledTimes ( 1 ) ;
212+ } ) ;
171213 } ) ;
172214} ) ;
0 commit comments