@@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import { EventType , MatrixEvent , Room } from "matrix-js-sdk/src/matrix" ;
17
+ import { EventType , MatrixEvent , PendingEventOrdering , Room } from "matrix-js-sdk/src/matrix" ;
18
18
19
19
import { MatrixDispatcher } from "../../../src/dispatcher/dispatcher" ;
20
20
import SettingsStore from "../../../src/settings/SettingsStore" ;
21
21
import { ListAlgorithm , SortAlgorithm } from "../../../src/stores/room-list/algorithms/models" ;
22
22
import { OrderedDefaultTagIDs , RoomUpdateCause } from "../../../src/stores/room-list/models" ;
23
23
import RoomListStore , { RoomListStoreClass } from "../../../src/stores/room-list/RoomListStore" ;
24
+ import DMRoomMap from "../../../src/utils/DMRoomMap" ;
24
25
import { stubClient , upsertRoomStateEvents } from "../../test-utils" ;
25
26
26
27
describe ( "RoomListStore" , ( ) => {
@@ -62,7 +63,9 @@ describe("RoomListStore", () => {
62
63
upsertRoomStateEvents ( roomWithPredecessorEvent , [ predecessor ] ) ;
63
64
const roomWithCreatePredecessor = new Room ( newRoomId , client , userId , { } ) ;
64
65
upsertRoomStateEvents ( roomWithCreatePredecessor , [ createWithPredecessor ] ) ;
65
- const roomNoPredecessor = new Room ( roomNoPredecessorId , client , userId , { } ) ;
66
+ const roomNoPredecessor = new Room ( roomNoPredecessorId , client , userId , {
67
+ pendingEventOrdering : PendingEventOrdering . Detached ,
68
+ } ) ;
66
69
upsertRoomStateEvents ( roomNoPredecessor , [ createNoPredecessor ] ) ;
67
70
const oldRoom = new Room ( oldRoomId , client , userId , { } ) ;
68
71
client . getRoom = jest . fn ( ) . mockImplementation ( ( roomId ) => {
@@ -138,6 +141,31 @@ describe("RoomListStore", () => {
138
141
expect ( handleRoomUpdate ) . toHaveBeenCalledTimes ( 1 ) ;
139
142
} ) ;
140
143
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
+
141
169
describe ( "When feature_dynamic_room_predecessors = true" , ( ) => {
142
170
beforeEach ( ( ) => {
143
171
jest . spyOn ( SettingsStore , "getValue" ) . mockImplementation (
@@ -168,5 +196,19 @@ describe("RoomListStore", () => {
168
196
// And the new room is added
169
197
expect ( handleRoomUpdate ) . toHaveBeenCalledWith ( roomWithPredecessorEvent , RoomUpdateCause . NewRoom ) ;
170
198
} ) ;
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
+ } ) ;
171
213
} ) ;
172
214
} ) ;
0 commit comments