2020-06-08 04:06:41 +00:00
|
|
|
/*
|
2021-01-05 12:29:48 +00:00
|
|
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
2020-06-08 04:06:41 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
import React, { createRef, useContext, useState } from "react";
|
2021-03-01 15:53:16 +00:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
import * as fbEmitter from "fbemitter";
|
2021-11-30 18:08:46 +00:00
|
|
|
import classNames from "classnames";
|
2021-03-01 15:53:16 +00:00
|
|
|
|
2020-06-08 04:06:41 +00:00
|
|
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
|
|
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
2021-03-01 15:53:16 +00:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
2020-06-08 04:06:41 +00:00
|
|
|
import { ActionPayload } from "../../dispatcher/payloads";
|
|
|
|
import { Action } from "../../dispatcher/actions";
|
|
|
|
import { _t } from "../../languageHandler";
|
2021-11-30 18:08:46 +00:00
|
|
|
import { ChevronFace, ContextMenuButton } from "./ContextMenu";
|
2021-06-18 11:44:15 +00:00
|
|
|
import { UserTab } from "../views/dialogs/UserSettingsDialog";
|
2020-06-08 14:20:15 +00:00
|
|
|
import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload";
|
2020-10-29 15:53:14 +00:00
|
|
|
import FeedbackDialog from "../views/dialogs/FeedbackDialog";
|
2020-06-08 15:04:43 +00:00
|
|
|
import Modal from "../../Modal";
|
|
|
|
import LogoutDialog from "../views/dialogs/LogoutDialog";
|
2020-07-28 17:53:43 +00:00
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
2021-10-28 12:01:50 +00:00
|
|
|
import { findHighContrastTheme, getCustomTheme, isHighContrastTheme } from "../../theme";
|
2021-06-29 12:11:58 +00:00
|
|
|
import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton";
|
2020-06-16 14:46:48 +00:00
|
|
|
import SdkConfig from "../../SdkConfig";
|
2021-03-01 15:53:16 +00:00
|
|
|
import { getHomePageUrl } from "../../utils/pages";
|
2020-06-24 02:59:26 +00:00
|
|
|
import { OwnProfileStore } from "../../stores/OwnProfileStore";
|
|
|
|
import { UPDATE_EVENT } from "../../stores/AsyncStore";
|
2020-06-26 01:38:11 +00:00
|
|
|
import BaseAvatar from '../views/avatars/BaseAvatar';
|
2020-07-01 00:50:31 +00:00
|
|
|
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
|
2020-07-28 17:53:43 +00:00
|
|
|
import { SettingLevel } from "../../settings/SettingLevel";
|
2020-08-04 20:42:39 +00:00
|
|
|
import IconizedContextMenu, {
|
2021-11-30 18:08:46 +00:00
|
|
|
IconizedContextMenuCheckbox,
|
2020-08-04 20:42:39 +00:00
|
|
|
IconizedContextMenuOption,
|
2020-08-29 00:11:08 +00:00
|
|
|
IconizedContextMenuOptionList,
|
2020-08-04 20:42:39 +00:00
|
|
|
} from "../views/context_menus/IconizedContextMenu";
|
2020-10-10 12:32:58 +00:00
|
|
|
import GroupFilterOrderStore from "../../stores/GroupFilterOrderStore";
|
2021-03-01 15:53:16 +00:00
|
|
|
import { UIFeature } from "../../settings/UIFeature";
|
2021-01-04 14:05:49 +00:00
|
|
|
import HostSignupAction from "./HostSignupAction";
|
2021-03-01 15:53:16 +00:00
|
|
|
import { IHostSignupConfig } from "../views/dialogs/HostSignupDialogTypes";
|
2021-11-11 13:07:41 +00:00
|
|
|
import SpaceStore from "../../stores/spaces/SpaceStore";
|
|
|
|
import { UPDATE_SELECTED_SPACE } from "../../stores/spaces";
|
2021-06-29 12:11:58 +00:00
|
|
|
import { replaceableComponent } from "../../utils/replaceableComponent";
|
2021-11-30 18:08:46 +00:00
|
|
|
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
|
|
|
import { SettingUpdatedPayload } from "../../dispatcher/payloads/SettingUpdatedPayload";
|
|
|
|
|
|
|
|
const CustomStatusSection = () => {
|
|
|
|
const cli = useContext(MatrixClientContext);
|
|
|
|
const setStatus = cli.getUser(cli.getUserId()).unstable_statusMessage || "";
|
|
|
|
const [value, setValue] = useState(setStatus);
|
|
|
|
|
|
|
|
let details: JSX.Element;
|
|
|
|
if (value !== setStatus) {
|
|
|
|
details = <>
|
|
|
|
<p>{ _t("Your status will be shown to people you have a DM with.") }</p>
|
|
|
|
|
|
|
|
<AccessibleButton
|
|
|
|
onClick={() => cli._unstable_setStatusMessage(value)}
|
|
|
|
kind="primary_outline"
|
|
|
|
>
|
|
|
|
{ value ? _t("Set status") : _t("Clear status") }
|
|
|
|
</AccessibleButton>
|
|
|
|
</>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="mx_UserMenu_CustomStatusSection">
|
|
|
|
<div className="mx_UserMenu_CustomStatusSection_input">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value={value}
|
|
|
|
onChange={e => setValue(e.target.value)}
|
|
|
|
placeholder={_t("Set a new status")}
|
|
|
|
autoComplete="off"
|
|
|
|
/>
|
|
|
|
<AccessibleButton
|
|
|
|
tabIndex={-1}
|
|
|
|
title={_t("Clear")}
|
|
|
|
className="mx_UserMenu_CustomStatusSection_clear"
|
|
|
|
onClick={() => setValue("")}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{ details }
|
|
|
|
</div>;
|
|
|
|
};
|
|
|
|
|
2020-06-08 04:06:41 +00:00
|
|
|
interface IProps {
|
2021-11-30 18:08:46 +00:00
|
|
|
isPanelCollapsed: boolean;
|
2020-06-08 04:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 22:06:26 +00:00
|
|
|
type PartialDOMRect = Pick<DOMRect, "width" | "left" | "top" | "height">;
|
|
|
|
|
2020-06-08 04:06:41 +00:00
|
|
|
interface IState {
|
2020-07-01 22:06:26 +00:00
|
|
|
contextMenuPosition: PartialDOMRect;
|
2020-06-08 15:24:08 +00:00
|
|
|
isDarkTheme: boolean;
|
2021-10-28 12:01:50 +00:00
|
|
|
isHighContrast: boolean;
|
2021-03-01 15:53:16 +00:00
|
|
|
selectedSpace?: Room;
|
2021-11-30 18:08:46 +00:00
|
|
|
dndEnabled: boolean;
|
2020-06-08 04:06:41 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
const toRightOf = (rect: PartialDOMRect) => {
|
|
|
|
return {
|
|
|
|
left: rect.width + rect.left + 8,
|
|
|
|
top: rect.top,
|
|
|
|
chevronFace: ChevronFace.None,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const below = (rect: PartialDOMRect) => {
|
|
|
|
return {
|
|
|
|
left: rect.left,
|
|
|
|
top: rect.top + rect.height,
|
|
|
|
chevronFace: ChevronFace.None,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-09 02:35:10 +00:00
|
|
|
@replaceableComponent("structures.UserMenu")
|
2020-06-26 01:29:12 +00:00
|
|
|
export default class UserMenu extends React.Component<IProps, IState> {
|
2020-06-08 04:06:41 +00:00
|
|
|
private dispatcherRef: string;
|
2020-06-08 15:24:08 +00:00
|
|
|
private themeWatcherRef: string;
|
2021-11-30 18:08:46 +00:00
|
|
|
private readonly dndWatcherRef: string;
|
2020-06-08 04:06:41 +00:00
|
|
|
private buttonRef: React.RefObject<HTMLButtonElement> = createRef();
|
2020-08-28 22:14:08 +00:00
|
|
|
private tagStoreRef: fbEmitter.EventSubscription;
|
2020-06-08 04:06:41 +00:00
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2020-07-01 22:06:26 +00:00
|
|
|
contextMenuPosition: null,
|
2020-06-08 15:24:08 +00:00
|
|
|
isDarkTheme: this.isUserOnDarkTheme(),
|
2021-10-28 12:01:50 +00:00
|
|
|
isHighContrast: this.isUserOnHighContrastTheme(),
|
2021-11-30 18:08:46 +00:00
|
|
|
dndEnabled: this.doNotDisturb,
|
2021-11-11 13:07:41 +00:00
|
|
|
selectedSpace: SpaceStore.instance.activeSpaceRoom,
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-06-24 02:59:26 +00:00
|
|
|
OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate);
|
2021-07-15 07:26:49 +00:00
|
|
|
if (SpaceStore.spacesEnabled) {
|
2021-03-01 15:53:16 +00:00
|
|
|
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
|
|
|
}
|
2021-04-15 06:47:09 +00:00
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
SettingsStore.monitorSetting("feature_dnd", null);
|
|
|
|
SettingsStore.monitorSetting("doNotDisturb", null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private get doNotDisturb(): boolean {
|
|
|
|
return SettingsStore.getValue("doNotDisturb");
|
2020-06-08 04:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 14:46:48 +00:00
|
|
|
private get hasHomePage(): boolean {
|
|
|
|
return !!getHomePageUrl(SdkConfig.get());
|
|
|
|
}
|
|
|
|
|
2020-06-08 04:06:41 +00:00
|
|
|
public componentDidMount() {
|
|
|
|
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
2020-06-08 15:24:08 +00:00
|
|
|
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
2020-10-10 12:32:58 +00:00
|
|
|
this.tagStoreRef = GroupFilterOrderStore.addListener(this.onTagStoreUpdate);
|
2020-06-08 04:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 15:24:08 +00:00
|
|
|
public componentWillUnmount() {
|
|
|
|
if (this.themeWatcherRef) SettingsStore.unwatchSetting(this.themeWatcherRef);
|
2021-04-15 06:47:09 +00:00
|
|
|
if (this.dndWatcherRef) SettingsStore.unwatchSetting(this.dndWatcherRef);
|
2020-06-08 15:24:08 +00:00
|
|
|
if (this.dispatcherRef) defaultDispatcher.unregister(this.dispatcherRef);
|
2020-06-24 02:59:26 +00:00
|
|
|
OwnProfileStore.instance.off(UPDATE_EVENT, this.onProfileUpdate);
|
2020-08-28 22:14:08 +00:00
|
|
|
this.tagStoreRef.remove();
|
2021-07-15 07:26:49 +00:00
|
|
|
if (SpaceStore.spacesEnabled) {
|
2021-03-01 15:53:16 +00:00
|
|
|
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
|
|
|
}
|
2021-05-27 07:58:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 22:14:08 +00:00
|
|
|
private onTagStoreUpdate = () => {
|
|
|
|
this.forceUpdate(); // we don't have anything useful in state to update
|
|
|
|
};
|
|
|
|
|
2020-06-08 15:24:08 +00:00
|
|
|
private isUserOnDarkTheme(): boolean {
|
2021-02-21 16:15:32 +00:00
|
|
|
if (SettingsStore.getValue("use_system_theme")) {
|
|
|
|
return window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
|
|
} else {
|
|
|
|
const theme = SettingsStore.getValue("theme");
|
|
|
|
if (theme.startsWith("custom-")) {
|
|
|
|
return getCustomTheme(theme.substring("custom-".length)).is_dark;
|
|
|
|
}
|
|
|
|
return theme === "dark";
|
2020-06-08 15:24:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 12:01:50 +00:00
|
|
|
private isUserOnHighContrastTheme(): boolean {
|
|
|
|
if (SettingsStore.getValue("use_system_theme")) {
|
|
|
|
return window.matchMedia("(prefers-contrast: more)").matches;
|
|
|
|
} else {
|
|
|
|
const theme = SettingsStore.getValue("theme");
|
|
|
|
if (theme.startsWith("custom-")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isHighContrastTheme(theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 02:59:26 +00:00
|
|
|
private onProfileUpdate = async () => {
|
|
|
|
// the store triggered an update, so force a layout update. We don't
|
|
|
|
// have any state to store here for that to magically happen.
|
|
|
|
this.forceUpdate();
|
|
|
|
};
|
|
|
|
|
2021-11-11 13:07:41 +00:00
|
|
|
private onSelectedSpaceUpdate = async () => {
|
|
|
|
this.setState({
|
|
|
|
selectedSpace: SpaceStore.instance.activeSpaceRoom,
|
|
|
|
});
|
2021-03-01 15:53:16 +00:00
|
|
|
};
|
|
|
|
|
2020-06-08 15:24:08 +00:00
|
|
|
private onThemeChanged = () => {
|
2021-10-28 12:01:50 +00:00
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
isDarkTheme: this.isUserOnDarkTheme(),
|
|
|
|
isHighContrast: this.isUserOnHighContrastTheme(),
|
|
|
|
});
|
2020-06-08 15:24:08 +00:00
|
|
|
};
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
private onAction = (payload: ActionPayload) => {
|
|
|
|
switch (payload.action) {
|
2021-05-24 14:02:26 +00:00
|
|
|
case Action.ToggleUserMenu:
|
|
|
|
if (this.state.contextMenuPosition) {
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null });
|
2021-05-24 14:02:26 +00:00
|
|
|
} else {
|
|
|
|
if (this.buttonRef.current) this.buttonRef.current.click();
|
|
|
|
}
|
|
|
|
break;
|
2020-06-08 04:06:41 +00:00
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
case Action.SettingUpdated: {
|
|
|
|
const settingUpdatedPayload = payload as SettingUpdatedPayload;
|
|
|
|
switch (settingUpdatedPayload.settingName) {
|
|
|
|
case "feature_dnd":
|
|
|
|
case "doNotDisturb": {
|
|
|
|
const dndEnabled = this.doNotDisturb;
|
|
|
|
if (this.state.dndEnabled !== dndEnabled) {
|
|
|
|
this.setState({ dndEnabled });
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-24 14:02:26 +00:00
|
|
|
}
|
2021-11-30 18:08:46 +00:00
|
|
|
};
|
2021-05-24 14:02:26 +00:00
|
|
|
|
2020-07-01 22:56:57 +00:00
|
|
|
private onOpenMenuClick = (ev: React.MouseEvent) => {
|
2020-06-08 04:06:41 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2021-11-30 18:08:46 +00:00
|
|
|
this.setState({ contextMenuPosition: ev.currentTarget.getBoundingClientRect() });
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-07-01 22:06:26 +00:00
|
|
|
private onContextMenu = (ev: React.MouseEvent) => {
|
2020-06-26 01:54:17 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2020-07-01 22:06:26 +00:00
|
|
|
this.setState({
|
|
|
|
contextMenuPosition: {
|
|
|
|
left: ev.clientX,
|
|
|
|
top: ev.clientY,
|
|
|
|
width: 20,
|
|
|
|
height: 0,
|
|
|
|
},
|
|
|
|
});
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-07-01 22:13:54 +00:00
|
|
|
private onCloseMenu = () => {
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null });
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-07-03 15:29:48 +00:00
|
|
|
private onSwitchThemeClick = (ev: React.MouseEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-06-08 15:24:08 +00:00
|
|
|
// Disable system theme matching if the user hits this button
|
|
|
|
SettingsStore.setValue("use_system_theme", null, SettingLevel.DEVICE, false);
|
|
|
|
|
2021-10-28 12:01:50 +00:00
|
|
|
let newTheme = this.state.isDarkTheme ? "light" : "dark";
|
|
|
|
if (this.state.isHighContrast) {
|
|
|
|
const hcTheme = findHighContrastTheme(newTheme);
|
|
|
|
if (hcTheme) {
|
|
|
|
newTheme = hcTheme;
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 19:34:49 +00:00
|
|
|
SettingsStore.setValue("theme", null, SettingLevel.DEVICE, newTheme); // set at same level as Appearance tab
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-06-10 21:05:29 +00:00
|
|
|
private onSettingsOpen = (ev: ButtonEvent, tabId: string) => {
|
2020-06-08 04:06:41 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2021-06-29 12:11:58 +00:00
|
|
|
const payload: OpenToTabPayload = { action: Action.ViewUserSettings, initialTabId: tabId };
|
2020-06-08 14:20:15 +00:00
|
|
|
defaultDispatcher.dispatch(payload);
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-06-10 21:05:29 +00:00
|
|
|
private onProvideFeedback = (ev: ButtonEvent) => {
|
2020-06-08 04:06:41 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-10-29 15:53:14 +00:00
|
|
|
Modal.createTrackedDialog('Feedback Dialog', '', FeedbackDialog);
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-11-09 15:50:35 +00:00
|
|
|
private onSignOutClick = async (ev: ButtonEvent) => {
|
2020-06-08 04:06:41 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-11-09 15:50:35 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
if (!cli || !cli.isCryptoEnabled() || !(await cli.exportRoomKeys())?.length) {
|
|
|
|
// log out without user prompt if they have no local megolm sessions
|
2021-06-29 12:11:58 +00:00
|
|
|
dis.dispatch({ action: 'logout' });
|
2020-11-09 15:50:35 +00:00
|
|
|
} else {
|
|
|
|
Modal.createTrackedDialog('Logout from LeftPanel', '', LogoutDialog);
|
|
|
|
}
|
|
|
|
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-11-12 12:46:55 +00:00
|
|
|
private onSignInClick = () => {
|
|
|
|
dis.dispatch({ action: 'start_login' });
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-11-12 12:46:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private onRegisterClick = () => {
|
|
|
|
dis.dispatch({ action: 'start_registration' });
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-11-12 12:46:55 +00:00
|
|
|
};
|
|
|
|
|
2020-06-16 14:46:48 +00:00
|
|
|
private onHomeClick = (ev: ButtonEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2021-06-29 12:11:58 +00:00
|
|
|
defaultDispatcher.dispatch({ action: 'view_home_page' });
|
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-16 14:46:48 +00:00
|
|
|
};
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
private onDndToggle = (ev: ButtonEvent) => {
|
2021-04-15 06:47:09 +00:00
|
|
|
ev.stopPropagation();
|
|
|
|
const current = SettingsStore.getValue("doNotDisturb");
|
|
|
|
SettingsStore.setValue("doNotDisturb", null, SettingLevel.DEVICE, !current);
|
|
|
|
};
|
|
|
|
|
2020-06-26 01:54:17 +00:00
|
|
|
private renderContextMenu = (): React.ReactNode => {
|
2020-07-01 22:06:26 +00:00
|
|
|
if (!this.state.contextMenuPosition) return null;
|
2020-06-26 01:54:17 +00:00
|
|
|
|
2020-11-12 12:46:55 +00:00
|
|
|
let topSection;
|
2021-01-15 13:32:30 +00:00
|
|
|
const hostSignupConfig: IHostSignupConfig = SdkConfig.get().hostSignup;
|
2020-11-12 12:46:55 +00:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
topSection = (
|
|
|
|
<div className="mx_UserMenu_contextMenu_header mx_UserMenu_contextMenu_guestPrompts">
|
2021-07-19 21:43:11 +00:00
|
|
|
{ _t("Got an account? <a>Sign in</a>", {}, {
|
2020-11-12 12:46:55 +00:00
|
|
|
a: sub => (
|
|
|
|
<AccessibleButton kind="link" onClick={this.onSignInClick}>
|
2021-07-19 21:43:11 +00:00
|
|
|
{ sub }
|
2020-11-12 12:46:55 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-07-19 21:43:11 +00:00
|
|
|
}) }
|
|
|
|
{ _t("New here? <a>Create an account</a>", {}, {
|
2020-11-12 12:46:55 +00:00
|
|
|
a: sub => (
|
|
|
|
<AccessibleButton kind="link" onClick={this.onRegisterClick}>
|
2021-07-19 21:43:11 +00:00
|
|
|
{ sub }
|
2020-11-12 12:46:55 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
),
|
2021-07-19 21:43:11 +00:00
|
|
|
}) }
|
2020-11-12 12:46:55 +00:00
|
|
|
</div>
|
2021-06-29 12:11:58 +00:00
|
|
|
);
|
2021-02-09 18:01:45 +00:00
|
|
|
} else if (hostSignupConfig) {
|
2021-01-04 14:05:49 +00:00
|
|
|
if (hostSignupConfig && hostSignupConfig.url) {
|
2021-01-15 13:32:30 +00:00
|
|
|
// If hostSignup.domains is set to a non-empty array, only show
|
2020-11-27 11:18:16 +00:00
|
|
|
// dialog if the user is on the domain or a subdomain.
|
2021-01-04 14:05:49 +00:00
|
|
|
const hostSignupDomains = hostSignupConfig.domains || [];
|
2020-11-27 11:18:16 +00:00
|
|
|
const mxDomain = MatrixClientPeg.get().getDomain();
|
2021-01-04 14:05:49 +00:00
|
|
|
const validDomains = hostSignupDomains.filter(d => (d === mxDomain || mxDomain.endsWith(`.${d}`)));
|
2021-02-15 17:38:11 +00:00
|
|
|
if (!hostSignupConfig.domains || validDomains.length > 0) {
|
2021-06-08 16:31:08 +00:00
|
|
|
topSection = <HostSignupAction onClick={this.onCloseMenu} />;
|
2020-11-27 11:18:16 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-08 04:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 01:54:17 +00:00
|
|
|
let homeButton = null;
|
|
|
|
if (this.hasHomePage) {
|
|
|
|
homeButton = (
|
2020-08-04 20:42:39 +00:00
|
|
|
<IconizedContextMenuOption
|
2020-07-03 13:34:43 +00:00
|
|
|
iconClassName="mx_UserMenu_iconHome"
|
|
|
|
label={_t("Home")}
|
|
|
|
onClick={this.onHomeClick}
|
|
|
|
/>
|
2020-06-26 01:54:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
let customStatusSection: JSX.Element;
|
|
|
|
if (SettingsStore.getValue("feature_custom_status")) {
|
|
|
|
customStatusSection = <CustomStatusSection />;
|
|
|
|
}
|
|
|
|
|
|
|
|
let dndButton: JSX.Element;
|
|
|
|
if (SettingsStore.getValue("feature_dnd")) {
|
|
|
|
dndButton = (
|
|
|
|
<IconizedContextMenuCheckbox
|
|
|
|
iconClassName={this.state.dndEnabled ? "mx_UserMenu_iconDnd" : "mx_UserMenu_iconDndOff"}
|
|
|
|
label={_t("Do not disturb")}
|
|
|
|
onClick={this.onDndToggle}
|
|
|
|
active={this.state.dndEnabled}
|
|
|
|
words
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-16 09:59:14 +00:00
|
|
|
let feedbackButton;
|
|
|
|
if (SettingsStore.getValue(UIFeature.Feedback)) {
|
|
|
|
feedbackButton = <IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconMessage"
|
|
|
|
label={_t("Feedback")}
|
|
|
|
onClick={this.onProvideFeedback}
|
|
|
|
/>;
|
|
|
|
}
|
|
|
|
|
2020-08-28 23:03:17 +00:00
|
|
|
let primaryOptionList = (
|
2021-11-30 18:08:46 +00:00
|
|
|
<IconizedContextMenuOptionList>
|
|
|
|
{ homeButton }
|
|
|
|
{ dndButton }
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconBell"
|
|
|
|
label={_t("Notifications")}
|
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.Notifications)}
|
|
|
|
/>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconLock"
|
|
|
|
label={_t("Security & privacy")}
|
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.Security)}
|
|
|
|
/>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
|
|
|
label={_t("All settings")}
|
|
|
|
onClick={(e) => this.onSettingsOpen(e, null)}
|
|
|
|
/>
|
|
|
|
{ feedbackButton }
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
className="mx_IconizedContextMenu_option_red"
|
|
|
|
iconClassName="mx_UserMenu_iconSignOut"
|
|
|
|
label={_t("Sign out")}
|
|
|
|
onClick={this.onSignOutClick}
|
|
|
|
/>
|
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
primaryOptionList = (
|
2020-08-28 23:03:17 +00:00
|
|
|
<IconizedContextMenuOptionList>
|
2021-07-19 21:43:11 +00:00
|
|
|
{ homeButton }
|
2020-08-28 23:03:17 +00:00
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
2021-11-30 18:08:46 +00:00
|
|
|
label={_t("Settings")}
|
2020-08-28 23:03:17 +00:00
|
|
|
onClick={(e) => this.onSettingsOpen(e, null)}
|
|
|
|
/>
|
2020-09-16 09:59:14 +00:00
|
|
|
{ feedbackButton }
|
2020-08-28 23:03:17 +00:00
|
|
|
</IconizedContextMenuOptionList>
|
2020-11-12 12:46:55 +00:00
|
|
|
);
|
2020-08-28 23:03:17 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
const position = this.props.isPanelCollapsed
|
|
|
|
? toRightOf(this.state.contextMenuPosition)
|
|
|
|
: below(this.state.contextMenuPosition);
|
2020-08-28 23:03:17 +00:00
|
|
|
|
2020-08-04 20:42:39 +00:00
|
|
|
return <IconizedContextMenu
|
2021-11-30 18:08:46 +00:00
|
|
|
{...position}
|
2020-08-04 20:42:39 +00:00
|
|
|
onFinished={this.onCloseMenu}
|
2021-11-30 18:08:46 +00:00
|
|
|
className="mx_UserMenu_contextMenu"
|
2020-08-04 20:42:39 +00:00
|
|
|
>
|
|
|
|
<div className="mx_UserMenu_contextMenu_header">
|
2021-11-30 18:08:46 +00:00
|
|
|
<div className="mx_UserMenu_contextMenu_name">
|
|
|
|
<span className="mx_UserMenu_contextMenu_displayName">
|
|
|
|
{ OwnProfileStore.instance.displayName }
|
|
|
|
</span>
|
|
|
|
<span className="mx_UserMenu_contextMenu_userId">
|
|
|
|
{ MatrixClientPeg.get().getUserId() }
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
|
2020-08-04 20:42:39 +00:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_UserMenu_contextMenu_themeButton"
|
|
|
|
onClick={this.onSwitchThemeClick}
|
|
|
|
title={this.state.isDarkTheme ? _t("Switch to light mode") : _t("Switch to dark mode")}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
src={require("../../../res/img/element-icons/roomlist/dark-light-mode.svg")}
|
|
|
|
alt={_t("Switch theme")}
|
|
|
|
width={16}
|
|
|
|
/>
|
|
|
|
</AccessibleTooltipButton>
|
|
|
|
</div>
|
2021-11-30 18:08:46 +00:00
|
|
|
{ customStatusSection }
|
2021-07-19 21:43:11 +00:00
|
|
|
{ topSection }
|
|
|
|
{ primaryOptionList }
|
2020-08-04 20:42:39 +00:00
|
|
|
</IconizedContextMenu>;
|
2020-06-26 01:54:17 +00:00
|
|
|
};
|
2020-06-26 01:38:11 +00:00
|
|
|
|
|
|
|
public render() {
|
|
|
|
const avatarSize = 32; // should match border-radius of the avatar
|
|
|
|
|
2020-10-21 13:11:39 +00:00
|
|
|
const userId = MatrixClientPeg.get().getUserId();
|
|
|
|
const displayName = OwnProfileStore.instance.displayName || userId;
|
2020-08-25 20:23:18 +00:00
|
|
|
const avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize);
|
2020-08-21 01:45:54 +00:00
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
let badge: JSX.Element;
|
|
|
|
if (this.state.dndEnabled) {
|
|
|
|
badge = <div className="mx_UserMenu_dndBadge" />;
|
2020-06-26 01:38:11 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
let name: JSX.Element;
|
|
|
|
if (!this.props.isPanelCollapsed) {
|
|
|
|
name = <div className="mx_UserMenu_name">
|
|
|
|
{ displayName }
|
|
|
|
</div>;
|
|
|
|
}
|
2020-06-26 01:54:17 +00:00
|
|
|
|
2021-12-07 09:32:00 +00:00
|
|
|
return <div className="mx_UserMenu">
|
2021-11-30 18:08:46 +00:00
|
|
|
<ContextMenuButton
|
|
|
|
onClick={this.onOpenMenuClick}
|
|
|
|
inputRef={this.buttonRef}
|
|
|
|
label={_t("User menu")}
|
|
|
|
isExpanded={!!this.state.contextMenuPosition}
|
|
|
|
onContextMenu={this.onContextMenu}
|
2021-12-07 09:32:00 +00:00
|
|
|
className={classNames({
|
2021-11-30 18:08:46 +00:00
|
|
|
mx_UserMenu_cutout: badge,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className="mx_UserMenu_userAvatar">
|
|
|
|
<BaseAvatar
|
|
|
|
idName={userId}
|
|
|
|
name={displayName}
|
|
|
|
url={avatarUrl}
|
|
|
|
width={avatarSize}
|
|
|
|
height={avatarSize}
|
|
|
|
resizeMethod="crop"
|
|
|
|
className="mx_UserMenu_userAvatar_BaseAvatar"
|
|
|
|
/>
|
|
|
|
{ badge }
|
|
|
|
</div>
|
|
|
|
{ name }
|
|
|
|
|
2021-07-19 21:43:11 +00:00
|
|
|
{ this.renderContextMenu() }
|
2021-11-30 18:08:46 +00:00
|
|
|
</ContextMenuButton>
|
2021-12-07 09:32:00 +00:00
|
|
|
|
|
|
|
{ this.props.children }
|
|
|
|
</div>;
|
2020-06-26 01:38:11 +00:00
|
|
|
}
|
2020-06-08 04:06:41 +00:00
|
|
|
}
|