2020-06-07 22:06:41 -06:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2021-01-05 14:29:48 +02:00
|
|
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
2020-06-07 22:06:41 -06:00
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-06-07 22:06:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2023-03-08 13:28:07 +00:00
|
|
|
import React, { createRef, ReactNode } from "react";
|
2024-10-15 10:18:57 +01:00
|
|
|
import { Room } from "matrix-js-sdk/src/matrix";
|
2021-03-01 15:53:16 +00:00
|
|
|
|
2020-06-07 22:06:41 -06:00
|
|
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
|
|
|
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
|
|
|
|
import { ActionPayload } from "../../dispatcher/payloads";
|
|
|
|
|
import { Action } from "../../dispatcher/actions";
|
|
|
|
|
import { _t } from "../../languageHandler";
|
2023-01-12 13:25:14 +00:00
|
|
|
import { ChevronFace, ContextMenuButton, MenuProps } from "./ContextMenu";
|
2022-03-24 16:42:53 -06:00
|
|
|
import { UserTab } from "../views/dialogs/UserTab";
|
2020-06-08 08:20:15 -06:00
|
|
|
import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload";
|
2020-10-29 15:53:14 +00:00
|
|
|
import FeedbackDialog from "../views/dialogs/FeedbackDialog";
|
2020-06-08 09:04:43 -06:00
|
|
|
import Modal from "../../Modal";
|
2024-07-29 13:53:44 +01:00
|
|
|
import LogoutDialog, { shouldShowLogoutDialog } from "../views/dialogs/LogoutDialog";
|
2020-07-28 11:53:43 -06:00
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
2021-10-28 13:01:50 +01:00
|
|
|
import { findHighContrastTheme, getCustomTheme, isHighContrastTheme } from "../../theme";
|
2024-05-17 12:29:30 +02:00
|
|
|
import { RovingAccessibleButton } from "../../accessibility/RovingTabIndex";
|
2021-06-29 13:11:58 +01:00
|
|
|
import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton";
|
2020-06-16 08:46:48 -06:00
|
|
|
import SdkConfig from "../../SdkConfig";
|
2021-03-01 15:53:16 +00:00
|
|
|
import { getHomePageUrl } from "../../utils/pages";
|
2020-06-23 20:59:26 -06:00
|
|
|
import { OwnProfileStore } from "../../stores/OwnProfileStore";
|
|
|
|
|
import { UPDATE_EVENT } from "../../stores/AsyncStore";
|
2020-06-25 19:38:11 -06:00
|
|
|
import BaseAvatar from "../views/avatars/BaseAvatar";
|
2020-07-28 11:53:43 -06:00
|
|
|
import { SettingLevel } from "../../settings/SettingLevel";
|
2020-08-04 21:42:39 +01:00
|
|
|
import IconizedContextMenu, {
|
|
|
|
|
IconizedContextMenuOption,
|
2020-08-29 01:11:08 +01:00
|
|
|
IconizedContextMenuOptionList,
|
2020-08-04 21:42:39 +01:00
|
|
|
} from "../views/context_menus/IconizedContextMenu";
|
2021-03-01 15:53:16 +00:00
|
|
|
import { UIFeature } from "../../settings/UIFeature";
|
2021-11-11 13:07:41 +00:00
|
|
|
import SpaceStore from "../../stores/spaces/SpaceStore";
|
|
|
|
|
import { UPDATE_SELECTED_SPACE } from "../../stores/spaces";
|
2022-01-25 10:40:02 +01:00
|
|
|
import UserIdentifierCustomisations from "../../customisations/UserIdentifier";
|
2022-02-10 13:53:07 +00:00
|
|
|
import PosthogTrackers from "../../PosthogTrackers";
|
2022-02-22 11:04:27 +01:00
|
|
|
import { ViewHomePagePayload } from "../../dispatcher/payloads/ViewHomePagePayload";
|
2023-03-08 11:11:01 +01:00
|
|
|
import { Icon as LiveIcon } from "../../../res/img/compound/live-8px.svg";
|
2022-12-27 08:39:26 +01:00
|
|
|
import { VoiceBroadcastRecording, VoiceBroadcastRecordingsStoreEvent } from "../../voice-broadcast";
|
|
|
|
|
import { SDKContext } from "../../contexts/SDKContext";
|
2023-04-05 12:17:25 +01:00
|
|
|
import { shouldShowFeedback } from "../../utils/Feedback";
|
2024-10-16 16:43:07 +01:00
|
|
|
import DarkLightModeSvg from "../../../res/img/element-icons/roomlist/dark-light-mode.svg";
|
2021-11-30 18:08:46 +00:00
|
|
|
|
2020-06-07 22:06:41 -06:00
|
|
|
interface IProps {
|
2021-11-30 18:08:46 +00:00
|
|
|
isPanelCollapsed: boolean;
|
2023-03-08 13:28:07 +00:00
|
|
|
children?: ReactNode;
|
2020-06-07 22:06:41 -06:00
|
|
|
}
|
|
|
|
|
|
2020-07-01 23:06:26 +01:00
|
|
|
type PartialDOMRect = Pick<DOMRect, "width" | "left" | "top" | "height">;
|
|
|
|
|
|
2020-06-07 22:06:41 -06:00
|
|
|
interface IState {
|
2022-11-18 08:36:20 +01:00
|
|
|
contextMenuPosition: PartialDOMRect | null;
|
2020-06-08 09:24:08 -06:00
|
|
|
isDarkTheme: boolean;
|
2021-10-28 13:01:50 +01:00
|
|
|
isHighContrast: boolean;
|
2022-11-18 08:36:20 +01:00
|
|
|
selectedSpace?: Room | null;
|
|
|
|
|
showLiveAvatarAddon: boolean;
|
2020-06-07 22:06:41 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const toRightOf = (rect: PartialDOMRect): MenuProps => {
|
2021-11-30 18:08:46 +00:00
|
|
|
return {
|
|
|
|
|
left: rect.width + rect.left + 8,
|
|
|
|
|
top: rect.top,
|
|
|
|
|
chevronFace: ChevronFace.None,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const below = (rect: PartialDOMRect): MenuProps => {
|
2021-11-30 18:08:46 +00:00
|
|
|
return {
|
|
|
|
|
left: rect.left,
|
|
|
|
|
top: rect.top + rect.height,
|
|
|
|
|
chevronFace: ChevronFace.None,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-25 19:29:12 -06:00
|
|
|
export default class UserMenu extends React.Component<IProps, IState> {
|
2022-12-27 08:39:26 +01:00
|
|
|
public static contextType = SDKContext;
|
2024-08-01 17:14:28 +01:00
|
|
|
public declare context: React.ContextType<typeof SDKContext>;
|
2022-12-27 08:39:26 +01:00
|
|
|
|
2023-05-10 08:41:55 +01:00
|
|
|
private dispatcherRef?: string;
|
|
|
|
|
private themeWatcherRef?: string;
|
|
|
|
|
private readonly dndWatcherRef?: string;
|
2020-06-07 22:06:41 -06:00
|
|
|
private buttonRef: React.RefObject<HTMLButtonElement> = createRef();
|
|
|
|
|
|
2022-12-27 08:39:26 +01:00
|
|
|
public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
|
|
|
|
|
super(props, context);
|
2020-06-07 22:06:41 -06:00
|
|
|
|
|
|
|
|
this.state = {
|
2020-07-01 23:06:26 +01:00
|
|
|
contextMenuPosition: null,
|
2020-06-08 09:24:08 -06:00
|
|
|
isDarkTheme: this.isUserOnDarkTheme(),
|
2021-10-28 13:01:50 +01:00
|
|
|
isHighContrast: this.isUserOnHighContrastTheme(),
|
2021-11-11 13:07:41 +00:00
|
|
|
selectedSpace: SpaceStore.instance.activeSpaceRoom,
|
2022-12-27 08:39:26 +01:00
|
|
|
showLiveAvatarAddon: this.context.voiceBroadcastRecordingsStore.hasCurrent(),
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 08:46:48 -06:00
|
|
|
private get hasHomePage(): boolean {
|
2023-05-23 16:24:12 +01:00
|
|
|
return !!getHomePageUrl(SdkConfig.get(), this.context.client!);
|
2020-06-16 08:46:48 -06:00
|
|
|
}
|
|
|
|
|
|
2023-05-12 09:49:37 +01:00
|
|
|
private onCurrentVoiceBroadcastRecordingChanged = (recording: VoiceBroadcastRecording | null): void => {
|
2022-11-18 08:36:20 +01:00
|
|
|
this.setState({
|
|
|
|
|
showLiveAvatarAddon: recording !== null,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentDidMount(): void {
|
2024-11-01 17:39:08 +00:00
|
|
|
OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate);
|
|
|
|
|
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
2022-12-27 08:39:26 +01:00
|
|
|
this.context.voiceBroadcastRecordingsStore.on(
|
2022-11-18 08:36:20 +01:00
|
|
|
VoiceBroadcastRecordingsStoreEvent.CurrentChanged,
|
|
|
|
|
this.onCurrentVoiceBroadcastRecordingChanged,
|
|
|
|
|
);
|
2020-06-07 22:06:41 -06:00
|
|
|
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
2020-06-08 09:24:08 -06:00
|
|
|
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
2020-06-07 22:06:41 -06:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public componentWillUnmount(): void {
|
2024-11-01 15:15:04 +00:00
|
|
|
SettingsStore.unwatchSetting(this.themeWatcherRef);
|
|
|
|
|
SettingsStore.unwatchSetting(this.dndWatcherRef);
|
|
|
|
|
defaultDispatcher.unregister(this.dispatcherRef);
|
2020-06-23 20:59:26 -06:00
|
|
|
OwnProfileStore.instance.off(UPDATE_EVENT, this.onProfileUpdate);
|
2022-03-22 17:07:37 -06:00
|
|
|
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
2022-12-27 08:39:26 +01:00
|
|
|
this.context.voiceBroadcastRecordingsStore.off(
|
2022-11-18 08:36:20 +01:00
|
|
|
VoiceBroadcastRecordingsStoreEvent.CurrentChanged,
|
|
|
|
|
this.onCurrentVoiceBroadcastRecordingChanged,
|
|
|
|
|
);
|
2021-05-27 08:58:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-08 09:24:08 -06: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-")) {
|
2023-03-10 14:55:06 +00:00
|
|
|
return !!getCustomTheme(theme.substring("custom-".length)).is_dark;
|
2021-02-21 16:15:32 +00:00
|
|
|
}
|
|
|
|
|
return theme === "dark";
|
2020-06-08 09:24:08 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 13:01:50 +01: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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onProfileUpdate = async (): Promise<void> => {
|
2020-06-23 20:59:26 -06:00
|
|
|
// 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();
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onSelectedSpaceUpdate = async (): Promise<void> => {
|
2021-11-11 13:07:41 +00:00
|
|
|
this.setState({
|
|
|
|
|
selectedSpace: SpaceStore.instance.activeSpaceRoom,
|
|
|
|
|
});
|
2021-03-01 15:53:16 +00:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onThemeChanged = (): void => {
|
2021-10-28 13:01:50 +01:00
|
|
|
this.setState({
|
|
|
|
|
isDarkTheme: this.isUserOnDarkTheme(),
|
|
|
|
|
isHighContrast: this.isUserOnHighContrastTheme(),
|
|
|
|
|
});
|
2020-06-08 09:24:08 -06:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onAction = (payload: ActionPayload): void => {
|
2021-11-30 18:08:46 +00:00
|
|
|
switch (payload.action) {
|
2021-05-24 15:02:26 +01:00
|
|
|
case Action.ToggleUserMenu:
|
|
|
|
|
if (this.state.contextMenuPosition) {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null });
|
2021-05-24 15:02:26 +01:00
|
|
|
} else {
|
|
|
|
|
if (this.buttonRef.current) this.buttonRef.current.click();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2020-07-03 14:34:43 +01:00
|
|
|
}
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2023-05-12 09:49:37 +01:00
|
|
|
private onOpenMenuClick = (ev: ButtonEvent): void => {
|
2020-06-07 22:06:41 -06:00
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
2021-11-30 18:08:46 +00:00
|
|
|
this.setState({ contextMenuPosition: ev.currentTarget.getBoundingClientRect() });
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onContextMenu = (ev: React.MouseEvent): void => {
|
2020-06-25 19:54:17 -06:00
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
2020-07-01 23:06:26 +01:00
|
|
|
this.setState({
|
|
|
|
|
contextMenuPosition: {
|
|
|
|
|
left: ev.clientX,
|
|
|
|
|
top: ev.clientY,
|
|
|
|
|
width: 20,
|
|
|
|
|
height: 0,
|
|
|
|
|
},
|
|
|
|
|
});
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onCloseMenu = (): void => {
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null });
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2023-05-12 09:49:37 +01:00
|
|
|
private onSwitchThemeClick = (ev: ButtonEvent): void => {
|
2020-07-03 16:29:48 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
2022-02-10 13:53:07 +00:00
|
|
|
PosthogTrackers.trackInteraction("WebUserMenuThemeToggleButton", ev);
|
|
|
|
|
|
2020-06-08 09:24:08 -06:00
|
|
|
// Disable system theme matching if the user hits this button
|
|
|
|
|
SettingsStore.setValue("use_system_theme", null, SettingLevel.DEVICE, false);
|
|
|
|
|
|
2021-10-28 13:01:50 +01:00
|
|
|
let newTheme = this.state.isDarkTheme ? "light" : "dark";
|
|
|
|
|
if (this.state.isHighContrast) {
|
|
|
|
|
const hcTheme = findHighContrastTheme(newTheme);
|
|
|
|
|
if (hcTheme) {
|
|
|
|
|
newTheme = hcTheme;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-22 13:34:49 -06:00
|
|
|
SettingsStore.setValue("theme", null, SettingLevel.DEVICE, newTheme); // set at same level as Appearance tab
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2024-06-06 09:57:28 +01:00
|
|
|
private onSettingsOpen = (ev: ButtonEvent, tabId?: string, props?: Record<string, any>): void => {
|
2020-06-07 22:06:41 -06:00
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
2024-06-06 09:57:28 +01:00
|
|
|
const payload: OpenToTabPayload = { action: Action.ViewUserSettings, initialTabId: tabId, props };
|
2020-06-08 08:20:15 -06:00
|
|
|
defaultDispatcher.dispatch(payload);
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onProvideFeedback = (ev: ButtonEvent): void => {
|
2020-06-07 22:06:41 -06:00
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
2022-06-14 17:51:51 +01:00
|
|
|
Modal.createDialog(FeedbackDialog);
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onSignOutClick = async (ev: ButtonEvent): Promise<void> => {
|
2020-06-07 22:06:41 -06:00
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
2024-07-29 13:53:44 +01:00
|
|
|
if (await shouldShowLogoutDialog(MatrixClientPeg.safeGet())) {
|
2022-06-14 17:51:51 +01:00
|
|
|
Modal.createDialog(LogoutDialog);
|
2024-02-02 12:43:59 +01:00
|
|
|
} else {
|
|
|
|
|
defaultDispatcher.dispatch({ action: "logout" });
|
2020-11-09 15:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-07 22:06:41 -06:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onSignInClick = (): void => {
|
2022-05-03 22:04:37 +01:00
|
|
|
defaultDispatcher.dispatch({ action: "start_login" });
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-11-12 12:46:55 +00:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onRegisterClick = (): void => {
|
2022-05-03 22:04:37 +01:00
|
|
|
defaultDispatcher.dispatch({ action: "start_registration" });
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-11-12 12:46:55 +00:00
|
|
|
};
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private onHomeClick = (ev: ButtonEvent): void => {
|
2020-06-16 08:46:48 -06:00
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
2022-02-22 11:04:27 +01:00
|
|
|
defaultDispatcher.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
|
2021-06-29 13:11:58 +01:00
|
|
|
this.setState({ contextMenuPosition: null }); // also close the menu
|
2020-06-16 08:46:48 -06:00
|
|
|
};
|
|
|
|
|
|
2020-06-25 19:54:17 -06:00
|
|
|
private renderContextMenu = (): React.ReactNode => {
|
2020-07-01 23:06:26 +01:00
|
|
|
if (!this.state.contextMenuPosition) return null;
|
2020-06-08 09:32:16 -06:00
|
|
|
|
2023-03-14 15:20:38 +00:00
|
|
|
let topSection: JSX.Element | undefined;
|
2023-06-15 15:11:49 +01:00
|
|
|
if (MatrixClientPeg.safeGet().isGuest()) {
|
2020-11-12 12:46:55 +00:00
|
|
|
topSection = (
|
|
|
|
|
<div className="mx_UserMenu_contextMenu_header mx_UserMenu_contextMenu_guestPrompts">
|
2021-07-19 22:43:11 +01:00
|
|
|
{_t(
|
2023-09-19 07:17:31 +01:00
|
|
|
"auth|sign_in_prompt",
|
2021-07-19 22:43:11 +01:00
|
|
|
{},
|
|
|
|
|
{
|
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 22:43:11 +01:00
|
|
|
{sub}
|
2020-11-12 12:46:55 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
|
),
|
2021-07-19 22:43:11 +01:00
|
|
|
},
|
2022-12-12 12:24:14 +01:00
|
|
|
)}
|
2023-03-14 15:20:38 +00:00
|
|
|
{SettingsStore.getValue(UIFeature.Registration)
|
|
|
|
|
? _t(
|
2023-09-19 07:17:31 +01:00
|
|
|
"auth|create_account_prompt",
|
2023-03-14 15:20:38 +00:00
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
a: (sub) => (
|
|
|
|
|
<AccessibleButton kind="link_inline" onClick={this.onRegisterClick}>
|
|
|
|
|
{sub}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: null}
|
2020-11-12 12:46:55 +00:00
|
|
|
</div>
|
2021-06-29 13:11:58 +01:00
|
|
|
);
|
2020-10-21 15:22:35 +03:00
|
|
|
}
|
2020-06-07 22:06:41 -06:00
|
|
|
|
2023-03-10 14:55:06 +00:00
|
|
|
let homeButton: JSX.Element | undefined;
|
2020-06-25 19:54:17 -06:00
|
|
|
if (this.hasHomePage) {
|
|
|
|
|
homeButton = (
|
2020-08-04 21:42:39 +01:00
|
|
|
<IconizedContextMenuOption
|
2020-07-03 14:34:43 +01:00
|
|
|
iconClassName="mx_UserMenu_iconHome"
|
2023-08-23 10:25:33 +01:00
|
|
|
label={_t("common|home")}
|
2020-07-03 14:34:43 +01:00
|
|
|
onClick={this.onHomeClick}
|
|
|
|
|
/>
|
2020-06-25 19:54:17 -06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 14:55:06 +00:00
|
|
|
let feedbackButton: JSX.Element | undefined;
|
2023-04-05 12:17:25 +01:00
|
|
|
if (shouldShowFeedback()) {
|
2020-09-16 10:59:14 +01:00
|
|
|
feedbackButton = (
|
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
|
iconClassName="mx_UserMenu_iconMessage"
|
2023-09-19 07:17:31 +01:00
|
|
|
label={_t("common|feedback")}
|
2020-09-16 10:59:14 +01:00
|
|
|
onClick={this.onProvideFeedback}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-15 10:18:57 +01:00
|
|
|
const linkNewDeviceButton = (
|
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
|
iconClassName="mx_UserMenu_iconQr"
|
|
|
|
|
label={_t("user_menu|link_new_device")}
|
|
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.SessionManager, { showMsc4108QrCode: true })}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2024-06-06 09:57:28 +01:00
|
|
|
|
2020-08-28 17:03:17 -06:00
|
|
|
let primaryOptionList = (
|
2021-11-30 18:08:46 +00:00
|
|
|
<IconizedContextMenuOptionList>
|
|
|
|
|
{homeButton}
|
2024-06-06 09:57:28 +01:00
|
|
|
{linkNewDeviceButton}
|
2021-11-30 18:08:46 +00:00
|
|
|
<IconizedContextMenuOption
|
|
|
|
|
iconClassName="mx_UserMenu_iconBell"
|
2023-09-25 18:12:41 +01:00
|
|
|
label={_t("notifications|enable_prompt_toast_title")}
|
2021-11-30 18:08:46 +00:00
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.Notifications)}
|
|
|
|
|
/>
|
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
|
iconClassName="mx_UserMenu_iconLock"
|
2023-09-21 09:11:26 +01:00
|
|
|
label={_t("room_settings|security|title")}
|
2021-11-30 18:08:46 +00:00
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.Security)}
|
|
|
|
|
/>
|
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
2023-09-25 18:12:41 +01:00
|
|
|
label={_t("user_menu|settings")}
|
2023-03-10 14:55:06 +00:00
|
|
|
onClick={(e) => this.onSettingsOpen(e)}
|
2021-11-30 18:08:46 +00:00
|
|
|
/>
|
|
|
|
|
{feedbackButton}
|
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
|
className="mx_IconizedContextMenu_option_red"
|
|
|
|
|
iconClassName="mx_UserMenu_iconSignOut"
|
2023-08-23 11:57:22 +01:00
|
|
|
label={_t("action|sign_out")}
|
2021-11-30 18:08:46 +00:00
|
|
|
onClick={this.onSignOutClick}
|
|
|
|
|
/>
|
|
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
|
);
|
|
|
|
|
|
2023-06-15 15:11:49 +01:00
|
|
|
if (MatrixClientPeg.safeGet().isGuest()) {
|
2021-11-30 18:08:46 +00:00
|
|
|
primaryOptionList = (
|
2020-08-28 17:03:17 -06:00
|
|
|
<IconizedContextMenuOptionList>
|
2021-07-19 22:43:11 +01:00
|
|
|
{homeButton}
|
2020-08-28 17:03:17 -06:00
|
|
|
<IconizedContextMenuOption
|
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
2023-08-22 18:47:33 +01:00
|
|
|
label={_t("common|settings")}
|
2023-03-10 14:55:06 +00:00
|
|
|
onClick={(e) => this.onSettingsOpen(e)}
|
2020-08-28 17:03:17 -06:00
|
|
|
/>
|
2021-11-30 18:08:46 +00:00
|
|
|
{feedbackButton}
|
2020-08-28 17:03:17 -06:00
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 18:08:46 +00:00
|
|
|
const position = this.props.isPanelCollapsed
|
|
|
|
|
? toRightOf(this.state.contextMenuPosition)
|
|
|
|
|
: below(this.state.contextMenuPosition);
|
2020-08-28 17:03:17 -06:00
|
|
|
|
2020-08-04 21:42:39 +01:00
|
|
|
return (
|
2021-11-30 18:08:46 +00:00
|
|
|
<IconizedContextMenu {...position} onFinished={this.onCloseMenu} className="mx_UserMenu_contextMenu">
|
2020-08-04 21:42:39 +01: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">
|
2023-03-10 14:55:06 +00:00
|
|
|
{UserIdentifierCustomisations.getDisplayUserIdentifier(
|
2023-06-15 15:11:49 +01:00
|
|
|
MatrixClientPeg.safeGet().getSafeUserId(),
|
2023-03-10 14:55:06 +00:00
|
|
|
{
|
|
|
|
|
withDisplayName: true,
|
|
|
|
|
},
|
|
|
|
|
)}
|
2021-11-30 18:08:46 +00:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-05-17 12:29:30 +02:00
|
|
|
<RovingAccessibleButton
|
2020-08-04 21:42:39 +01:00
|
|
|
className="mx_UserMenu_contextMenu_themeButton"
|
|
|
|
|
onClick={this.onSwitchThemeClick}
|
2023-09-21 09:11:26 +01:00
|
|
|
title={
|
|
|
|
|
this.state.isDarkTheme
|
|
|
|
|
? _t("user_menu|switch_theme_light")
|
|
|
|
|
: _t("user_menu|switch_theme_dark")
|
|
|
|
|
}
|
2020-08-04 21:42:39 +01:00
|
|
|
>
|
2024-10-16 16:43:07 +01:00
|
|
|
<img src={DarkLightModeSvg} role="presentation" alt="" width={16} />
|
2024-05-17 12:29:30 +02:00
|
|
|
</RovingAccessibleButton>
|
2020-08-04 21:42:39 +01:00
|
|
|
</div>
|
2021-07-19 22:43:11 +01:00
|
|
|
{topSection}
|
|
|
|
|
{primaryOptionList}
|
2020-08-04 21:42:39 +01:00
|
|
|
</IconizedContextMenu>
|
|
|
|
|
);
|
2020-06-25 19:54:17 -06:00
|
|
|
};
|
2020-06-25 19:38:11 -06:00
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2020-06-25 19:38:11 -06:00
|
|
|
const avatarSize = 32; // should match border-radius of the avatar
|
|
|
|
|
|
2023-06-15 15:11:49 +01:00
|
|
|
const userId = MatrixClientPeg.safeGet().getSafeUserId();
|
2020-10-21 14:11:39 +01:00
|
|
|
const displayName = OwnProfileStore.instance.displayName || userId;
|
2020-08-25 14:23:18 -06:00
|
|
|
const avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize);
|
2020-08-20 19:45:54 -06:00
|
|
|
|
2023-03-10 14:55:06 +00:00
|
|
|
let name: JSX.Element | undefined;
|
2021-11-30 18:08:46 +00:00
|
|
|
if (!this.props.isPanelCollapsed) {
|
|
|
|
|
name = <div className="mx_UserMenu_name">{displayName}</div>;
|
|
|
|
|
}
|
2020-06-25 19:54:17 -06:00
|
|
|
|
2022-11-18 08:36:20 +01:00
|
|
|
const liveAvatarAddon = this.state.showLiveAvatarAddon ? (
|
|
|
|
|
<div className="mx_UserMenu_userAvatarLive" data-testid="user-menu-live-vb">
|
|
|
|
|
<LiveIcon className="mx_Icon_8" />
|
|
|
|
|
</div>
|
|
|
|
|
) : null;
|
|
|
|
|
|
2021-12-07 09:32:00 +00:00
|
|
|
return (
|
|
|
|
|
<div className="mx_UserMenu">
|
2021-11-30 18:08:46 +00:00
|
|
|
<ContextMenuButton
|
2023-07-06 00:00:03 +02:00
|
|
|
className="mx_UserMenu_contextMenuButton"
|
2021-11-30 18:08:46 +00:00
|
|
|
onClick={this.onOpenMenuClick}
|
2023-12-21 08:50:42 +00:00
|
|
|
ref={this.buttonRef}
|
2023-08-22 17:15:25 +01:00
|
|
|
label={_t("a11y|user_menu")}
|
2021-11-30 18:08:46 +00:00
|
|
|
isExpanded={!!this.state.contextMenuPosition}
|
|
|
|
|
onContextMenu={this.onContextMenu}
|
|
|
|
|
>
|
|
|
|
|
<div className="mx_UserMenu_userAvatar">
|
|
|
|
|
<BaseAvatar
|
|
|
|
|
idName={userId}
|
|
|
|
|
name={displayName}
|
|
|
|
|
url={avatarUrl}
|
2023-08-24 04:48:35 +01:00
|
|
|
size={avatarSize + "px"}
|
2021-11-30 18:08:46 +00:00
|
|
|
className="mx_UserMenu_userAvatar_BaseAvatar"
|
|
|
|
|
/>
|
2022-11-18 08:36:20 +01:00
|
|
|
{liveAvatarAddon}
|
2021-11-30 18:08:46 +00:00
|
|
|
</div>
|
|
|
|
|
{name}
|
2021-07-19 22:43:11 +01: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-25 19:38:11 -06:00
|
|
|
}
|
2020-06-07 22:06:41 -06:00
|
|
|
}
|