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

Commit

Permalink
Iterate room context menus for DMs (#7308)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Dec 9, 2021
1 parent e0162d2 commit 9452a3c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
75 changes: 42 additions & 33 deletions src/components/views/context_menus/RoomContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { Action } from "../../../dispatcher/actions";
import { RightPanelPhases } from "../../../stores/RightPanelStorePhases";
import { ROOM_NOTIFICATIONS_TAB } from "../dialogs/RoomSettingsDialog";
import { useEventEmitterState } from "../../../hooks/useEventEmitter";
import DMRoomMap from "../../../utils/DMRoomMap";

interface IProps extends IContextMenuProps {
room: Room;
Expand Down Expand Up @@ -96,8 +97,10 @@ const RoomContextMenu = ({ room, onFinished, ...props }: IProps) => {
/>;
}

const isDm = DMRoomMap.shared().getUserIdForRoomId(room.roomId);

let inviteOption: JSX.Element;
if (room.canInvite(cli.getUserId())) {
if (room.canInvite(cli.getUserId()) && !isDm) {
const onInviteClick = (ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();
Expand Down Expand Up @@ -179,6 +182,42 @@ const RoomContextMenu = ({ room, onFinished, ...props }: IProps) => {
</IconizedContextMenuOption>;
}

let peopleOption: JSX.Element;
let copyLinkOption: JSX.Element;
if (!isDm) {
peopleOption = <IconizedContextMenuOption
onClick={(ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();

ensureViewingRoom();
onRoomMembersClick(false);
onFinished();
}}
label={_t("People")}
iconClassName="mx_RoomTile_iconPeople"
>
<span className="mx_IconizedContextMenu_sublabel">
{ room.getJoinedMemberCount() }
</span>
</IconizedContextMenuOption>;

copyLinkOption = <IconizedContextMenuOption
onClick={(ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();

dis.dispatch({
action: "copy_room",
room_id: room.roomId,
});
onFinished();
}}
label={_t("Copy link")}
iconClassName="mx_RoomTile_iconCopyLink"
/>;
}

const onTagRoom = (ev: ButtonEvent, tagId: TagID) => {
ev.preventDefault();
ev.stopPropagation();
Expand Down Expand Up @@ -212,23 +251,7 @@ const RoomContextMenu = ({ room, onFinished, ...props }: IProps) => {
{ inviteOption }
{ notificationOption }
{ favouriteOption }

<IconizedContextMenuOption
onClick={(ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();

ensureViewingRoom();
onRoomMembersClick(false);
onFinished();
}}
label={_t("People")}
iconClassName="mx_RoomTile_iconPeople"
>
<span className="mx_IconizedContextMenu_sublabel">
{ room.getJoinedMemberCount() }
</span>
</IconizedContextMenuOption>
{ peopleOption }

<IconizedContextMenuOption
onClick={(ev: ButtonEvent) => {
Expand Down Expand Up @@ -261,21 +284,7 @@ const RoomContextMenu = ({ room, onFinished, ...props }: IProps) => {
/>

{ lowPriorityOption }

<IconizedContextMenuOption
onClick={(ev: ButtonEvent) => {
ev.preventDefault();
ev.stopPropagation();

dis.dispatch({
action: "copy_room",
room_id: room.roomId,
});
onFinished();
}}
label={_t("Copy link")}
iconClassName="mx_RoomTile_iconCopyLink"
/>
{ copyLinkOption }

<IconizedContextMenuOption
onClick={(ev: ButtonEvent) => {
Expand Down
8 changes: 5 additions & 3 deletions src/components/views/rooms/RoomTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,10 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
const isLowPriority = roomTags.includes(DefaultTagID.LowPriority);
const lowPriorityLabel = _t("Low Priority");

const isDm = roomTags.includes(DefaultTagID.DM);

const userId = MatrixClientPeg.get().getUserId();
const canInvite = this.props.room.canInvite(userId);
const canInvite = this.props.room.canInvite(userId) && !isDm; // hide invite in DMs from this quick menu
contextMenu = <IconizedContextMenu
{...contextMenuBelow(this.state.generalMenuPosition)}
onFinished={this.onCloseGeneralMenu}
Expand All @@ -513,11 +515,11 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
iconClassName="mx_RoomTile_iconInvite"
/>
) : null }
<IconizedContextMenuOption
{ !isDm ? <IconizedContextMenuOption
onClick={this.onCopyRoomClick}
label={_t("Copy Room Link")}
iconClassName="mx_RoomTile_iconCopyLink"
/>
/> : null }
<IconizedContextMenuOption
onClick={this.onOpenRoomSettings}
label={_t("Settings")}
Expand Down

0 comments on commit 9452a3c

Please sign in to comment.