Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
RoomIcon,
SpaceIcon,
UserProfileIcon,
FavouriteIcon,
HomeIcon,
GroupIcon,
CloseIcon,
Expand Down Expand Up @@ -156,10 +155,6 @@ function metaspaceToIcon(key: MetaSpace): JSX.Element | undefined {
switch (key) {
case MetaSpace.Home:
return <HomeIcon />;
case MetaSpace.Favourites:
return <FavouriteIcon />;
case MetaSpace.People:
return <UserProfileIcon />;
case MetaSpace.Orphans:
return <RoomIcon />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ export const onMetaSpaceChangeFactory =
PosthogTrackers.trackInteraction(
interactionName,
e,
[
MetaSpace.Home,
null,
MetaSpace.Favourites,
MetaSpace.People,
MetaSpace.Orphans,
MetaSpace.VideoRooms,
].indexOf(metaSpace),
[MetaSpace.Home, null, MetaSpace.Orphans, MetaSpace.VideoRooms].indexOf(metaSpace),
);
};

Expand Down
32 changes: 0 additions & 32 deletions apps/web/src/components/views/spaces/SpacePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import { DragDropContext, Draggable, Droppable, type DroppableProvidedProps } fr
import classNames from "classnames";
import { type Room } from "matrix-js-sdk/src/matrix";
import {
FavouriteSolidIcon,
HomeSolidIcon,
RoomIcon,
VideoCallSolidIcon,
UserProfileSolidIcon,
PlusIcon,
ChevronRightIcon,
} from "@vector-im/compound-design-tokens/assets/web/icons";
Expand Down Expand Up @@ -178,34 +176,6 @@ const HomeButton: React.FC<MetaSpaceButtonProps> = ({ selected, isPanelCollapsed
);
};

const FavouritesButton: React.FC<MetaSpaceButtonProps> = ({ selected, isPanelCollapsed }) => {
return (
<MetaSpaceButton
spaceKey={MetaSpace.Favourites}
selected={selected}
isPanelCollapsed={isPanelCollapsed}
label={getMetaSpaceName(MetaSpace.Favourites)}
notificationState={SpaceStore.instance.getNotificationState(MetaSpace.Favourites)}
size="32px"
icon={<FavouriteSolidIcon />}
/>
);
};

const PeopleButton: React.FC<MetaSpaceButtonProps> = ({ selected, isPanelCollapsed }) => {
return (
<MetaSpaceButton
spaceKey={MetaSpace.People}
selected={selected}
isPanelCollapsed={isPanelCollapsed}
label={getMetaSpaceName(MetaSpace.People)}
notificationState={SpaceStore.instance.getNotificationState(MetaSpace.People)}
size="32px"
icon={<UserProfileSolidIcon />}
/>
);
};

const OrphansButton: React.FC<MetaSpaceButtonProps> = ({ selected, isPanelCollapsed }) => {
return (
<MetaSpaceButton
Expand Down Expand Up @@ -286,8 +256,6 @@ const CreateSpaceButton: React.FC<Pick<IInnerSpacePanelProps, "isPanelCollapsed"

const metaSpaceComponentMap: Record<MetaSpace, typeof HomeButton> = {
[MetaSpace.Home]: HomeButton,
[MetaSpace.Favourites]: FavouritesButton,
[MetaSpace.People]: PeopleButton,
[MetaSpace.Orphans]: OrphansButton,
[MetaSpace.VideoRooms]: VideoRoomsButton,
};
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@
"encrypted": "Encrypted",
"error": "Error",
"faq": "FAQ",
"favourites": "Favourites",
"feedback": "Feedback",
"filter_results": "Filter results",
"forward_message": "Forward message",
Expand Down
14 changes: 0 additions & 14 deletions apps/web/src/stores/spaces/SpaceStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ describe("SpaceStore", () => {

await SettingsStore.setValue("Spaces.enabledMetaSpaces", null, SettingLevel.DEVICE, {
[MetaSpace.Home]: true,
[MetaSpace.Favourites]: true,
[MetaSpace.People]: true,
[MetaSpace.Orphans]: true,
});

Expand Down Expand Up @@ -444,12 +442,6 @@ describe("SpaceStore", () => {
expect(store.isRoomInSpace(MetaSpace.Home, room1)).toBeTruthy();
});

it("people space does contain people even if they are also shown in a space", async () => {
expect(store.isRoomInSpace(MetaSpace.People, dm1)).toBeTruthy();
expect(store.isRoomInSpace(MetaSpace.People, dm2)).toBeTruthy();
expect(store.isRoomInSpace(MetaSpace.People, dm3)).toBeTruthy();
});

it("orphans space does contain orphans even if they are also shown in all rooms", async () => {
await setShowAllRooms(true);
expect(store.isRoomInSpace(MetaSpace.Orphans, orphan1)).toBeTruthy();
Expand Down Expand Up @@ -1259,8 +1251,6 @@ describe("SpaceStore", () => {
expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([rootSpace]);
expect(SpaceStore.instance.isRoomInSpace(space1, room1)).toBeTruthy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Home, room1)).toBeFalsy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Favourites, room1)).toBeFalsy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.People, room1)).toBeFalsy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Orphans, room1)).toBeFalsy();

// receive room invite
Expand All @@ -1273,8 +1263,6 @@ describe("SpaceStore", () => {
expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([rootSpace]);
expect(SpaceStore.instance.isRoomInSpace(space1, room2)).toBeTruthy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Home, room2)).toBeTruthy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Favourites, room2)).toBeFalsy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.People, room2)).toBeFalsy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Orphans, room2)).toBeFalsy();

