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

Commit 0c4ae43

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

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

src/stores/room-list/RoomListStore.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> implements
5656
public static TEST_MODE = false;
5757

5858
private initialListsGenerated = false;
59+
private msc3946ProcessDynamicPredecessor: boolean;
60+
private msc3946SettingWatcherRef: string;
5961
private algorithm = new Algorithm();
6062
private prefilterConditions: IFilterCondition[] = [];
6163
private updateFn = new MarkedExecution(() => {
@@ -69,6 +71,20 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> implements
6971
super(dis);
7072
this.setMaxListeners(20); // RoomList + LeftPanel + 8xRoomSubList + spares
7173
this.algorithm.start();
74+
75+
this.msc3946ProcessDynamicPredecessor = SettingsStore.getValue("feature_dynamic_room_predecessors");
76+
this.msc3946SettingWatcherRef = SettingsStore.watchSetting(
77+
"feature_dynamic_room_predecessors",
78+
null,
79+
(_settingName, _roomId, _level, _newValAtLevel, newVal) => {
80+
this.msc3946ProcessDynamicPredecessor = newVal;
81+
this.regenerateAllLists({ trigger: true });
82+
},
83+
);
84+
}
85+
86+
public componentWillUnmount(): void {
87+
SettingsStore.unwatchSetting(this.msc3946SettingWatcherRef);
7288
}
7389

7490
private setupWatchers(): void {
@@ -286,7 +302,7 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> implements
286302
// If we're joining an upgraded room, we'll want to make sure we don't proliferate
287303
// the dead room in the list.
288304
const roomState: RoomState = membershipPayload.room.currentState;
289-
const predecessor = roomState.findPredecessor(SettingsStore.getValue("feature_dynamic_room_predecessors"));
305+
const predecessor = roomState.findPredecessor(this.msc3946ProcessDynamicPredecessor);
290306
if (predecessor) {
291307
const prevRoom = this.matrixClient.getRoom(predecessor.roomId);
292308
if (prevRoom) {
@@ -496,7 +512,8 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> implements
496512
private getPlausibleRooms(): Room[] {
497513
if (!this.matrixClient) return [];
498514

499-
let rooms = this.matrixClient.getVisibleRooms().filter((r) => VisibilityProvider.instance.isRoomVisible(r));
515+
let rooms = this.matrixClient.getVisibleRooms(this.msc3946ProcessDynamicPredecessor);
516+
rooms = rooms.filter((r) => VisibilityProvider.instance.isRoomVisible(r));
500517

501518
if (this.prefilterConditions.length > 0) {
502519
rooms = rooms.filter((r) => {

test/stores/room-list/RoomListStore-test.ts

Lines changed: 44 additions & 2 deletions
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)