Removing some menu items from message request context menu.
This commit is contained in:
parent
56c1a06a28
commit
eed72a6b1b
|
@ -12,6 +12,7 @@ import {
|
|||
useIsMe,
|
||||
useIsPrivate,
|
||||
useIsPublic,
|
||||
useIsRequest,
|
||||
useNotificationSetting,
|
||||
useWeAreAdmin,
|
||||
} from '../../hooks/useParamSelector';
|
||||
|
@ -68,21 +69,27 @@ function showTimerOptions(
|
|||
function showNotificationConvo(
|
||||
isKickedFromGroup: boolean,
|
||||
left: boolean,
|
||||
isBlocked: boolean
|
||||
isBlocked: boolean,
|
||||
isRequest: boolean
|
||||
): boolean {
|
||||
return !left && !isKickedFromGroup && !isBlocked;
|
||||
return !left && !isKickedFromGroup && !isBlocked && !isRequest;
|
||||
}
|
||||
|
||||
function showBlock(isMe: boolean, isPrivate: boolean): boolean {
|
||||
return !isMe && isPrivate;
|
||||
function showBlock(isMe: boolean, isPrivate: boolean, isRequest: boolean): boolean {
|
||||
return !isMe && isPrivate && !isRequest;
|
||||
}
|
||||
|
||||
function showClearNickname(isMe: boolean, hasNickname: boolean, isPrivate: boolean): boolean {
|
||||
return !isMe && hasNickname && isPrivate;
|
||||
function showClearNickname(
|
||||
isMe: boolean,
|
||||
hasNickname: boolean,
|
||||
isPrivate: boolean,
|
||||
isRequest: boolean
|
||||
): boolean {
|
||||
return !isMe && hasNickname && isPrivate && isRequest;
|
||||
}
|
||||
|
||||
function showChangeNickname(isMe: boolean, isPrivate: boolean) {
|
||||
return !isMe && isPrivate;
|
||||
function showChangeNickname(isMe: boolean, isPrivate: boolean, isRequest: boolean) {
|
||||
return !isMe && isPrivate && !isRequest;
|
||||
}
|
||||
|
||||
// we want to show the copyId for open groups and private chats only
|
||||
|
@ -94,10 +101,11 @@ function showDeleteContact(
|
|||
isGroup: boolean,
|
||||
isPublic: boolean,
|
||||
isGroupLeft: boolean,
|
||||
isKickedFromGroup: boolean
|
||||
isKickedFromGroup: boolean,
|
||||
isRequest: boolean
|
||||
): boolean {
|
||||
// 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) => {
|
||||
|
@ -169,8 +177,9 @@ export const PinConversationMenuItem = (): JSX.Element | null => {
|
|||
const conversationId = useContext(ContextConversationId);
|
||||
const isMessagesSection = useSelector(getFocusedSection) === SectionType.Message;
|
||||
const nbOfAlreadyPinnedConvos = useSelector(getNumberOfPinnedConversations);
|
||||
const isRequest = useIsRequest(conversationId);
|
||||
|
||||
if (isMessagesSection) {
|
||||
if (isMessagesSection && !isRequest) {
|
||||
const conversation = getConversationController().get(conversationId);
|
||||
const isPinned = conversation?.isPinned() || false;
|
||||
|
||||
|
@ -199,8 +208,9 @@ export const DeleteContactMenuItem = () => {
|
|||
const isLeft = useIsLeft(convoId);
|
||||
const isKickedFromGroup = useIsKickedFromGroup(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;
|
||||
if (isPublic) {
|
||||
menuItemText = window.i18n('leaveGroup');
|
||||
|
@ -448,9 +458,12 @@ export const NotificationForConvoMenuItem = (): JSX.Element | null => {
|
|||
const left = useIsLeft(convoId);
|
||||
const isBlocked = useIsBlocked(convoId);
|
||||
const isPrivate = useIsPrivate(convoId);
|
||||
const isRequest = useIsRequest(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();'
|
||||
|
||||
// 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 isBlocked = useIsBlocked(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 blockHandler = isBlocked
|
||||
? () => unblockConvoById(convoId)
|
||||
|
@ -519,8 +533,9 @@ export const ClearNicknameMenuItem = (): JSX.Element | null => {
|
|||
const isMe = useIsMe(convoId);
|
||||
const hasNickname = useHasNickname(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 (
|
||||
<Item onClick={() => clearNickNameByConvoId(convoId)}>{window.i18n('clearNickname')}</Item>
|
||||
);
|
||||
|
@ -532,9 +547,10 @@ export const ChangeNicknameMenuItem = () => {
|
|||
const convoId = useContext(ContextConversationId);
|
||||
const isMe = useIsMe(convoId);
|
||||
const isPrivate = useIsPrivate(convoId);
|
||||
const isRequest = useIsRequest(convoId);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
if (showChangeNickname(isMe, isPrivate)) {
|
||||
if (showChangeNickname(isMe, isPrivate, isRequest)) {
|
||||
return (
|
||||
<Item
|
||||
onClick={() => {
|
||||
|
@ -550,6 +566,11 @@ export const ChangeNicknameMenuItem = () => {
|
|||
|
||||
export const DeleteMessagesMenuItem = () => {
|
||||
const convoId = useContext(ContextConversationId);
|
||||
const isRequest = useIsRequest(convoId);
|
||||
|
||||
if (isRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Item
|
||||
|
@ -577,10 +598,10 @@ export const HideBannerMenuItem = (): JSX.Element => {
|
|||
|
||||
export const AcceptMenuItem = () => {
|
||||
const convoId = useContext(ContextConversationId);
|
||||
const isRequest = useIsRequest(convoId);
|
||||
const convo = getConversationController().get(convoId);
|
||||
const showMenuItem = convo.isRequest();
|
||||
|
||||
if (showMenuItem) {
|
||||
if (isRequest) {
|
||||
return (
|
||||
<Item
|
||||
onClick={async () => {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { useSelector } from 'react-redux';
|
||||
import { ConversationModel } from '../models/conversation';
|
||||
import { PubKey } from '../session/types';
|
||||
import { UserUtils } from '../session/utils';
|
||||
import { StateType } from '../state/reducer';
|
||||
|
@ -118,6 +119,24 @@ export function useIsPinned(convoId?: string) {
|
|||
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) {
|
||||
return useSelector((state: StateType) => {
|
||||
if (!convoId) {
|
||||
|
|
Loading…
Reference in New Issue