diff --git a/src/common/hook/useUserOperation.ts b/src/common/hook/useUserOperation.ts index 27e8ddaa..5646dd61 100644 --- a/src/common/hook/useUserOperation.ts +++ b/src/common/hook/useUserOperation.ts @@ -81,8 +81,9 @@ const useUserOperation = ({ uid, cid }: IProps) => { (isAdmin || channel?.owner == loginUid) && uid != channel?.owner; const canRemove: boolean = isAdmin && loginUid != uid && !cid && uid !== 1; - + const canInviteChannel = !!cid && (loginUser?.is_admin || channel?.owner == loginUser?.uid); return { + canInviteChannel, canDeleteChannel, canRemove, removeUser: handleRemove, diff --git a/src/routes/chat/SessionList/ContextMenu.tsx b/src/routes/chat/SessionList/ContextMenu.tsx index 3c249400..42a09e52 100644 --- a/src/routes/chat/SessionList/ContextMenu.tsx +++ b/src/routes/chat/SessionList/ContextMenu.tsx @@ -10,7 +10,7 @@ import useUserOperation from "../../../common/hook/useUserOperation"; import { useAppSelector } from "../../../app/store"; import { useTranslation } from "react-i18next"; type Props = { - context: "user" | "channel"; + context: "dm" | "channel"; id: number; visible: boolean; mid: number; @@ -20,7 +20,7 @@ type Props = { children: ReactElement; }; const SessionContextMenu: FC = ({ - context = "user", + context = "dm", id, visible, mid, @@ -30,8 +30,8 @@ const SessionContextMenu: FC = ({ children }) => { const { t } = useTranslation(); - const { canCopyEmail, copyEmail, canDeleteChannel } = useUserOperation({ - uid: context == "user" ? id : undefined, + const { canCopyEmail, copyEmail, canDeleteChannel, canInviteChannel } = useUserOperation({ + uid: context == "dm" ? id : undefined, cid: context == "channel" ? id : undefined }); const [muteChannel] = useUpdateMuteSettingMutation(); @@ -53,7 +53,7 @@ const SessionContextMenu: FC = ({ const handleReadAll = () => { if (mid) { const param = - context == "user" ? { users: [{ uid: +id, mid }] } : { groups: [{ gid: +id, mid }] }; + context == "dm" ? { users: [{ uid: +id, mid }] } : { groups: [{ gid: +id, mid }] }; updateReadIndex(param); } }; @@ -74,7 +74,7 @@ const SessionContextMenu: FC = ({ }; const items = - context == "user" + context == "dm" ? [ { title: t("action.mark_read"), @@ -109,7 +109,7 @@ const SessionContextMenu: FC = ({ title: channelMuted ? t("action.unmute") : t("action.mute"), handler: handleChannelMute }, - { + canInviteChannel && { title: t("action.invite_people"), handler: setInviteChannelId.bind(null, id) },