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

Space preferences for whether or not you see DMs in a Space #7250

Merged
merged 32 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8e58cfc
Space preferences for whether or not you see DMs in a Space
t3chguy Dec 1, 2021
b25f201
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy Dec 6, 2021
ae3a710
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy Dec 6, 2021
489b0d5
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy Dec 7, 2021
fe15f7e
SpaceStore refactor space hierarchy building
t3chguy Dec 7, 2021
56d4790
stop throttling and inline method
t3chguy Dec 7, 2021
a5a2f3b
SpaceStore refactor metaspace building
t3chguy Dec 7, 2021
e4ce602
SpaceStore refactor hide internals of room filtering behind isRoomInS…
t3chguy Dec 7, 2021
e3208e5
SpaceStore refactor building notification states
t3chguy Dec 7, 2021
58fca9f
Fix WatchManager IRRELEVANT_ROOM
t3chguy Dec 7, 2021
899c0ca
Wire up `Spaces.showPeopleInSpace`
t3chguy Dec 7, 2021
4c9c763
Round 1 of optimisations
t3chguy Dec 7, 2021
3516494
Round 2 of optimisations
t3chguy Dec 7, 2021
87a1414
Fix joining subspaces not showing up immediately in the Space Panel
t3chguy Dec 7, 2021
5fcab8e
Round 3 of optimisations
t3chguy Dec 7, 2021
76801b1
Round 4 of optimisations
t3chguy Dec 8, 2021
6d8f744
remove unused bits
t3chguy Dec 8, 2021
cf4093e
Fix edge case
t3chguy Dec 8, 2021
ec3e559
Fix edge case behaviour around orphans and dms
t3chguy Dec 9, 2021
11cb10b
Fix edge case behaviour around orphans and dms
t3chguy Dec 9, 2021
905bcc4
delint
t3chguy Dec 9, 2021
8252a09
stash
t3chguy Dec 9, 2021
18abac8
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy Dec 9, 2021
ba34f84
TestyMcTestFace
t3chguy Dec 10, 2021
5a4c26f
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy Dec 10, 2021
3a0805e
Fix tests
t3chguy Dec 10, 2021
44c7a84
Tweak copy
t3chguy Dec 13, 2021
04eceec
consolidate types
t3chguy Dec 14, 2021
12910bc
Extract isMetaSpace to utility function
t3chguy Dec 14, 2021
46654a0
tidy
t3chguy Dec 14, 2021
027fd19
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy Dec 17, 2021
2b7cdea
tidy up
t3chguy Dec 17, 2021
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
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
@import "./views/dialogs/_SettingsDialog.scss";
@import "./views/dialogs/_ShareDialog.scss";
@import "./views/dialogs/_SlashCommandHelpDialog.scss";
@import "./views/dialogs/_SpacePreferencesDialog.scss";
@import "./views/dialogs/_SpaceSettingsDialog.scss";
@import "./views/dialogs/_SpotlightDialog.scss";
@import "./views/dialogs/_TabbedIntegrationManagerDialog.scss";
Expand Down
4 changes: 4 additions & 0 deletions res/css/structures/_SpacePanel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ $activeBorderColor: $primary-content;
mask-image: url('$(res)/img/element-icons/roomlist/search.svg');
}

.mx_SpacePanel_iconPreferences::before {
mask-image: url('$(res)/img/element-icons/settings/preference.svg');
}