// start DM in space
Expand Down Expand Up @@ -1314,8 +1302,6 @@ describe("SpaceStore", () => {
expect(SpaceStore.instance.spacePanelSpaces).toStrictEqual([rootSpace]);
expect(SpaceStore.instance.isRoomInSpace(space1, dm1)).toBeTruthy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Home, dm1)).toBeTruthy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Favourites, dm1)).toBeFalsy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.People, dm1)).toBeTruthy();
expect(SpaceStore.instance.isRoomInSpace(MetaSpace.Orphans, dm1)).toBeFalsy();

// join subspace
Expand Down
71 changes: 8 additions & 63 deletions apps/web/src/stores/spaces/SpaceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import DMRoomMap from "../../utils/DMRoomMap";
import { SpaceNotificationState } from "../notifications/SpaceNotificationState";
import { RoomNotificationStateStore } from "../notifications/RoomNotificationStateStore";
import { DefaultTagID } from "../room-list-v3/skip-list/tag";
import { EnhancedMap, mapDiff } from "../../utils/maps";
import { setDiff, setHasDiff } from "../../utils/sets";
import { Action } from "../../dispatcher/actions";
Expand Down Expand Up @@ -451,7 +450,7 @@
}
// beyond this point we know this is a DM

if (space === MetaSpace.Home || space === MetaSpace.People) {
if (space === MetaSpace.Home) {
// these spaces contain all DMs
return true;
}
Expand Down Expand Up @@ -648,13 +647,6 @@
this.roomIdsBySpace.delete(MetaSpace.Home);
}

if (enabledMetaSpaces.has(MetaSpace.Favourites)) {
const favourites = visibleRooms.filter((r) => r.tags[DefaultTagID.Favourite]);
this.roomIdsBySpace.set(MetaSpace.Favourites, new Set(favourites.map((r) => r.roomId)));
} else {
this.roomIdsBySpace.delete(MetaSpace.Favourites);
}

// The People metaspace doesn't need maintaining

// Populate the orphans space if the Home space is enabled as it is a superset of it.
Expand All @@ -678,18 +670,13 @@
const visibleRooms = this.matrixClient.getVisibleRooms(this._msc3946ProcessDynamicPredecessor);

let dmBadgeSpace: MetaSpace | undefined;
// only show badges on dms on the most relevant space if such exists
if (enabledMetaSpaces.has(MetaSpace.People)) {
dmBadgeSpace = MetaSpace.People;
} else if (enabledMetaSpaces.has(MetaSpace.Home)) {
// only show badges on home
if (enabledMetaSpaces.has(MetaSpace.Home)) {
dmBadgeSpace = MetaSpace.Home;
}

if (!spaces) {
spaces = [...this.roomIdsBySpace.keys()];
if (dmBadgeSpace === MetaSpace.People) {
spaces.push(MetaSpace.People);
}
if (enabledMetaSpaces.has(MetaSpace.Home) && !this.allRoomsInHome) {
spaces.push(MetaSpace.Home);
}
Expand All @@ -703,10 +690,6 @@
// Update NotificationStates
this.getNotificationState(s).setRooms(
visibleRooms.filter((room) => {
if (s === MetaSpace.People) {
return this.isRoomInSpace(MetaSpace.People, room.roomId);
}

if (room.isSpaceRoom() || !flattenedRoomsForSpace.has(room.roomId)) return false;

if (dmBadgeSpace && DMRoomMap.shared().getUserIdForRoomId(room.roomId)) {
Expand All @@ -717,10 +700,6 @@
}),
);
});

if (dmBadgeSpace !== MetaSpace.People) {
this.notificationStateMap.delete(MetaSpace.People);
}
};

