diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index e49d28380..2a7fa5e2b 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -172,6 +172,7 @@ isClosable: this.model.isClosable(), isBlocked: this.model.isBlocked(), isGroup: !this.model.isPrivate(), + isPrivate: this.model.isPrivate(), isOnline: this.model.isOnline(), isArchived: this.model.get('isArchived'), isPublic: this.model.isPublic(), diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 686fb4a36..75b48e443 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -11,6 +11,12 @@ import { ContactName } from './conversation/ContactName'; import { TypingAnimation } from './conversation/TypingAnimation'; import { Colors, LocalizerType } from '../types/Util'; +import { + showClearNickname, + showBlock, + showCopyId, + showDeleteContact, +} from '../session/utils/Menu'; export type PropsData = { id: string; @@ -179,7 +185,7 @@ export class ConversationListItem extends React.PureComponent { return ( - {!isPublic && !isRss && !isMe && isPrivate ? ( + {showBlock(isMe, isPrivate) ? ( {blockTitle} ) : null} {/* {!isPublic && !isRss && !isMe ? ( @@ -187,14 +193,20 @@ export class ConversationListItem extends React.PureComponent { {i18n('changeNickname')} ) : null} */} - {!isPublic && !isRss && !isMe && hasNickname ? ( + {showClearNickname(isPublic, isRss, isMe, hasNickname) ? ( {i18n('clearNickname')} ) : null} - {!isPublic && !isRss ? ( + {showCopyId(isPublic, isRss) ? ( {i18n('copyPublicKey')} ) : null} {i18n('deleteMessages')} - {!isMe && isClosable ? ( + {showDeleteContact( + isMe, + isClosable, + type === 'group', + isPublic, + isRss + ) ? ( !isPublic ? ( {i18n('deleteContact')} diff --git a/ts/components/conversation/ConversationHeader.tsx b/ts/components/conversation/ConversationHeader.tsx index 8a66cf64a..0e530554d 100644 --- a/ts/components/conversation/ConversationHeader.tsx +++ b/ts/components/conversation/ConversationHeader.tsx @@ -20,6 +20,20 @@ import { SessionButtonColor, SessionButtonType, } from '../session/SessionButton'; +import { + showAddModerators, + showBlock, + showCopyId, + showDeleteContact, + showInviteContact, + showLeaveGroup, + showMemberMenu, + showRemoveModerators, + showResetSession, + showSafetyNumber, + showTimerOptions, + showUpdateGroupName, +} from '../../session/utils/Menu'; export interface TimerOption { name: string; @@ -38,6 +52,7 @@ interface Props { isMe: boolean; isClosable?: boolean; isGroup: boolean; + isPrivate: boolean; isArchived: boolean; isPublic: boolean; isRss: boolean; @@ -304,40 +319,38 @@ export class ConversationHeader extends React.Component { onUpdateGroupName, } = this.props; - const isPrivateGroup = isGroup && !isPublic && !isRss; - const copyIdLabel = isGroup ? i18n('copyChatId') : i18n('copyPublicKey'); return ( {this.renderPublicMenuItems()} - {!isRss ? ( + {showCopyId(isPublic, isRss) ? ( {copyIdLabel} ) : null} {i18n('deleteMessages')} - {amMod && !isKickedFromGroup ? ( + {showAddModerators(amMod, isKickedFromGroup) ? ( {i18n('addModerators')} ) : null} - {amMod && !isKickedFromGroup ? ( + {showRemoveModerators(amMod, isKickedFromGroup) ? ( {i18n('removeModerators')} ) : null} - {amMod && !isKickedFromGroup ? ( + {showUpdateGroupName(amMod, isKickedFromGroup) ? ( {i18n('editGroupNameOrPicture')} ) : null} - {isPrivateGroup && !isKickedFromGroup ? ( + {showLeaveGroup(isKickedFromGroup, isGroup, isPublic, isRss) ? ( {i18n('leaveGroup')} ) : null} {/* TODO: add delete group */} - {isGroup && isPublic ? ( + {showInviteContact(isGroup, isPublic) ? ( {i18n('inviteContacts')} ) : null} - {!isMe && isClosable && !isPrivateGroup ? ( + {showDeleteContact(isMe, isClosable, isGroup, isPublic, isRss) ? ( !isPublic ? ( {i18n('deleteContact')} @@ -433,6 +446,7 @@ export class ConversationHeader extends React.Component { isBlocked, isMe, isGroup, + isPrivate, isKickedFromGroup, isPublic, isRss, @@ -454,7 +468,12 @@ export class ConversationHeader extends React.Component { const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser'); const blockHandler = isBlocked ? onUnblockUser : onBlockUser; - const disappearingMessagesMenuItem = !isKickedFromGroup && !isBlocked && ( + const disappearingMessagesMenuItem = showTimerOptions( + isPublic, + isRss, + isKickedFromGroup, + isBlocked + ) && ( {(timerOptions || []).map(item => ( { ))} ); - const showMembersMenuItem = isGroup && ( + const showMembersMenuItem = showMemberMenu(isPublic, isRss, isGroup) && ( {i18n('showMembers')} ); - const showSafetyNumberMenuItem = !isGroup && !isMe && ( + const showSafetyNumberMenuItem = showSafetyNumber( + isPublic, + isRss, + isGroup, + isMe + ) && ( {i18n('showSafetyNumber')} ); - const resetSessionMenuItem = !isGroup && ( + const resetSessionMenuItem = showResetSession(isPublic, isRss, isGroup) && ( {i18n('resetSession')} ); - const blockHandlerMenuItem = !isMe && !isRss && !isGroup && ( + const blockHandlerMenuItem = showBlock(isMe, isPrivate) && ( {blockTitle} ); diff --git a/ts/session/utils/Menu.ts b/ts/session/utils/Menu.ts new file mode 100644 index 000000000..63418c5b0 --- /dev/null +++ b/ts/session/utils/Menu.ts @@ -0,0 +1,111 @@ +export function showTimerOptions( + isPublic: boolean, + isRss: boolean, + isKickedFromGroup: boolean, + isBlocked: boolean +): boolean { + return ( + Boolean(!isPublic) && Boolean(!isRss) && !isKickedFromGroup && !isBlocked + ); +} + +export function showMemberMenu( + isPublic: boolean, + isRss: boolean, + isGroup: boolean +): boolean { + return Boolean(!isPublic) && Boolean(!isRss) && isGroup; +} + +export function showSafetyNumber( + isPublic: boolean, + isRss: boolean, + isGroup: boolean, + isMe: boolean +): boolean { + return Boolean(!isPublic) && Boolean(!isRss) && !isGroup && !isMe; +} + +export function showResetSession( + isPublic: boolean, + isRss: boolean, + isGroup: boolean +): boolean { + return Boolean(!isPublic) && Boolean(!isRss) && Boolean(!isGroup); +} + +export function showBlock( + isMe: boolean | undefined, + isPrivate: boolean | undefined +): boolean { + return Boolean(!isMe) && Boolean(isPrivate); +} + +export function showClearNickname( + isPublic: boolean | undefined, + isRss: boolean | undefined, + isMe: boolean | undefined, + hasNickname: boolean | undefined +): boolean { + return ( + Boolean(!isPublic) && + Boolean(!isRss) && + Boolean(!isMe) && + Boolean(hasNickname) + ); +} + +export function showCopyId( + isPublic: boolean | undefined, + isRss: boolean | undefined +): boolean { + return Boolean(!isPublic) && Boolean(!isRss); +} + +export function showDeleteContact( + isMe: boolean | undefined, + isClosable: boolean | undefined, + isGroup: boolean | undefined, + isPublic: boolean | undefined, + isRss: boolean | undefined +): boolean { + return ( + Boolean(!isMe) && Boolean(isClosable) && !!(!isGroup || isPublic || isRss) + ); +} + +export function showAddModerators( + amMod: boolean | undefined, + isKickedFromGroup: boolean | undefined +): boolean { + return Boolean(!isKickedFromGroup) && Boolean(amMod); +} + +export function showRemoveModerators( + amMod: boolean | undefined, + isKickedFromGroup: boolean | undefined +): boolean { + return Boolean(!isKickedFromGroup) && Boolean(amMod); +} +export function showUpdateGroupName( + amMod: boolean | undefined, + isKickedFromGroup: boolean | undefined +): boolean { + return Boolean(!isKickedFromGroup) && Boolean(amMod); +} + +export function showLeaveGroup( + isKickedFromGroup: boolean | undefined, + isGroup: boolean | undefined, + isPublic: boolean | undefined, + isRss: boolean | undefined +): boolean { + return Boolean(!isKickedFromGroup) && !!(!isGroup || isPublic || isRss); +} + +export function showInviteContact( + isGroup: boolean | undefined, + isPublic: boolean | undefined +): boolean { + return Boolean(isGroup) && Boolean(isPublic); +} diff --git a/ts/session/utils/index.ts b/ts/session/utils/index.ts index d9cafc0fa..b38705d0e 100644 --- a/ts/session/utils/index.ts +++ b/ts/session/utils/index.ts @@ -5,6 +5,7 @@ import * as StringUtils from './String'; import * as NumberUtils from './Number'; import * as PromiseUtils from './Promise'; import * as ProtobufUtils from './Protobuf'; +import * as MenuUtils from './Menu'; export * from './Attachments'; export * from './TypedEmitter'; @@ -18,4 +19,5 @@ export { NumberUtils, PromiseUtils, ProtobufUtils, + MenuUtils, };