.mx_SpacePanel_noIcon {
display: none;

Expand Down
5 changes: 4 additions & 1 deletion res/css/views/dialogs/_SettingsDialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ limitations under the License.
*/

// Not actually a component but things shared by settings components
.mx_UserSettingsDialog, .mx_RoomSettingsDialog, .mx_SpaceSettingsDialog {
.mx_UserSettingsDialog,
.mx_RoomSettingsDialog,
.mx_SpaceSettingsDialog,
.mx_SpacePreferencesDialog {
width: 90vw;
max-width: 1000px;
// set the height too since tabbed view scrolls itself.
Expand Down
34 changes: 34 additions & 0 deletions res/css/views/dialogs/_SpacePreferencesDialog.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_SpacePreferencesDialog {
width: 700px;
height: 400px;

.mx_TabbedView .mx_SettingsTab {
min-width: unset;

.mx_SettingsTab_section {
font-size: $font-15px;
line-height: $font-24px;

.mx_Checkbox + p {
color: $secondary-content;
margin: 0 20px 0 24px;
}
}
}
}
14 changes: 14 additions & 0 deletions src/components/views/context_menus/SpaceContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
showCreateNewRoom,
showCreateNewSubspace,
showSpaceInvite,
showSpacePreferences,
showSpaceSettings,
} from "../../../utils/space";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
Expand Down Expand Up @@ -166,6 +167,14 @@ const SpaceContextMenu = ({ space, hideHeader, onFinished, ...props }: IProps) =
</>;
}

const onPreferencesClick = (ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();

showSpacePreferences(space);
onFinished();
};

const onExploreRoomsClick = (ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();
Expand Down Expand Up @@ -193,6 +202,11 @@ const SpaceContextMenu = ({ space, hideHeader, onFinished, ...props }: IProps) =
label={canAddRooms ? _t("Manage & explore rooms") : _t("Explore rooms")}
onClick={onExploreRoomsClick}
/>
<IconizedContextMenuOption
iconClassName="mx_SpacePanel_iconPreferences"
label={_t("Preferences")}
onClick={onPreferencesClick}
/>
{ settingsOption }
{ leaveOption }
{ devtoolsOption }
Expand Down
97 changes: 97 additions & 0 deletions src/components/views/dialogs/SpacePreferencesDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { ChangeEvent } from "react";
import { Room } from "matrix-js-sdk/src/models/room";

import { _t, _td } from '../../../languageHandler';
import BaseDialog from "../dialogs/BaseDialog";
import { IDialogProps } from "./IDialogProps";
import TabbedView, { Tab } from "../../structures/TabbedView";
import StyledCheckbox from "../elements/StyledCheckbox";
import { useSettingValue } from "../../../hooks/useSettings";
import SettingsStore from "../../../settings/SettingsStore";
import { SettingLevel } from "../../../settings/SettingLevel";
import RoomName from "../elements/RoomName";

export enum SpacePreferenceTab {
Appearance = "SPACE_PREFERENCE_APPEARANCE_TAB",
}

interface IProps extends IDialogProps {
space: Room;
initialTabId?: SpacePreferenceTab;
}

const SpacePreferencesAppearanceTab = ({ space }: Pick<IProps, "space">) => {
const showPeople = useSettingValue("Spaces.showPeopleInSpace", space.roomId);

return (
<div className="mx_SettingsTab">
<div className="mx_SettingsTab_heading">{ _t("Sections to show") }</div>

<div className="mx_SettingsTab_section">
<StyledCheckbox
checked={!!showPeople}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
SettingsStore.setValue(
"Spaces.showPeopleInSpace",
space.roomId,
SettingLevel.ROOM_ACCOUNT,
!showPeople,
);
}}
>
{ _t("People") }
</StyledCheckbox>
<p>
{ _t("This groups your ongoing conversations with members of this space. " +
"Turning off will hide it from your view.") }
</p>
</div>
</div>
);
};

const SpacePreferencesDialog: React.FC<IProps> = ({ space, initialTabId, onFinished }) => {
const tabs = [
new Tab(
SpacePreferenceTab.Appearance,
_td("Appearance"),
"mx_RoomSettingsDialog_notificationsIcon",
<SpacePreferencesAppearanceTab space={space} />,
),
];

return (
<BaseDialog
className="mx_SpacePreferencesDialog"
hasCancel
onFinished={onFinished}
title={_t("Preferences")}
fixedWidth={false}
>
<h4>
<RoomName room={space} />
</h4>
<div className="mx_SettingsDialog_content">
<TabbedView tabs={tabs} initialTabId={initialTabId} />
</div>
</BaseDialog>
);
};

export default SpacePreferencesDialog;
2 changes: 1 addition & 1 deletion src/components/views/dialogs/UserSettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export enum UserTab {
}

interface IProps extends IDialogProps {
initialTabId?: string;
initialTabId?: UserTab;
}

