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

Commit

Permalink
Space preferences for whether or not you see DMs in a Space (#7250)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Dec 17, 2021
1 parent 5ee356d commit 39c4b78
Show file tree
Hide file tree
Showing 22 changed files with 881 additions and 320 deletions.
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 @@ -396,6 +396,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
99 changes: 99 additions & 0 deletions src/components/views/dialogs/SpacePreferencesDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
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 chats with members of this space. " +
"Turning this off will hide those chats from your view of %(spaceName)s.", {
spaceName: space.name,
}) }
</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
15 changes: 11 additions & 4 deletions src/components/views/rooms/RoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
SpaceKey,
UPDATE_SUGGESTED_ROOMS,
UPDATE_SELECTED_SPACE,
isMetaSpace,
} from "../../../stores/spaces";
import { shouldShowSpaceInvite, showAddExistingRooms, showCreateNewRoom, showSpaceInvite } from "../../../utils/space";
import { replaceableComponent } from "../../../utils/replaceableComponent";
Expand All @@ -62,6 +63,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 @@ -493,10 +495,10 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
};

private onExplore = () => {
if (this.props.activeSpace[0] === "!") {
if (!isMetaSpace(this.props.activeSpace)) {
defaultDispatcher.dispatch({
action: "view_room",
room_id: SpaceStore.instance.activeSpace,
room_id: this.props.activeSpace,
});
} else {
const initialText = RoomListStore.instance.getFirstNameFilterCondition()?.search;
Expand Down Expand Up @@ -611,7 +613,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) ||
(
!isMetaSpace(this.props.activeSpace) &&
orderedTagId === DefaultTagID.DM &&
!SettingsStore.getValue("Spaces.showPeopleInSpace", this.props.activeSpace)
)
) {
alwaysVisible = false;
}
Expand Down Expand Up @@ -668,7 +675,7 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
kind="link"
onClick={this.onExplore}
>
{ this.props.activeSpace[0] === "!" ? _t("Explore rooms") : _t("Explore all public rooms") }
{ !isMetaSpace(this.props.activeSpace) ? _t("Explore rooms") : _t("Explore all public rooms") }
</AccessibleButton>
</div>;
}
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 @@ -2727,6 +2727,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 chats with members of this space. Turning this off will hide those chats from your view of %(spaceName)s.": "This groups your chats with members of this space. Turning this off will hide those chats from your view of %(spaceName)s.",
"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 @@ -872,6 +872,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
4 changes: 2 additions & 2 deletions src/stores/room-list/SpaceWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import { RoomListStoreClass } from "./RoomListStore";
import { SpaceFilterCondition } from "./filters/SpaceFilterCondition";
import SpaceStore from "../spaces/SpaceStore";
import { MetaSpace, SpaceKey, UPDATE_HOME_BEHAVIOUR, UPDATE_SELECTED_SPACE } from "../spaces";
import { isMetaSpace, MetaSpace, SpaceKey, UPDATE_HOME_BEHAVIOUR, UPDATE_SELECTED_SPACE } from "../spaces";

/**
* Watches for changes in spaces to manage the filter on the provided RoomListStore
Expand Down Expand Up @@ -66,7 +66,7 @@ export class SpaceWatcher {
};

private updateFilter = () => {
if (this.activeSpace[0] === "!") {
if (!isMetaSpace(this.activeSpace)) {
SpaceStore.instance.traverseSpace(this.activeSpace, roomId => {
this.store.matrixClient?.getRoom(roomId)?.loadMembersIfNeeded();
});
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

0 comments on commit 39c4b78

Please sign in to comment.