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.
|
|
|
|
*/
|
|
|
|
|
2022-05-06 18:39:03 +00:00
|
|
|
import React, { createRef } from "react";
|
2021-03-01 15:53:16 +00:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
|
2020-06-08 04:06:41 +00:00
|
|
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
|
|
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
|
|
|
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";
|
2022-03-24 22:42:53 +00:00
|
|
|
import { UserTab } from "../views/dialogs/UserTab";
|
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-12-17 17:08:56 +00:00
|
|
|
import { RovingAccessibleTooltipButton } from "../../accessibility/RovingTabIndex";
|
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-28 17:53:43 +00:00
|
|
|
import { SettingLevel } from "../../settings/SettingLevel";
|
2020-08-04 20:42:39 +00:00
|
|
|
import IconizedContextMenu, {
|
|
|
|
IconizedContextMenuOption,
|
2020-08-29 00:11:08 +00:00
|
|
|
IconizedContextMenuOptionList,
|
2020-08-04 20:42:39 +00:00
|
|
|
} from "../views/context_menus/IconizedContextMenu";
|
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-11-11 13:07:41 +00:00
|
|
|
import SpaceStore from "../../stores/spaces/SpaceStore";
|
|
|
|
import { UPDATE_SELECTED_SPACE } from "../../stores/spaces";
|
2022-01-25 09:40:02 +00:00
|
|
|
import UserIdentifierCustomisations from "../../customisations/UserIdentifier";
|
2022-02-10 13:53:07 +00:00
|
|
|
import PosthogTrackers from "../../PosthogTrackers";
|
2022-02-22 10:04:27 +00:00
|
|
|
import { ViewHomePagePayload } from "../../dispatcher/payloads/ViewHomePagePayload";
|
2022-11-18 07:36:20 +00:00
|
|
|
import { Icon as LiveIcon } from "../../../res/img/element-icons/live.svg";
|
|
|
|
import {
|
|
|
|
VoiceBroadcastRecording,
|
|
|
|
VoiceBroadcastRecordingsStore,
|
|
|
|
VoiceBroadcastRecordingsStoreEvent,
|
|
|
|
} from "../../voice-broadcast";
|
2021-11-30 18:08:46 +00:00
|
|
|
|
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 {
|
2022-11-18 07:36:20 +00:00
|
|
|
contextMenuPosition: PartialDOMRect | null;
|
2020-06-08 15:24:08 +00:00
|
|
|
isDarkTheme: boolean;
|
2021-10-28 12:01:50 +00:00
|
|
|
isHighContrast: boolean;
|
2022-11-18 07:36:20 +00:00
|
|
|
selectedSpace?: Room | null;
|
|
|
|
showLiveAvatarAddon: 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,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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();
|
2022-11-18 07:36:20 +00:00
|
|
|
private voiceBroadcastRecordingStore = VoiceBroadcastRecordingsStore.instance();
|
2020-06-08 04:06:41 +00:00
|
|
|
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props: IProps) {
|
2020-06-08 04:06:41 +00:00
|
|
|
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-11 13:07:41 +00:00
|
|
|
selectedSpace: SpaceStore.instance.activeSpaceRoom,
|
2022-11-18 07:36:20 +00:00
|
|
|
showLiveAvatarAddon: this.voiceBroadcastRecordingStore.hasCurrent(),
|
2020-06-08 04:06:41 +00:00
|
|
|
};
|
|
|
|
|
2020-06-24 02:59:26 +00:00
|
|
|
OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate);
|
2022-03-22 23:07:37 +00:00
|
|
|
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
2020-06-08 04:06:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 14:46:48 +00:00
|
|
|
private get hasHomePage(): boolean {
|
|
|
|
return !!getHomePageUrl(SdkConfig.get());
|
|
|
|
}
|
|
|
|
|
2022-11-18 07:36:20 +00:00
|
|
|
private onCurrentVoiceBroadcastRecordingChanged = (recording: VoiceBroadcastRecording): void => {
|
|
|
|
this.setState({
|
|
|
|
showLiveAvatarAddon: recording !== null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-06-08 04:06:41 +00:00
|
|
|
public componentDidMount() {
|
2022-11-18 07:36:20 +00:00
|
|
|
this.voiceBroadcastRecordingStore.on(
|
|
|
|
VoiceBroadcastRecordingsStoreEvent.CurrentChanged,
|
|
|
|
this.onCurrentVoiceBroadcastRecordingChanged,
|
|
|
|
);
|
2020-06-08 04:06:41 +00:00
|
|
|
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
2020-06-08 15:24:08 +00:00
|
|
|
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
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);
|
2022-03-22 23:07:37 +00:00
|
|
|
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
2022-11-18 07:36:20 +00:00
|
|
|
this.voiceBroadcastRecordingStore.off(
|
|
|
|
VoiceBroadcastRecordingsStoreEvent.CurrentChanged,
|
|
|
|
this.onCurrentVoiceBroadcastRecordingChanged,
|
|
|
|
);
|
2021-05-27 07:58:11 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
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();
|
|
|
|
|
2022-02-10 13:53:07 +00:00
|
|
|
PosthogTrackers.trackInteraction("WebUserMenuThemeToggleButton", ev);
|
|
|
|
|
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();
|
|
|
|
|
2022-06-14 16:51:51 +00:00
|
|
|
Modal.createDialog(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
|
2022-05-03 21:04:37 +00:00
|
|
|
defaultDispatcher.dispatch({ action: "logout" });
|
2020-11-09 15:50:35 +00:00
|
|
|
} else {
|
2022-06-14 16:51:51 +00:00
|
|
|
Modal.createDialog(LogoutDialog);
|
2020-11-09 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
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 = () => {
|
2022-05-03 21:04:37 +00:00
|
|
|
defaultDispatcher.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 = () => {
|
2022-05-03 21:04:37 +00:00
|
|
|
defaultDispatcher.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();
|
|
|
|
|
2022-02-22 10:04:27 +00:00
|
|
|
defaultDispatcher.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
|
2021-06-29 12:11:58 +00:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-16 14:46:48 +00:00
|
|
|
};
|
|
|
|
|
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;
|
2022-03-18 16:12:36 +00:00
|
|
|
const hostSignupConfig = SdkConfig.getObject("host_signup");
|
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) => (
|
2022-06-29 22:37:34 +00:00
|
|
|
<AccessibleButton kind="link_inline" 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
|
|
|
},
|
2022-12-12 11:24:14 +00:00
|
|
|
)}
|
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) => (
|
2022-06-29 22:37:34 +00:00
|
|
|
<AccessibleButton kind="link_inline" 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
|
|
|
);
|
2022-03-18 16:12:36 +00:00
|
|
|
} else if (hostSignupConfig?.get("url")) {
|
|
|
|
// If hostSignup.domains is set to a non-empty array, only show
|
|
|
|
// dialog if the user is on the domain or a subdomain.
|
|
|
|
const hostSignupDomains = hostSignupConfig.get("domains") || [];
|
|
|
|
const mxDomain = MatrixClientPeg.get().getDomain();
|
|
|
|
const validDomains = hostSignupDomains.filter((d) => d === mxDomain || mxDomain.endsWith(`.${d}`));
|
|
|
|
if (!hostSignupConfig.get("domains") || validDomains.length > 0) {
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconBell"
|
|
|
|
label={_t("Notifications")}
|
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.Notifications)}
|
|
|
|
/>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconLock"
|
2022-02-08 08:31:51 +00:00
|
|
|
label={_t("Security & Privacy")}
|
2021-11-30 18:08:46 +00:00
|
|
|
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 (
|
2021-11-30 18:08:46 +00:00
|
|
|
<IconizedContextMenu {...position} onFinished={this.onCloseMenu} 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">
|
2022-01-25 09:40:02 +00:00
|
|
|
{UserIdentifierCustomisations.getDisplayUserIdentifier(MatrixClientPeg.get().getUserId(), {
|
|
|
|
withDisplayName: true,
|
|
|
|
})}
|
2021-11-30 18:08:46 +00:00
|
|
|
</span>
|
2022-12-12 11:24:14 +00:00
|
|
|
</div>
|
|
|
|
|
2021-12-17 17:08:56 +00:00
|
|
|
<RovingAccessibleTooltipButton
|
2020-08-04 20:42:39 +00:00
|
|
|
className="mx_UserMenu_contextMenu_themeButton"
|
|
|
|
onClick={this.onSwitchThemeClick}
|
|
|
|
title={this.state.isDarkTheme ? _t("Switch to light mode") : _t("Switch to dark mode")}
|
2022-12-12 11:24:14 +00:00
|
|
|
>
|
|
|
|
<img
|
2022-03-03 17:51:38 +00:00
|
|
|
src={require("../../../res/img/element-icons/roomlist/dark-light-mode.svg").default}
|
2020-08-04 20:42:39 +00:00
|
|
|
alt={_t("Switch theme")}
|
|
|
|
width={16}
|
2022-12-12 11:24:14 +00:00
|
|
|
/>
|
2021-12-17 17:08:56 +00:00
|
|
|
</RovingAccessibleTooltipButton>
|
2021-11-30 18:08:46 +00:00
|
|
|
</div>
|
2020-08-04 20:42:39 +00:00
|
|
|
{topSection}
|
2021-07-19 21:43:11 +00:00
|
|
|
{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 name: JSX.Element;
|
|
|
|
if (!this.props.isPanelCollapsed) {
|
|
|
|
name = <div className="mx_UserMenu_name">{displayName}</div>;
|
|
|
|
}
|
2020-06-26 01:54:17 +00:00
|
|
|
|
2022-11-18 07:36:20 +00:00
|
|
|
const liveAvatarAddon = this.state.showLiveAvatarAddon ? (
|
|
|
|
<div className="mx_UserMenu_userAvatarLive" data-testid="user-menu-live-vb">
|
|
|
|
<LiveIcon className="mx_Icon_8" />
|
|
|
|
</div>
|
|
|
|
) : null;
|
2022-12-12 11:24:14 +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}
|
|
|
|
>
|
|
|
|
<div className="mx_UserMenu_userAvatar">
|
|
|
|
<BaseAvatar
|
|
|
|
idName={userId}
|
|
|
|
name={displayName}
|
|
|
|
url={avatarUrl}
|
|
|
|
width={avatarSize}
|
|
|
|
height={avatarSize}
|
|
|
|
resizeMethod="crop"
|
|
|
|
className="mx_UserMenu_userAvatar_BaseAvatar"
|
|
|
|
/>
|
2022-11-18 07:36:20 +00:00
|
|
|
{liveAvatarAddon}
|
2021-11-30 18:08:46 +00:00
|
|
|
</div>
|
|
|
|
{name}
|
2021-07-19 21:43:11 +00:00
|
|
|
{this.renderContextMenu()}
|
2021-11-30 18:08:46 +00:00
|
|
|
</ContextMenuButton>
|
2022-12-12 11:24:14 +00:00
|
|
|
|
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
|
|
|
}
|