2020-06-08 07:06:41 +03:00
|
|
|
/*
|
2021-01-05 15:29:48 +03:00
|
|
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
2020-06-08 07:06:41 +03: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.
|
|
|
|
*/
|
|
|
|
|
2020-07-07 17:01:27 +03:00
|
|
|
import React, { createRef } from "react";
|
2021-03-01 18:53:16 +03:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
import classNames from "classnames";
|
|
|
|
import * as fbEmitter from "fbemitter";
|
|
|
|
|
2020-06-08 07:06:41 +03:00
|
|
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
|
|
|
import defaultDispatcher from "../../dispatcher/dispatcher";
|
2021-03-01 18:53:16 +03:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
2020-06-08 07:06:41 +03:00
|
|
|
import { ActionPayload } from "../../dispatcher/payloads";
|
|
|
|
import { Action } from "../../dispatcher/actions";
|
|
|
|
import { _t } from "../../languageHandler";
|
2020-08-04 23:42:39 +03:00
|
|
|
import { ContextMenuButton } from "./ContextMenu";
|
2021-06-18 14:44:15 +03:00
|
|
|
import { UserTab } from "../views/dialogs/UserSettingsDialog";
|
2020-06-08 17:20:15 +03:00
|
|
|
import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload";
|
2020-10-29 18:53:14 +03:00
|
|
|
import FeedbackDialog from "../views/dialogs/FeedbackDialog";
|
2020-06-08 18:04:43 +03:00
|
|
|
import Modal from "../../Modal";
|
|
|
|
import LogoutDialog from "../views/dialogs/LogoutDialog";
|
2020-07-28 20:53:43 +03:00
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
2020-06-08 18:24:08 +03:00
|
|
|
import {getCustomTheme} from "../../theme";
|
2020-11-12 15:46:55 +03:00
|
|
|
import AccessibleButton, {ButtonEvent} from "../views/elements/AccessibleButton";
|
2020-06-16 17:46:48 +03:00
|
|
|
import SdkConfig from "../../SdkConfig";
|
2021-03-01 18:53:16 +03:00
|
|
|
import { getHomePageUrl } from "../../utils/pages";
|
2020-06-24 05:59:26 +03:00
|
|
|
import { OwnProfileStore } from "../../stores/OwnProfileStore";
|
|
|
|
import { UPDATE_EVENT } from "../../stores/AsyncStore";
|
2020-06-26 04:38:11 +03:00
|
|
|
import BaseAvatar from '../views/avatars/BaseAvatar';
|
2020-07-01 03:50:31 +03:00
|
|
|
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
|
2020-07-28 20:53:43 +03:00
|
|
|
import { SettingLevel } from "../../settings/SettingLevel";
|
2020-08-04 23:42:39 +03:00
|
|
|
import IconizedContextMenu, {
|
|
|
|
IconizedContextMenuOption,
|
2020-08-29 03:11:08 +03:00
|
|
|
IconizedContextMenuOptionList,
|
2020-08-04 23:42:39 +03:00
|
|
|
} from "../views/context_menus/IconizedContextMenu";
|
2020-08-29 01:14:08 +03:00
|
|
|
import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
|
2020-10-10 15:32:58 +03:00
|
|
|
import GroupFilterOrderStore from "../../stores/GroupFilterOrderStore";
|
2020-08-29 05:08:12 +03:00
|
|
|
import { showCommunityInviteDialog } from "../../RoomInvite";
|
2020-08-31 19:12:12 +03:00
|
|
|
import { RightPanelPhases } from "../../stores/RightPanelStorePhases";
|
|
|
|
import ErrorDialog from "../views/dialogs/ErrorDialog";
|
2020-08-31 19:52:08 +03:00
|
|
|
import EditCommunityPrototypeDialog from "../views/dialogs/EditCommunityPrototypeDialog";
|
2021-03-01 18:53:16 +03:00
|
|
|
import { UIFeature } from "../../settings/UIFeature";
|
2021-01-04 17:05:49 +03:00
|
|
|
import HostSignupAction from "./HostSignupAction";
|
2021-03-01 18:53:16 +03:00
|
|
|
import { IHostSignupConfig } from "../views/dialogs/HostSignupDialogTypes";
|
|
|
|
import SpaceStore, { UPDATE_SELECTED_SPACE } from "../../stores/SpaceStore";
|
|
|
|
import RoomName from "../views/elements/RoomName";
|
2021-03-09 05:35:10 +03:00
|
|
|
import {replaceableComponent} from "../../utils/replaceableComponent";
|
2021-05-24 17:02:26 +03:00
|
|
|
import InlineSpinner from "../views/elements/InlineSpinner";
|
|
|
|
import TooltipButton from "../views/elements/TooltipButton";
|
2020-06-08 07:06:41 +03:00
|
|
|
interface IProps {
|
2020-06-26 04:38:11 +03:00
|
|
|
isMinimized: boolean;
|
2020-06-08 07:06:41 +03:00
|
|
|
}
|
|
|
|
|
2020-07-02 01:06:26 +03:00
|
|
|
type PartialDOMRect = Pick<DOMRect, "width" | "left" | "top" | "height">;
|
|
|
|
|
2020-06-08 07:06:41 +03:00
|
|
|
interface IState {
|
2020-07-02 01:06:26 +03:00
|
|
|
contextMenuPosition: PartialDOMRect;
|
2020-06-08 18:24:08 +03:00
|
|
|
isDarkTheme: boolean;
|
2021-03-01 18:53:16 +03:00
|
|
|
selectedSpace?: Room;
|
2021-05-27 11:23:56 +03:00
|
|
|
pendingRoomJoin: Set<string>;
|
2020-06-08 07:06:41 +03:00
|
|
|
}
|
|
|
|
|
2021-03-09 05:35:10 +03:00
|
|
|
@replaceableComponent("structures.UserMenu")
|
2020-06-26 04:29:12 +03:00
|
|
|
export default class UserMenu extends React.Component<IProps, IState> {
|
2020-06-08 07:06:41 +03:00
|
|
|
private dispatcherRef: string;
|
2020-06-08 18:24:08 +03:00
|
|
|
private themeWatcherRef: string;
|
2021-04-15 09:47:09 +03:00
|
|
|
private dndWatcherRef: string;
|
2020-06-08 07:06:41 +03:00
|
|
|
private buttonRef: React.RefObject<HTMLButtonElement> = createRef();
|
2020-08-29 01:14:08 +03:00
|
|
|
private tagStoreRef: fbEmitter.EventSubscription;
|
2020-06-08 07:06:41 +03:00
|
|
|
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2020-07-02 01:06:26 +03:00
|
|
|
contextMenuPosition: null,
|
2020-06-08 18:24:08 +03:00
|
|
|
isDarkTheme: this.isUserOnDarkTheme(),
|
2021-05-27 10:57:27 +03:00
|
|
|
pendingRoomJoin: new Set<string>(),
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-06-24 05:59:26 +03:00
|
|
|
OwnProfileStore.instance.on(UPDATE_EVENT, this.onProfileUpdate);
|
2021-03-01 18:53:16 +03:00
|
|
|
if (SettingsStore.getValue("feature_spaces")) {
|
|
|
|
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
|
|
|
}
|
2021-04-15 09:47:09 +03:00
|
|
|
|
|
|
|
// Force update is the easiest way to trigger the UI update (we don't store state for this)
|
|
|
|
this.dndWatcherRef = SettingsStore.watchSetting("doNotDisturb", null, () => this.forceUpdate());
|
2020-06-08 07:06:41 +03:00
|
|
|
}
|
|
|
|
|
2020-06-16 17:46:48 +03:00
|
|
|
private get hasHomePage(): boolean {
|
|
|
|
return !!getHomePageUrl(SdkConfig.get());
|
|
|
|
}
|
|
|
|
|
2020-06-08 07:06:41 +03:00
|
|
|
public componentDidMount() {
|
|
|
|
this.dispatcherRef = defaultDispatcher.register(this.onAction);
|
2020-06-08 18:24:08 +03:00
|
|
|
this.themeWatcherRef = SettingsStore.watchSetting("theme", null, this.onThemeChanged);
|
2020-10-10 15:32:58 +03:00
|
|
|
this.tagStoreRef = GroupFilterOrderStore.addListener(this.onTagStoreUpdate);
|
2021-05-27 10:58:11 +03:00
|
|
|
MatrixClientPeg.get().on("Room", this.onRoom);
|
2020-06-08 07:06:41 +03:00
|
|
|
}
|
|
|
|
|
2020-06-08 18:24:08 +03:00
|
|
|
public componentWillUnmount() {
|
|
|
|
if (this.themeWatcherRef) SettingsStore.unwatchSetting(this.themeWatcherRef);
|
2021-04-15 09:47:09 +03:00
|
|
|
if (this.dndWatcherRef) SettingsStore.unwatchSetting(this.dndWatcherRef);
|
2020-06-08 18:24:08 +03:00
|
|
|
if (this.dispatcherRef) defaultDispatcher.unregister(this.dispatcherRef);
|
2020-06-24 05:59:26 +03:00
|
|
|
OwnProfileStore.instance.off(UPDATE_EVENT, this.onProfileUpdate);
|
2020-08-29 01:14:08 +03:00
|
|
|
this.tagStoreRef.remove();
|
2021-03-01 18:53:16 +03:00
|
|
|
if (SettingsStore.getValue("feature_spaces")) {
|
|
|
|
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdate);
|
|
|
|
}
|
2021-05-27 10:58:11 +03:00
|
|
|
MatrixClientPeg.get().removeListener("Room", this.onRoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onRoom = (room: Room): void => {
|
|
|
|
this.removePendingJoinRoom(room.roomId);
|
2020-06-08 18:24:08 +03:00
|
|
|
}
|
|
|
|
|
2020-08-29 01:14:08 +03:00
|
|
|
private onTagStoreUpdate = () => {
|
|
|
|
this.forceUpdate(); // we don't have anything useful in state to update
|
|
|
|
};
|
|
|
|
|
2020-06-08 18:24:08 +03:00
|
|
|
private isUserOnDarkTheme(): boolean {
|
2021-02-21 19:15:32 +03: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 18:24:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 05:59:26 +03: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-03-01 18:53:16 +03:00
|
|
|
private onSelectedSpaceUpdate = async (selectedSpace?: Room) => {
|
|
|
|
this.setState({ selectedSpace });
|
|
|
|
};
|
|
|
|
|
2020-06-08 18:24:08 +03:00
|
|
|
private onThemeChanged = () => {
|
|
|
|
this.setState({isDarkTheme: this.isUserOnDarkTheme()});
|
|
|
|
};
|
|
|
|
|
2020-06-08 07:06:41 +03:00
|
|
|
private onAction = (ev: ActionPayload) => {
|
2021-05-24 17:02:26 +03:00
|
|
|
switch (ev.action) {
|
|
|
|
case Action.ToggleUserMenu:
|
|
|
|
if (this.state.contextMenuPosition) {
|
|
|
|
this.setState({contextMenuPosition: null});
|
|
|
|
} else {
|
|
|
|
if (this.buttonRef.current) this.buttonRef.current.click();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Action.JoinRoom:
|
|
|
|
this.addPendingJoinRoom(ev.roomId);
|
|
|
|
break;
|
|
|
|
case Action.JoinRoomReady:
|
|
|
|
case Action.JoinRoomError:
|
|
|
|
this.removePendingJoinRoom(ev.roomId);
|
|
|
|
break;
|
2020-07-03 16:34:43 +03:00
|
|
|
}
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2021-05-27 10:57:27 +03:00
|
|
|
private addPendingJoinRoom(roomId: string): void {
|
2021-05-24 17:02:26 +03:00
|
|
|
this.setState({
|
2021-05-27 10:57:27 +03:00
|
|
|
pendingRoomJoin: new Set<string>(this.state.pendingRoomJoin)
|
|
|
|
.add(roomId),
|
2021-05-24 17:02:26 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-27 10:57:27 +03:00
|
|
|
private removePendingJoinRoom(roomId: string): void {
|
2021-05-27 11:23:56 +03:00
|
|
|
if (this.state.pendingRoomJoin.delete(roomId)) {
|
2021-05-24 17:02:26 +03:00
|
|
|
this.setState({
|
2021-05-27 10:57:27 +03:00
|
|
|
pendingRoomJoin: new Set<string>(this.state.pendingRoomJoin),
|
2021-05-24 17:02:26 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-02 01:56:57 +03:00
|
|
|
private onOpenMenuClick = (ev: React.MouseEvent) => {
|
2020-06-08 07:06:41 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2020-07-02 01:06:26 +03:00
|
|
|
const target = ev.target as HTMLButtonElement;
|
|
|
|
this.setState({contextMenuPosition: target.getBoundingClientRect()});
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-07-02 01:06:26 +03:00
|
|
|
private onContextMenu = (ev: React.MouseEvent) => {
|
2020-06-26 04:54:17 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2020-07-02 01:06:26 +03:00
|
|
|
this.setState({
|
|
|
|
contextMenuPosition: {
|
|
|
|
left: ev.clientX,
|
|
|
|
top: ev.clientY,
|
|
|
|
width: 20,
|
|
|
|
height: 0,
|
|
|
|
},
|
|
|
|
});
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-07-02 01:13:54 +03:00
|
|
|
private onCloseMenu = () => {
|
2020-07-02 01:06:26 +03:00
|
|
|
this.setState({contextMenuPosition: null});
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-07-03 18:29:48 +03:00
|
|
|
private onSwitchThemeClick = (ev: React.MouseEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-06-08 18:24:08 +03:00
|
|
|
// Disable system theme matching if the user hits this button
|
|
|
|
SettingsStore.setValue("use_system_theme", null, SettingLevel.DEVICE, false);
|
|
|
|
|
2020-07-14 19:40:32 +03:00
|
|
|
const newTheme = this.state.isDarkTheme ? "light" : "dark";
|
2020-06-22 22:34:49 +03:00
|
|
|
SettingsStore.setValue("theme", null, SettingLevel.DEVICE, newTheme); // set at same level as Appearance tab
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-06-11 00:05:29 +03:00
|
|
|
private onSettingsOpen = (ev: ButtonEvent, tabId: string) => {
|
2020-06-08 07:06:41 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-06-08 17:20:15 +03:00
|
|
|
const payload: OpenToTabPayload = {action: Action.ViewUserSettings, initialTabId: tabId};
|
|
|
|
defaultDispatcher.dispatch(payload);
|
2020-07-02 01:06:26 +03:00
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-06-11 00:05:29 +03:00
|
|
|
private onShowArchived = (ev: ButtonEvent) => {
|
2020-06-08 07:06:41 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-08-03 18:02:26 +03:00
|
|
|
// TODO: Archived room view: https://github.com/vector-im/element-web/issues/14038
|
2020-07-14 05:25:02 +03:00
|
|
|
// Note: You'll need to uncomment the button too.
|
2020-06-08 07:06:41 +03:00
|
|
|
console.log("TODO: Show archived rooms");
|
|
|
|
};
|
|
|
|
|
2020-06-11 00:05:29 +03:00
|
|
|
private onProvideFeedback = (ev: ButtonEvent) => {
|
2020-06-08 07:06:41 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-10-29 18:53:14 +03:00
|
|
|
Modal.createTrackedDialog('Feedback Dialog', '', FeedbackDialog);
|
2020-07-02 01:06:26 +03:00
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-11-09 18:50:35 +03:00
|
|
|
private onSignOutClick = async (ev: ButtonEvent) => {
|
2020-06-08 07:06:41 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-11-09 18:50:35 +03: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
|
|
|
|
dis.dispatch({action: 'logout'});
|
|
|
|
} else {
|
|
|
|
Modal.createTrackedDialog('Logout from LeftPanel', '', LogoutDialog);
|
|
|
|
}
|
|
|
|
|
2020-07-02 01:06:26 +03:00
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
2020-06-08 07:06:41 +03:00
|
|
|
};
|
|
|
|
|
2020-11-12 15:46:55 +03:00
|
|
|
private onSignInClick = () => {
|
|
|
|
dis.dispatch({ action: 'start_login' });
|
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
|
|
|
};
|
|
|
|
|
|
|
|
private onRegisterClick = () => {
|
|
|
|
dis.dispatch({ action: 'start_registration' });
|
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
|
|
|
};
|
|
|
|
|
2020-06-16 17:46:48 +03:00
|
|
|
private onHomeClick = (ev: ButtonEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
|
|
defaultDispatcher.dispatch({action: 'view_home_page'});
|
2020-11-09 16:45:33 +03:00
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
2020-06-16 17:46:48 +03:00
|
|
|
};
|
|
|
|
|
2020-08-29 02:03:17 +03:00
|
|
|
private onCommunitySettingsClick = (ev: ButtonEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-08-31 19:52:08 +03:00
|
|
|
Modal.createTrackedDialog('Edit Community', '', EditCommunityPrototypeDialog, {
|
|
|
|
communityId: CommunityPrototypeStore.instance.getSelectedCommunityId(),
|
|
|
|
});
|
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
2020-08-29 02:03:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private onCommunityMembersClick = (ev: ButtonEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-08-31 19:12:12 +03:00
|
|
|
// We'd ideally just pop open a right panel with the member list, but the current
|
|
|
|
// way the right panel is structured makes this exceedingly difficult. Instead, we'll
|
|
|
|
// switch to the general room and open the member list there as it should be in sync
|
|
|
|
// anyways.
|
2020-08-31 19:19:05 +03:00
|
|
|
const chat = CommunityPrototypeStore.instance.getSelectedCommunityGeneralChat();
|
2020-08-31 19:12:12 +03:00
|
|
|
if (chat) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: chat.roomId,
|
|
|
|
}, true);
|
|
|
|
dis.dispatch({action: Action.SetRightPanelPhase, phase: RightPanelPhases.RoomMemberList});
|
|
|
|
} else {
|
|
|
|
// "This should never happen" clauses go here for the prototype.
|
|
|
|
Modal.createTrackedDialog('Failed to find general chat', '', ErrorDialog, {
|
|
|
|
title: _t('Failed to find the general chat for this community'),
|
|
|
|
description: _t("Failed to find the general chat for this community"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
2020-08-29 02:03:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private onCommunityInviteClick = (ev: ButtonEvent) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
2020-08-31 19:19:05 +03:00
|
|
|
showCommunityInviteDialog(CommunityPrototypeStore.instance.getSelectedCommunityId());
|
2020-08-29 05:08:12 +03:00
|
|
|
this.setState({contextMenuPosition: null}); // also close the menu
|
2020-08-29 02:03:17 +03:00
|
|
|
};
|
|
|
|
|
2021-04-15 09:47:09 +03:00
|
|
|
private onDndToggle = (ev) => {
|
|
|
|
ev.stopPropagation();
|
|
|
|
const current = SettingsStore.getValue("doNotDisturb");
|
|
|
|
SettingsStore.setValue("doNotDisturb", null, SettingLevel.DEVICE, !current);
|
|
|
|
};
|
|
|
|
|
2020-06-26 04:54:17 +03:00
|
|
|
private renderContextMenu = (): React.ReactNode => {
|
2020-07-02 01:06:26 +03:00
|
|
|
if (!this.state.contextMenuPosition) return null;
|
2020-06-26 04:54:17 +03:00
|
|
|
|
2020-08-29 02:03:17 +03:00
|
|
|
const prototypeCommunityName = CommunityPrototypeStore.instance.getSelectedCommunityName();
|
|
|
|
|
2020-11-12 15:46:55 +03:00
|
|
|
let topSection;
|
2021-01-15 16:32:30 +03:00
|
|
|
const hostSignupConfig: IHostSignupConfig = SdkConfig.get().hostSignup;
|
2020-11-12 15:46:55 +03:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
topSection = (
|
|
|
|
<div className="mx_UserMenu_contextMenu_header mx_UserMenu_contextMenu_guestPrompts">
|
2020-11-27 12:44:04 +03:00
|
|
|
{_t("Got an account? <a>Sign in</a>", {}, {
|
2020-11-12 15:46:55 +03:00
|
|
|
a: sub => (
|
|
|
|
<AccessibleButton kind="link" onClick={this.onSignInClick}>
|
|
|
|
{sub}
|
|
|
|
</AccessibleButton>
|
|
|
|
),
|
|
|
|
})}
|
|
|
|
{_t("New here? <a>Create an account</a>", {}, {
|
|
|
|
a: sub => (
|
|
|
|
<AccessibleButton kind="link" onClick={this.onRegisterClick}>
|
|
|
|
{sub}
|
|
|
|
</AccessibleButton>
|
|
|
|
),
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
)
|
2021-02-09 21:01:45 +03:00
|
|
|
} else if (hostSignupConfig) {
|
2021-01-04 17:05:49 +03:00
|
|
|
if (hostSignupConfig && hostSignupConfig.url) {
|
2021-01-15 16:32:30 +03:00
|
|
|
// If hostSignup.domains is set to a non-empty array, only show
|
2020-11-27 14:18:16 +03:00
|
|
|
// dialog if the user is on the domain or a subdomain.
|
2021-01-04 17:05:49 +03:00
|
|
|
const hostSignupDomains = hostSignupConfig.domains || [];
|
2020-11-27 14:18:16 +03:00
|
|
|
const mxDomain = MatrixClientPeg.get().getDomain();
|
2021-01-04 17:05:49 +03:00
|
|
|
const validDomains = hostSignupDomains.filter(d => (d === mxDomain || mxDomain.endsWith(`.${d}`)));
|
2021-02-15 20:38:11 +03:00
|
|
|
if (!hostSignupConfig.domains || validDomains.length > 0) {
|
2021-06-08 19:31:08 +03:00
|
|
|
topSection = <HostSignupAction onClick={this.onCloseMenu} />;
|
2020-11-27 14:18:16 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-08 07:06:41 +03:00
|
|
|
}
|
|
|
|
|
2020-06-26 04:54:17 +03:00
|
|
|
let homeButton = null;
|
|
|
|
if (this.hasHomePage) {
|
|
|
|
homeButton = (
|
2020-08-04 23:42:39 +03:00
|
|
|
<IconizedContextMenuOption
|
2020-07-03 16:34:43 +03:00
|
|
|
iconClassName="mx_UserMenu_iconHome"
|
|
|
|
label={_t("Home")}
|
|
|
|
onClick={this.onHomeClick}
|
|
|
|
/>
|
2020-06-26 04:54:17 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-16 12:59:14 +03:00
|
|
|
let feedbackButton;
|
|
|
|
if (SettingsStore.getValue(UIFeature.Feedback)) {
|
|
|
|
feedbackButton = <IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconMessage"
|
|
|
|
label={_t("Feedback")}
|
|
|
|
onClick={this.onProvideFeedback}
|
|
|
|
/>;
|
|
|
|
}
|
|
|
|
|
2020-08-29 02:03:17 +03:00
|
|
|
let primaryHeader = (
|
|
|
|
<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>
|
|
|
|
);
|
|
|
|
let primaryOptionList = (
|
|
|
|
<React.Fragment>
|
|
|
|
<IconizedContextMenuOptionList>
|
|
|
|
{homeButton}
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconBell"
|
|
|
|
label={_t("Notification settings")}
|
2021-06-18 14:44:15 +03:00
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.Notifications)}
|
2020-08-29 02:03:17 +03:00
|
|
|
/>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconLock"
|
|
|
|
label={_t("Security & privacy")}
|
2021-06-18 14:44:15 +03:00
|
|
|
onClick={(e) => this.onSettingsOpen(e, UserTab.Security)}
|
2020-08-29 02:03:17 +03:00
|
|
|
/>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
|
|
|
label={_t("All settings")}
|
|
|
|
onClick={(e) => this.onSettingsOpen(e, null)}
|
|
|
|
/>
|
|
|
|
{/* <IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconArchive"
|
|
|
|
label={_t("Archived rooms")}
|
|
|
|
onClick={this.onShowArchived}
|
|
|
|
/> */}
|
2020-09-16 12:59:14 +03:00
|
|
|
{ feedbackButton }
|
2020-08-29 02:03:17 +03:00
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
<IconizedContextMenuOptionList red>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSignOut"
|
|
|
|
label={_t("Sign out")}
|
|
|
|
onClick={this.onSignOutClick}
|
|
|
|
/>
|
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
let secondarySection = null;
|
|
|
|
|
|
|
|
if (prototypeCommunityName) {
|
2020-09-19 01:04:19 +03:00
|
|
|
const communityId = CommunityPrototypeStore.instance.getSelectedCommunityId();
|
2020-08-29 02:03:17 +03:00
|
|
|
primaryHeader = (
|
|
|
|
<div className="mx_UserMenu_contextMenu_name">
|
|
|
|
<span className="mx_UserMenu_contextMenu_displayName">
|
|
|
|
{prototypeCommunityName}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
2020-09-19 01:04:19 +03:00
|
|
|
let settingsOption;
|
|
|
|
let inviteOption;
|
|
|
|
if (CommunityPrototypeStore.instance.canInviteTo(communityId)) {
|
|
|
|
inviteOption = (
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconInvite"
|
|
|
|
label={_t("Invite")}
|
|
|
|
onClick={this.onCommunityInviteClick}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (CommunityPrototypeStore.instance.isAdminOf(communityId)) {
|
|
|
|
settingsOption = (
|
2020-08-29 02:03:17 +03:00
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
|
|
|
label={_t("Settings")}
|
2020-08-29 05:04:19 +03:00
|
|
|
aria-label={_t("Community settings")}
|
2020-08-29 02:03:17 +03:00
|
|
|
onClick={this.onCommunitySettingsClick}
|
|
|
|
/>
|
2020-09-19 01:04:19 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
primaryOptionList = (
|
|
|
|
<IconizedContextMenuOptionList>
|
|
|
|
{settingsOption}
|
2020-08-29 02:03:17 +03:00
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconMembers"
|
|
|
|
label={_t("Members")}
|
|
|
|
onClick={this.onCommunityMembersClick}
|
|
|
|
/>
|
2020-09-19 01:04:19 +03:00
|
|
|
{inviteOption}
|
2020-08-29 02:03:17 +03:00
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
);
|
|
|
|
secondarySection = (
|
|
|
|
<React.Fragment>
|
|
|
|
<hr />
|
|
|
|
<div className="mx_UserMenu_contextMenu_header">
|
|
|
|
<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>
|
|
|
|
</div>
|
|
|
|
<IconizedContextMenuOptionList>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
|
|
|
label={_t("Settings")}
|
2020-08-29 05:04:19 +03:00
|
|
|
aria-label={_t("User settings")}
|
2020-08-29 02:03:17 +03:00
|
|
|
onClick={(e) => this.onSettingsOpen(e, null)}
|
|
|
|
/>
|
2020-09-16 12:59:14 +03:00
|
|
|
{ feedbackButton }
|
2020-08-29 02:03:17 +03:00
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
<IconizedContextMenuOptionList red>
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSignOut"
|
|
|
|
label={_t("Sign out")}
|
|
|
|
onClick={this.onSignOutClick}
|
|
|
|
/>
|
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
</React.Fragment>
|
|
|
|
)
|
2020-11-12 15:46:55 +03:00
|
|
|
} else if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
primaryOptionList = (
|
|
|
|
<React.Fragment>
|
|
|
|
<IconizedContextMenuOptionList>
|
|
|
|
{ homeButton }
|
|
|
|
<IconizedContextMenuOption
|
|
|
|
iconClassName="mx_UserMenu_iconSettings"
|
|
|
|
label={_t("Settings")}
|
|
|
|
onClick={(e) => this.onSettingsOpen(e, null)}
|
|
|
|
/>
|
|
|
|
{ feedbackButton }
|
|
|
|
</IconizedContextMenuOptionList>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
2020-08-29 02:03:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const classes = classNames({
|
|
|
|
"mx_UserMenu_contextMenu": true,
|
|
|
|
"mx_UserMenu_contextMenu_prototype": !!prototypeCommunityName,
|
|
|
|
});
|
|
|
|
|
2020-08-04 23:42:39 +03:00
|
|
|
return <IconizedContextMenu
|
2020-08-29 02:03:17 +03:00
|
|
|
// numerical adjustments to overlap the context menu by just over the width of the
|
|
|
|
// menu icon and make it look connected
|
|
|
|
left={this.state.contextMenuPosition.width + this.state.contextMenuPosition.left - 10}
|
|
|
|
top={this.state.contextMenuPosition.top + this.state.contextMenuPosition.height + 8}
|
2020-08-04 23:42:39 +03:00
|
|
|
onFinished={this.onCloseMenu}
|
2020-08-29 02:03:17 +03:00
|
|
|
className={classes}
|
2020-08-04 23:42:39 +03:00
|
|
|
>
|
|
|
|
<div className="mx_UserMenu_contextMenu_header">
|
2020-08-29 02:03:17 +03:00
|
|
|
{primaryHeader}
|
2020-08-04 23:42:39 +03: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>
|
2020-11-12 15:46:55 +03:00
|
|
|
{topSection}
|
2020-08-29 02:03:17 +03:00
|
|
|
{primaryOptionList}
|
|
|
|
{secondarySection}
|
2020-08-04 23:42:39 +03:00
|
|
|
</IconizedContextMenu>;
|
2020-06-26 04:54:17 +03:00
|
|
|
};
|
2020-06-26 04:38:11 +03:00
|
|
|
|
|
|
|
public render() {
|
|
|
|
const avatarSize = 32; // should match border-radius of the avatar
|
|
|
|
|
2020-10-21 16:11:39 +03:00
|
|
|
const userId = MatrixClientPeg.get().getUserId();
|
|
|
|
const displayName = OwnProfileStore.instance.displayName || userId;
|
2020-08-25 23:23:18 +03:00
|
|
|
const avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize);
|
2020-08-21 04:45:54 +03:00
|
|
|
|
2020-08-29 01:14:08 +03:00
|
|
|
const prototypeCommunityName = CommunityPrototypeStore.instance.getSelectedCommunityName();
|
|
|
|
|
|
|
|
let isPrototype = false;
|
|
|
|
let menuName = _t("User menu");
|
2020-08-21 04:45:54 +03:00
|
|
|
let name = <span className="mx_UserMenu_userName">{displayName}</span>;
|
2020-06-26 04:38:11 +03:00
|
|
|
let buttons = (
|
|
|
|
<span className="mx_UserMenu_headerButtons">
|
2020-06-26 04:54:17 +03:00
|
|
|
{/* masked image in CSS */}
|
2020-06-26 04:38:11 +03:00
|
|
|
</span>
|
|
|
|
);
|
2021-04-15 09:47:09 +03:00
|
|
|
let dnd;
|
2021-03-01 18:53:16 +03:00
|
|
|
if (this.state.selectedSpace) {
|
|
|
|
name = (
|
|
|
|
<div className="mx_UserMenu_doubleName">
|
|
|
|
<span className="mx_UserMenu_userName">{displayName}</span>
|
|
|
|
<RoomName room={this.state.selectedSpace}>
|
|
|
|
{(roomName) => <span className="mx_UserMenu_subUserName">{roomName}</span>}
|
|
|
|
</RoomName>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (prototypeCommunityName) {
|
2020-08-29 01:14:08 +03:00
|
|
|
name = (
|
|
|
|
<div className="mx_UserMenu_doubleName">
|
|
|
|
<span className="mx_UserMenu_userName">{prototypeCommunityName}</span>
|
|
|
|
<span className="mx_UserMenu_subUserName">{displayName}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
menuName = _t("Community and user menu");
|
|
|
|
isPrototype = true;
|
|
|
|
} else if (SettingsStore.getValue("feature_communities_v2_prototypes")) {
|
|
|
|
name = (
|
|
|
|
<div className="mx_UserMenu_doubleName">
|
|
|
|
<span className="mx_UserMenu_userName">{_t("Home")}</span>
|
|
|
|
<span className="mx_UserMenu_subUserName">{displayName}</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
isPrototype = true;
|
2021-04-15 09:47:09 +03:00
|
|
|
} else if (SettingsStore.getValue("feature_dnd")) {
|
|
|
|
const isDnd = SettingsStore.getValue("doNotDisturb");
|
|
|
|
dnd = <AccessibleButton
|
|
|
|
onClick={this.onDndToggle}
|
|
|
|
className={classNames({
|
|
|
|
"mx_UserMenu_dnd": true,
|
|
|
|
"mx_UserMenu_dnd_noisy": !isDnd,
|
|
|
|
"mx_UserMenu_dnd_muted": isDnd,
|
|
|
|
})}
|
|
|
|
/>;
|
2020-08-29 01:14:08 +03:00
|
|
|
}
|
2020-06-26 04:38:11 +03:00
|
|
|
if (this.props.isMinimized) {
|
|
|
|
name = null;
|
|
|
|
buttons = null;
|
|
|
|
}
|
|
|
|
|
2020-06-26 04:54:17 +03:00
|
|
|
const classes = classNames({
|
|
|
|
'mx_UserMenu': true,
|
|
|
|
'mx_UserMenu_minimized': this.props.isMinimized,
|
2020-08-29 01:14:08 +03:00
|
|
|
'mx_UserMenu_prototype': isPrototype,
|
2020-06-26 04:54:17 +03:00
|
|
|
});
|
|
|
|
|
2020-06-26 04:38:11 +03:00
|
|
|
return (
|
2020-06-26 04:54:17 +03:00
|
|
|
<React.Fragment>
|
|
|
|
<ContextMenuButton
|
|
|
|
className={classes}
|
|
|
|
onClick={this.onOpenMenuClick}
|
|
|
|
inputRef={this.buttonRef}
|
2020-08-29 01:14:08 +03:00
|
|
|
label={menuName}
|
2020-07-02 01:06:26 +03:00
|
|
|
isExpanded={!!this.state.contextMenuPosition}
|
|
|
|
onContextMenu={this.onContextMenu}
|
2020-06-26 04:54:17 +03:00
|
|
|
>
|
|
|
|
<div className="mx_UserMenu_row">
|
|
|
|
<span className="mx_UserMenu_userAvatarContainer">
|
|
|
|
<BaseAvatar
|
2020-10-21 16:11:39 +03:00
|
|
|
idName={userId}
|
2020-08-21 04:45:54 +03:00
|
|
|
name={displayName}
|
|
|
|
url={avatarUrl}
|
2020-06-26 04:54:17 +03:00
|
|
|
width={avatarSize}
|
|
|
|
height={avatarSize}
|
|
|
|
resizeMethod="crop"
|
|
|
|
className="mx_UserMenu_userAvatar"
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
{name}
|
2021-05-27 11:26:26 +03:00
|
|
|
{this.state.pendingRoomJoin.size > 0 && (
|
2021-05-24 17:02:26 +03:00
|
|
|
<InlineSpinner>
|
|
|
|
<TooltipButton helpText={_t(
|
|
|
|
"Currently joining %(count)s rooms",
|
2021-05-27 11:26:26 +03:00
|
|
|
{ count: this.state.pendingRoomJoin.size },
|
2021-05-24 17:02:26 +03:00
|
|
|
)} />
|
|
|
|
</InlineSpinner>
|
|
|
|
)}
|
2021-04-15 09:47:09 +03:00
|
|
|
{dnd}
|
2020-06-26 04:54:17 +03:00
|
|
|
{buttons}
|
|
|
|
</div>
|
|
|
|
</ContextMenuButton>
|
2020-07-08 20:59:27 +03:00
|
|
|
{this.renderContextMenu()}
|
2020-06-26 04:54:17 +03:00
|
|
|
</React.Fragment>
|
2020-06-26 04:38:11 +03:00
|
|
|
);
|
|
|
|
}
|
2020-06-08 07:06:41 +03:00
|
|
|
}
|