Removing some menu items from message request context menu.

pull/2222/head
warrickct 3 years ago
parent 56c1a06a28
commit eed72a6b1b

@ -12,6 +12,7 @@ import {
useIsMe, useIsMe,
useIsPrivate, useIsPrivate,
useIsPublic, useIsPublic,
useIsRequest,
useNotificationSetting, useNotificationSetting,
useWeAreAdmin, useWeAreAdmin,
} from '../../hooks/useParamSelector'; } from '../../hooks/useParamSelector';
@ -68,21 +69,27 @@ function showTimerOptions(
function showNotificationConvo( function showNotificationConvo(
isKickedFromGroup: boolean, isKickedFromGroup: boolean,
left: boolean, left: boolean,
isBlocked: boolean isBlocked: boolean,
isRequest: boolean
): boolean { ): boolean {
return !left && !isKickedFromGroup && !isBlocked; return !left && !isKickedFromGroup && !isBlocked && !isRequest;
} }
function showBlock(isMe: boolean, isPrivate: boolean): boolean { function showBlock(isMe: boolean, isPrivate: boolean, isRequest: boolean): boolean {
return !isMe && isPrivate; return !isMe && isPrivate && !isRequest;
} }
function showClearNickname(isMe: boolean, hasNickname: boolean, isPrivate: boolean): boolean { function showClearNickname(
return !isMe && hasNickname && isPrivate; isMe: boolean,
hasNickname: boolean,
isPrivate: boolean,
isRequest: boolean
): boolean {
return !isMe && hasNickname && isPrivate && isRequest;
} }
function showChangeNickname(isMe: boolean, isPrivate: boolean) { function showChangeNickname(isMe: boolean, isPrivate: boolean, isRequest: boolean) {
return !isMe && isPrivate; return !isMe && isPrivate && !isRequest;
} }
// we want to show the copyId for open groups and private chats only // we want to show the copyId for open groups and private chats only
@ -94,10 +101,11 @@ function showDeleteContact(
isGroup: boolean, isGroup: boolean,
isPublic: boolean, isPublic: boolean,
isGroupLeft: boolean, isGroupLeft: boolean,
isKickedFromGroup: boolean isKickedFromGroup: boolean,
isRequest: boolean
): boolean { ): boolean {
// you need to have left a closed group first to be able to delete it completely. // you need to have left a closed group first to be able to delete it completely.
return !isGroup || (isGroup && (isGroupLeft || isKickedFromGroup || isPublic)); return (!isGroup && !isRequest) || (isGroup && (isGroupLeft || isKickedFromGroup || isPublic));
} }
const showUnbanUser = (weAreAdmin: boolean, isPublic: boolean, isKickedFromGroup: boolean) => { const showUnbanUser = (weAreAdmin: boolean, isPublic: boolean, isKickedFromGroup: boolean) => {
@ -169,8 +177,9 @@ export const PinConversationMenuItem = (): JSX.Element | null => {
const conversationId = useContext(ContextConversationId); const conversationId = useContext(ContextConversationId);
const isMessagesSection = useSelector(getFocusedSection) === SectionType.Message; const isMessagesSection = useSelector(getFocusedSection) === SectionType.Message;
const nbOfAlreadyPinnedConvos = useSelector(getNumberOfPinnedConversations); const nbOfAlreadyPinnedConvos = useSelector(getNumberOfPinnedConversations);
const isRequest = useIsRequest(conversationId);
if (isMessagesSection) { if (isMessagesSection && !isRequest) {
const conversation = getConversationController().get(conversationId); const conversation = getConversationController().get(conversationId);
const isPinned = conversation?.isPinned() || false; const isPinned = conversation?.isPinned() || false;
@ -199,8 +208,9 @@ export const DeleteContactMenuItem = () => {
const isLeft = useIsLeft(convoId); const isLeft = useIsLeft(convoId);
const isKickedFromGroup = useIsKickedFromGroup(convoId); const isKickedFromGroup = useIsKickedFromGroup(convoId);
const isPrivate = useIsPrivate(convoId); const isPrivate = useIsPrivate(convoId);
const isRequest = useIsRequest(convoId);
if (showDeleteContact(!isPrivate, isPublic, isLeft, isKickedFromGroup)) { if (showDeleteContact(!isPrivate, isPublic, isLeft, isKickedFromGroup, isRequest)) {
let menuItemText: string; let menuItemText: string;
if (isPublic) { if (isPublic) {
menuItemText = window.i18n('leaveGroup'); menuItemText = window.i18n('leaveGroup');
@ -448,9 +458,12 @@ export const NotificationForConvoMenuItem = (): JSX.Element | null => {
const left = useIsLeft(convoId); const left = useIsLeft(convoId);
const isBlocked = useIsBlocked(convoId); const isBlocked = useIsBlocked(convoId);
const isPrivate = useIsPrivate(convoId); const isPrivate = useIsPrivate(convoId);
const isRequest = useIsRequest(convoId);
const currentNotificationSetting = useNotificationSetting(convoId); const currentNotificationSetting = useNotificationSetting(convoId);
if (showNotificationConvo(Boolean(isKickedFromGroup), Boolean(left), Boolean(isBlocked))) { if (
showNotificationConvo(Boolean(isKickedFromGroup), Boolean(left), Boolean(isBlocked), isRequest)
) {
// const isRtlMode = isRtlBody();' // const isRtlMode = isRtlBody();'
// exclude mentions_only settings for private chats as this does not make much sense // exclude mentions_only settings for private chats as this does not make much sense
@ -503,8 +516,9 @@ export const BlockMenuItem = (): JSX.Element | null => {
const isMe = useIsMe(convoId); const isMe = useIsMe(convoId);
const isBlocked = useIsBlocked(convoId); const isBlocked = useIsBlocked(convoId);
const isPrivate = useIsPrivate(convoId); const isPrivate = useIsPrivate(convoId);
const isRequest = useIsRequest(convoId);
if (showBlock(Boolean(isMe), Boolean(isPrivate))) { if (showBlock(Boolean(isMe), Boolean(isPrivate), Boolean(isRequest))) {
const blockTitle = isBlocked ? window.i18n('unblockUser') : window.i18n('blockUser'); const blockTitle = isBlocked ? window.i18n('unblockUser') : window.i18n('blockUser');
const blockHandler = isBlocked const blockHandler = isBlocked
? () => unblockConvoById(convoId) ? () => unblockConvoById(convoId)
@ -519,8 +533,9 @@ export const ClearNicknameMenuItem = (): JSX.Element | null => {
const isMe = useIsMe(convoId); const isMe = useIsMe(convoId);
const hasNickname = useHasNickname(convoId); const hasNickname = useHasNickname(convoId);
const isPrivate = useIsPrivate(convoId); const isPrivate = useIsPrivate(convoId);
const isRequest = Boolean(useIsRequest(convoId)); // easier to copy paste
if (showClearNickname(Boolean(isMe), Boolean(hasNickname), Boolean(isPrivate))) { if (showClearNickname(Boolean(isMe), Boolean(hasNickname), Boolean(isPrivate), isRequest)) {
return ( return (
<Item onClick={() => clearNickNameByConvoId(convoId)}>{window.i18n('clearNickname')}</Item> <Item onClick={() => clearNickNameByConvoId(convoId)}>{window.i18n('clearNickname')}</Item>
); );
@ -532,9 +547,10 @@ export const ChangeNicknameMenuItem = () => {
const convoId = useContext(ContextConversationId); const convoId = useContext(ContextConversationId);
const isMe = useIsMe(convoId); const isMe = useIsMe(convoId);
const isPrivate = useIsPrivate(convoId); const isPrivate = useIsPrivate(convoId);
const isRequest = useIsRequest(convoId);
const dispatch = useDispatch(); const dispatch = useDispatch();
if (showChangeNickname(isMe, isPrivate)) { if (showChangeNickname(isMe, isPrivate, isRequest)) {
return ( return (
<Item <Item
onClick={() => { onClick={() => {
@ -550,6 +566,11 @@ export const ChangeNicknameMenuItem = () => {
export const DeleteMessagesMenuItem = () => { export const DeleteMessagesMenuItem = () => {
const convoId = useContext(ContextConversationId); const convoId = useContext(ContextConversationId);
const isRequest = useIsRequest(convoId);
if (isRequest) {
return null;
}
return ( return (
<Item <Item
@ -577,10 +598,10 @@ export const HideBannerMenuItem = (): JSX.Element => {
export const AcceptMenuItem = () => { export const AcceptMenuItem = () => {
const convoId = useContext(ContextConversationId); const convoId = useContext(ContextConversationId);
const isRequest = useIsRequest(convoId);
const convo = getConversationController().get(convoId); const convo = getConversationController().get(convoId);
const showMenuItem = convo.isRequest();
if (showMenuItem) { if (isRequest) {
return ( return (
<Item <Item
onClick={async () => { onClick={async () => {

@ -1,4 +1,5 @@
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { ConversationModel } from '../models/conversation';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import { UserUtils } from '../session/utils'; import { UserUtils } from '../session/utils';
import { StateType } from '../state/reducer'; import { StateType } from '../state/reducer';
@ -118,6 +119,24 @@ export function useIsPinned(convoId?: string) {
return Boolean(convoProps && convoProps.isPinned); return Boolean(convoProps && convoProps.isPinned);
} }
export function useIsApproved(convoId?: string) {
const convoProps = useConversationPropsById(convoId);
return Boolean(convoProps && convoProps.isApproved);
}
export function useIsRequest(convoId: string) {
const convoProps = useConversationPropsById(convoId);
return Boolean(
convoProps &&
ConversationModel.hasValidRequestValues({
isMe: convoProps.isMe,
isApproved: convoProps.isMe,
isPrivate: convoProps.isPrivate,
isBlocked: convoProps.isBlocked,
})
);
}
export function useConversationPropsById(convoId?: string) { export function useConversationPropsById(convoId?: string) {
return useSelector((state: StateType) => { return useSelector((state: StateType) => {
if (!convoId) { if (!convoId) {

Loading…
Cancel
Save