private showInHomeSpace = (room: Room): boolean => {
Expand Down Expand Up @@ -885,13 +864,7 @@
this.switchSpaceIfNeeded();
}

const notificationStatesToUpdate = [...changeSet];
// We update the People metaspace even if we didn't detect any changes
// as roomIdsBySpace does not pre-calculate it so we have to assume it could have changed
if (this.enabledMetaSpaces.includes(MetaSpace.People)) {
notificationStatesToUpdate.push(MetaSpace.People);
}
this.updateNotificationStates(notificationStatesToUpdate);
this.updateNotificationStates([...changeSet]);
};

private switchSpaceIfNeeded = (roomId = SDKContextClass.instance.roomViewStore.getRoomId()): void => {
Expand Down Expand Up @@ -1070,27 +1043,9 @@
if (order !== lastOrder) {
this.notifyIfOrderChanged();
}
} else if (ev.getType() === EventType.Tag) {
// If the room was in favourites and now isn't or the opposite then update its position in the trees
const oldTags = lastEv?.getContent()?.tags || {};
const newTags = ev.getContent()?.tags || {};
if (!!oldTags[DefaultTagID.Favourite] !== !!newTags[DefaultTagID.Favourite]) {
this.onRoomFavouriteChange(room);
}
}
};

private onRoomFavouriteChange(room: Room): void {
if (this.enabledMetaSpaces.includes(MetaSpace.Favourites)) {
if (room.tags[DefaultTagID.Favourite]) {
this.roomIdsBySpace.get(MetaSpace.Favourites)?.add(room.roomId);
} else {
this.roomIdsBySpace.get(MetaSpace.Favourites)?.delete(room.roomId);
}
this.emit(MetaSpace.Favourites);
}
}

private onRoomDmChange(room: Room, isDm: boolean): void {
const enabledMetaSpaces = new Set(this.enabledMetaSpaces);

Expand All @@ -1105,10 +1060,6 @@
this.emit(MetaSpace.Home);
}

if (enabledMetaSpaces.has(MetaSpace.People)) {
this.emit(MetaSpace.People);
}

