Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e080614

Browse files
committed
Pass the dynamic predecessor feature flag when listing rooms
1 parent 6dd578e commit e080614

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

Diff for: src/stores/room-list/RoomListStore.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> implements
496496
private getPlausibleRooms(): Room[] {
497497
if (!this.matrixClient) return [];
498498

499-
let rooms = this.matrixClient.getVisibleRooms().filter((r) => VisibilityProvider.instance.isRoomVisible(r));
499+
let rooms = this.matrixClient.getVisibleRooms(SettingsStore.getValue("feature_dynamic_room_predecessors"));
500+
rooms = rooms.filter((r) => VisibilityProvider.instance.isRoomVisible(r));
500501

501502
if (this.prefilterConditions.length > 0) {
502503
rooms = rooms.filter((r) => {

Diff for: test/stores/room-list/RoomListStore-test.ts

+44-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
1414
limitations 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

1919
import { MatrixDispatcher } from "../../../src/dispatcher/dispatcher";
2020
import SettingsStore from "../../../src/settings/SettingsStore";
2121
import { ListAlgorithm, SortAlgorithm } from "../../../src/stores/room-list/algorithms/models";
2222
import { OrderedDefaultTagIDs, RoomUpdateCause } from "../../../src/stores/room-list/models";
2323
import RoomListStore, { RoomListStoreClass } from "../../../src/stores/room-list/RoomListStore";
24+
import DMRoomMap from "../../../src/utils/DMRoomMap";
2425
import { stubClient, upsertRoomStateEvents } from "../../test-utils";
2526

2627
describe("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

Comments
 (0)