Test and fix space store wrongly treating room invites as space invites
parent
3bb6edbda7
commit
203425c8de
|
@ -410,33 +410,40 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
});
|
});
|
||||||
}, 100, {trailing: true, leading: true});
|
}, 100, {trailing: true, leading: true});
|
||||||
|
|
||||||
private onRoom = (room: Room, membership?: string, oldMembership?: string) => {
|
private onRoom = (room: Room, newMembership?: string, oldMembership?: string) => {
|
||||||
if ((membership || room.getMyMembership()) === "invite") {
|
const membership = newMembership || room.getMyMembership();
|
||||||
this._invitedSpaces.add(room);
|
|
||||||
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
|
if (!room.isSpaceRoom()) {
|
||||||
} else if (oldMembership === "invite" && membership !== "join") {
|
|
||||||
this._invitedSpaces.delete(room);
|
|
||||||
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
|
|
||||||
} else if (room?.isSpaceRoom()) {
|
|
||||||
this.onSpaceUpdate();
|
|
||||||
this.emit(room.roomId);
|
|
||||||
} else {
|
|
||||||
// this.onRoomUpdate(room);
|
// this.onRoomUpdate(room);
|
||||||
this.onRoomsUpdate();
|
this.onRoomsUpdate();
|
||||||
}
|
|
||||||
|
|
||||||
if (room.getMyMembership() === "join") {
|
if (membership === "join") {
|
||||||
if (!room.isSpaceRoom()) {
|
// the user just joined a room, remove it from the suggested list if it was there
|
||||||
const numSuggestedRooms = this._suggestedRooms.length;
|
const numSuggestedRooms = this._suggestedRooms.length;
|
||||||
this._suggestedRooms = this._suggestedRooms.filter(r => r.room_id !== room.roomId);
|
this._suggestedRooms = this._suggestedRooms.filter(r => r.room_id !== room.roomId);
|
||||||
if (numSuggestedRooms !== this._suggestedRooms.length) {
|
if (numSuggestedRooms !== this._suggestedRooms.length) {
|
||||||
this.emit(SUGGESTED_ROOMS, this._suggestedRooms);
|
this.emit(SUGGESTED_ROOMS, this._suggestedRooms);
|
||||||
}
|
}
|
||||||
} else if (room.roomId === RoomViewStore.getRoomId()) {
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Space
|
||||||
|
if (membership === "invite") {
|
||||||
|
this._invitedSpaces.add(room);
|
||||||
|
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
|
||||||
|
} else if (oldMembership === "invite" && membership !== "join") {
|
||||||
|
this._invitedSpaces.delete(room);
|
||||||
|
this.emit(UPDATE_INVITED_SPACES, this.invitedSpaces);
|
||||||
|
} else {
|
||||||
|
this.onSpaceUpdate();
|
||||||
|
this.emit(room.roomId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (membership === "join" && room.roomId === RoomViewStore.getRoomId()) {
|
||||||
// if the user was looking at the space and then joined: select that space
|
// if the user was looking at the space and then joined: select that space
|
||||||
this.setActiveSpace(room);
|
this.setActiveSpace(room);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private onRoomState = (ev: MatrixEvent) => {
|
private onRoomState = (ev: MatrixEvent) => {
|
||||||
|
|
|
@ -463,6 +463,31 @@ describe("SpaceStore", () => {
|
||||||
expect(store.spacePanelSpaces).toStrictEqual([]);
|
expect(store.spacePanelSpaces).toStrictEqual([]);
|
||||||
expect(store.invitedSpaces).toStrictEqual([]);
|
expect(store.invitedSpaces).toStrictEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("room invite gets added to relevant space filters", async () => {
|
||||||
|
const space = mkSpace(space1, [invite1]);
|
||||||
|
await run();
|
||||||
|
|
||||||
|
expect(store.spacePanelSpaces).toStrictEqual([space]);
|
||||||
|
expect(store.invitedSpaces).toStrictEqual([]);
|
||||||
|
expect(store.getChildSpaces(space1)).toStrictEqual([]);
|
||||||
|
expect(store.getChildRooms(space1)).toStrictEqual([]);
|
||||||
|
expect(store.getSpaceFilteredRoomIds(client.getRoom(space1)).has(invite1)).toBeFalsy();
|
||||||
|
expect(store.getSpaceFilteredRoomIds(null).has(invite1)).toBeFalsy();
|
||||||
|
|
||||||
|
const invite = mkRoom(invite1);
|
||||||
|
invite.getMyMembership.mockReturnValue("invite");
|
||||||
|
const prom = emitPromise(store, space1);
|
||||||
|
emitter.emit("Room", space);
|
||||||
|
await prom;
|
||||||
|
|
||||||
|
expect(store.spacePanelSpaces).toStrictEqual([space]);
|
||||||
|
expect(store.invitedSpaces).toStrictEqual([]);
|
||||||
|
expect(store.getChildSpaces(space1)).toStrictEqual([]);
|
||||||
|
expect(store.getChildRooms(space1)).toStrictEqual([invite]);
|
||||||
|
expect(store.getSpaceFilteredRoomIds(client.getRoom(space1)).has(invite1)).toBeTruthy();
|
||||||
|
expect(store.getSpaceFilteredRoomIds(null).has(invite1)).toBeTruthy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("active space switching tests", () => {
|
describe("active space switching tests", () => {
|
||||||
|
|
Loading…
Reference in New Issue