if (enabledMetaSpaces.has(MetaSpace.Orphans) || enabledMetaSpaces.has(MetaSpace.Home)) {
if (isDm && this.roomIdsBySpace.get(MetaSpace.Orphans)?.delete(room.roomId)) {
this.emit(MetaSpace.Orphans);
Expand Down Expand Up @@ -1204,8 +1155,6 @@
const enabled = new Set(this.enabledMetaSpaces);
PosthogAnalytics.instance.setProperty("WebMetaSpaceHomeEnabled", enabled.has(MetaSpace.Home));
PosthogAnalytics.instance.setProperty("WebMetaSpaceHomeAllRooms", this.allRoomsInHome);
PosthogAnalytics.instance.setProperty("WebMetaSpacePeopleEnabled", enabled.has(MetaSpace.People));
PosthogAnalytics.instance.setProperty("WebMetaSpaceFavouritesEnabled", enabled.has(MetaSpace.Favourites));
PosthogAnalytics.instance.setProperty("WebMetaSpaceOrphansEnabled", enabled.has(MetaSpace.Orphans));
}

Expand Down Expand Up @@ -1292,21 +1241,17 @@
const newValue = SettingsStore.getValue("Spaces.enabledMetaSpaces");
const enabledMetaSpaces = metaSpaceOrder.filter((k) => newValue[k]);
if (arrayHasDiff(this._enabledMetaSpaces, enabledMetaSpaces)) {
const hadPeopleOrHomeEnabled = this.enabledMetaSpaces.some((s) => {
return s === MetaSpace.Home || s === MetaSpace.People;
});
const hadHomeEnabled = this.enabledMetaSpaces.some((s) => s === MetaSpace.Home);

Check warning on line 1244 in apps/web/src/stores/spaces/SpaceStore.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()` instead of `.some()` when checking value existence.

See more on https://sonarcloud.io/project/issues?id=element-web&issues=AZ9B7lDPo-H3ZaYClSGj&open=AZ9B7lDPo-H3ZaYClSGj&pullRequest=34187
this._enabledMetaSpaces = enabledMetaSpaces;
const hasPeopleOrHomeEnabled = this.enabledMetaSpaces.some((s) => {
return s === MetaSpace.Home || s === MetaSpace.People;
});
const hasHomeEnabled = this.enabledMetaSpaces.some((s) => s === MetaSpace.Home);

Check warning on line 1246 in apps/web/src/stores/spaces/SpaceStore.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()` instead of `.some()` when checking value existence.

See more on https://sonarcloud.io/project/issues?id=element-web&issues=AZ9B7lDPo-H3ZaYClSGk&open=AZ9B7lDPo-H3ZaYClSGk&pullRequest=34187

// if a metaspace currently being viewed was removed, go to another one
if (isMetaSpace(this.activeSpace) && !newValue[this.activeSpace]) {
this.switchSpaceIfNeeded();
}
this.rebuildMetaSpaces();

if (hadPeopleOrHomeEnabled !== hasPeopleOrHomeEnabled) {
if (hadHomeEnabled !== hasHomeEnabled) {
// in this case we have to rebuild everything as DM badges will move to/from real spaces
this.updateNotificationStates();
} else {
Expand All @@ -1323,7 +1268,7 @@
if (payload.roomId) {
// getSpaceFilteredUserIds will return the appropriate value
this.emit(payload.roomId);
if (!this.enabledMetaSpaces.some((s) => s === MetaSpace.Home || s === MetaSpace.People)) {
if (!this.enabledMetaSpaces.some((s) => s === MetaSpace.Home)) {

Check warning on line 1271 in apps/web/src/stores/spaces/SpaceStore.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()` instead of `.some()` when checking value existence.

See more on https://sonarcloud.io/project/issues?id=element-web&issues=AZ9B7lDPo-H3ZaYClSGl&open=AZ9B7lDPo-H3ZaYClSGl&pullRequest=34187

Check warning on line 1271 in apps/web/src/stores/spaces/SpaceStore.ts

View workflow job for this annotation

GitHub Actions / Tests

Uncovered Line

Line 1271 is not covered by tests
this.updateNotificationStates([payload.roomId]);
}
}
Expand Down
14 changes: 1 addition & 13 deletions apps/web/src/stores/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export const UPDATE_SUGGESTED_ROOMS = Symbol("suggested-rooms");

export enum MetaSpace {
Home = "home-space",
Favourites = "favourites-space",
People = "people-space",
Orphans = "orphans-space",
VideoRooms = "video-rooms-space",
}
Expand All @@ -31,10 +29,6 @@ export const getMetaSpaceName = (spaceKey: MetaSpace, allRoomsInHome = false): s
switch (spaceKey) {
case MetaSpace.Home:
return allRoomsInHome ? _t("common|all_chats") : _t("common|home");
case MetaSpace.Favourites:
return _t("common|favourites");
case MetaSpace.People:
return _t("common|people");
case MetaSpace.Orphans:
return _t("common|orphan_rooms");
case MetaSpace.VideoRooms:
Expand All @@ -57,11 +51,5 @@ export interface ISuggestedRoom extends HierarchyRoom {
}

export function isMetaSpace(spaceKey?: SpaceKey): spaceKey is MetaSpace {
return (
spaceKey === MetaSpace.Home ||
spaceKey === MetaSpace.Favourites ||
spaceKey === MetaSpace.People ||
spaceKey === MetaSpace.Orphans ||
spaceKey === MetaSpace.VideoRooms
);
return spaceKey === MetaSpace.Home || spaceKey === MetaSpace.Orphans || spaceKey === MetaSpace.VideoRooms;
}
Original file line number Diff line number Diff line change
Expand Up @@ -706,24 +706,19 @@ describe("Spotlight Dialog", () => {
beforeEach(() => {
jest.spyOn(SpaceStore.instance, "enabledMetaSpaces", "get").mockReturnValue([
MetaSpace.Home,
MetaSpace.Favourites,
MetaSpace.People,
MetaSpace.Orphans,
]);
});

it.each([MetaSpace.Home, MetaSpace.Favourites, MetaSpace.People])(
"should show metaspace %s",
async (metaSpace) => {
const onFinished = jest.fn();
const { asFragment, container } = render(
<SpotlightDialog initialText={metaSpace.split("-")[0]} onFinished={onFinished} />,
);
await waitFor(() =>
expect(container.querySelector(".mx_SpotlightDialog_metaspaceResult")).toBeInTheDocument(),
);
expect(asFragment()).toMatchSnapshot();
},
);
it("should show Home metaspace", async () => {
const onFinished = jest.fn();
const { asFragment, container } = render(
<SpotlightDialog initialText={MetaSpace.Home.split("-")[0]} onFinished={onFinished} />,
);
await waitFor(() =>
expect(container.querySelector(".mx_SpotlightDialog_metaspaceResult")).toBeInTheDocument(),
);
expect(asFragment()).toMatchSnapshot();
});
});
});
Loading
Loading