interface IState {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/rooms/NewRoomIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const NewRoomIntro = () => {
let parentSpace: Room;
if (
SpaceStore.instance.activeSpaceRoom?.canInvite(cli.getUserId()) &&
SpaceStore.instance.getSpaceFilteredRoomIds(SpaceStore.instance.activeSpace).has(room.roomId)
SpaceStore.instance.isRoomInSpace(SpaceStore.instance.activeSpace, room.roomId)
) {
parentSpace = SpaceStore.instance.activeSpaceRoom;
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/views/rooms/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
import { useEventEmitterState } from "../../../hooks/useEventEmitter";
import { ChevronFace, ContextMenuTooltipButton, useContextMenu } from "../../structures/ContextMenu";
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import SettingsStore from "../../../settings/SettingsStore";

interface IProps {
onKeyDown: (ev: React.KeyboardEvent, state: IRovingTabIndexState) => void;
Expand Down Expand Up @@ -611,7 +612,12 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
if (
(this.props.activeSpace === MetaSpace.Favourites && orderedTagId !== DefaultTagID.Favourite) ||
(this.props.activeSpace === MetaSpace.People && orderedTagId !== DefaultTagID.DM) ||
(this.props.activeSpace === MetaSpace.Orphans && orderedTagId === DefaultTagID.DM)
(this.props.activeSpace === MetaSpace.Orphans && orderedTagId === DefaultTagID.DM) ||
(
this.props.activeSpace[0] === "!" &&
orderedTagId === DefaultTagID.DM &&
!SettingsStore.getValue("Spaces.showPeopleInSpace", this.props.activeSpace)
)
) {
alwaysVisible = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/spaces/SpaceTreeLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
);

this.state = {
collapsed: collapsed,
collapsed,
childSpaces: this.childSpaces,
};

Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2705,6 +2705,8 @@
"Link to selected message": "Link to selected message",
"Link to room": "Link to room",
"Command Help": "Command Help",
"Sections to show": "Sections to show",
"This groups your ongoing conversations with members of this space. Turning off will hide it from your view.": "This groups your ongoing conversations with members of this space. Turning off will hide it from your view.",
"Space settings": "Space settings",
"Settings - %(spaceName)s": "Settings - %(spaceName)s",
"Spaces you're in": "Spaces you're in",
Expand Down
5 changes: 5 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,11 @@ export const SETTINGS: {[setting: string]: ISetting} = {
[MetaSpace.Home]: true,
}, false),
},
"Spaces.showPeopleInSpace": {
supportedLevels: [SettingLevel.ROOM_ACCOUNT],
default: true,
controller: new IncompatibleController("showCommunitiesInsteadOfSpaces", null),
},
"showCommunitiesInsteadOfSpaces": {
displayName: _td("Display Communities instead of Spaces"),
description: _td("Temporarily show communities instead of Spaces for this session. " +
Expand Down
2 changes: 1 addition & 1 deletion src/settings/WatchManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SettingLevel } from "./SettingLevel";

export type CallbackFn = (changedInRoomId: string, atLevel: SettingLevel, newValAtLevel: any) => void;

const IRRELEVANT_ROOM = Symbol("irrelevant-room");
const IRRELEVANT_ROOM: string = null;

/**
* Generalized management class for dealing with watchers on a per-handler (per-level)
Expand Down
18 changes: 16 additions & 2 deletions src/stores/room-list/filters/SpaceFilterCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { IDestroyable } from "../../../utils/IDestroyable";
import SpaceStore from "../../spaces/SpaceStore";
import { MetaSpace, SpaceKey } from "../../spaces";
import { setHasDiff } from "../../../utils/sets";
import SettingsStore from "../../../settings/SettingsStore";

/**
* A filter condition for the room list which reveals rooms which
Expand All @@ -31,22 +32,35 @@ import { setHasDiff } from "../../../utils/sets";
*/
export class SpaceFilterCondition extends EventEmitter implements IFilterCondition, IDestroyable {
private roomIds = new Set<string>();
private userIds = new Set<string>();
private showPeopleInSpace = true;
private space: SpaceKey = MetaSpace.Home;

public get kind(): FilterKind {
return FilterKind.Prefilter;
}

public isVisible(room: Room): boolean {
return this.roomIds.has(room.roomId);
return SpaceStore.instance.isRoomInSpace(this.space, room.roomId);
}

private onStoreUpdate = async (): Promise<void> => {
const beforeRoomIds = this.roomIds;
// clone the set as it may be mutated by the space store internally
this.roomIds = new Set(SpaceStore.instance.getSpaceFilteredRoomIds(this.space));

if (setHasDiff(beforeRoomIds, this.roomIds)) {
const beforeUserIds = this.userIds;
// clone the set as it may be mutated by the space store internally
this.userIds = new Set(SpaceStore.instance.getSpaceFilteredUserIds(this.space));

const beforeShowPeopleInSpace = this.showPeopleInSpace;
this.showPeopleInSpace = this.space[0] !== "!" ||
SettingsStore.getValue("Spaces.showPeopleInSpace", this.space);

if (beforeShowPeopleInSpace !== this.showPeopleInSpace ||
setHasDiff(beforeRoomIds, this.roomIds) ||
setHasDiff(beforeUserIds, this.userIds)
) {
this.emit(FILTER_CHANGED);
// XXX: Room List Store has a bug where updates to the pre-filter during a local echo of a
// tags transition seem to be ignored, so refire in the next tick to work around it
Expand Down
Loading