From 870dc7f904f6818f8656c79d4b3330e6351f001b Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Wed, 4 Sep 2019 10:58:32 +1000 Subject: [PATCH] Fix tests, refactor menu items to please linter and lint --- _locales/en/messages.json | 3 +- js/models/conversations.js | 2 +- ts/components/ConversationListItem.tsx | 8 +- .../conversation/ConversationHeader.tsx | 168 ++++++++++-------- ts/components/conversation/MessageDetail.tsx | 22 ++- 5 files changed, 115 insertions(+), 88 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 57ce3a524..e58951412 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1042,7 +1042,8 @@ "description": "Menu item for deleting messages, title case." }, "deletePublicConversationConfirmation": { - "message": "Permanently delete the messages locally from this public channel?", + "message": + "Permanently delete the messages locally from this public channel?", "description": "Confirmation dialog text that asks the user if they really wish to delete the public channel messages locally. Answer buttons use the strings 'ok' and 'cancel'. The deletion is permanent, i.e. it cannot be undone." }, diff --git a/js/models/conversations.js b/js/models/conversations.js index 7ee09277c..84ab4c509 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -195,7 +195,7 @@ return this.id === this.ourNumber; }, isPublic() { - return this.id.match(/^publicChat:/); + return this.id && this.id.match(/^publicChat:/); }, isClosable() { return !this.isRss() || this.get('closable'); diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 5d4ea63f3..3a2fab947 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -199,9 +199,13 @@ export class ConversationListItem extends React.PureComponent { {i18n('deleteMessages')} {!isMe && isClosable ? ( !isPublic ? ( - {i18n('deleteContact')} + + {i18n('deleteContact')} + ) : ( - {i18n('deletePublicChannel')} + + {i18n('deletePublicChannel')} + ) ) : null} diff --git a/ts/components/conversation/ConversationHeader.tsx b/ts/components/conversation/ConversationHeader.tsx index 7b221f10d..18bd7721d 100644 --- a/ts/components/conversation/ConversationHeader.tsx +++ b/ts/components/conversation/ConversationHeader.tsx @@ -201,93 +201,28 @@ export class ConversationHeader extends React.Component { public renderMenu(triggerId: string) { const { i18n, - isBlocked, isMe, isClosable, - isGroup, - isArchived, isPublic, onDeleteMessages, onDeleteContact, - onResetSession, - onSetDisappearingMessages, - // onShowAllMedia, - onShowGroupMembers, - onShowSafetyNumber, - onArchive, - onMoveToInbox, - timerOptions, - onBlockUser, - onUnblockUser, - hasNickname, - onClearNickname, - onChangeNickname, onCopyPublicKey, } = this.props; - const disappearingTitle = i18n('disappearingMessages') as any; - - const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser'); - const blockHandler = isBlocked ? onUnblockUser : onBlockUser; - return ( - {!isPublic ? ( - - {(timerOptions || []).map(item => ( - { - onSetDisappearingMessages(item.value); - }} - > - {item.name} - - ))} - - ) : null} - {/* {i18n('viewAllMedia')} */} - {!isPublic && isGroup ? ( - - {i18n('showMembers')} - - ) : null} - {!isPublic && !isGroup && !isMe ? ( - - {i18n('showSafetyNumber')} - - ) : null} - {!isPublic && !isGroup ? ( - {i18n('resetSession')} - ) : null} - {/* Only show the block on other conversations */} - {!isPublic && !isMe ? ( - {blockTitle} - ) : null} - {!isPublic && !isMe ? ( - - {i18n('changeNickname')} - - ) : null} - {!isPublic && !isMe && hasNickname ? ( - {i18n('clearNickname')} - ) : null} + {this.renderPublicMenuItems()} {i18n('copyPublicKey')} - {!isPublic ? ( - isArchived ? ( - - {i18n('moveConversationToInbox')} - - ) : ( - {i18n('archiveConversation')} - ) - ) : null} {i18n('deleteMessages')} {!isMe && isClosable ? ( !isPublic ? ( - {i18n('deleteContact')} + + {i18n('deleteContact')} + ) : ( - {i18n('deletePublicChannel')} + + {i18n('deletePublicChannel')} + ) ) : null} @@ -313,4 +248,93 @@ export class ConversationHeader extends React.Component { ); } + + private renderPublicMenuItems() { + const { + i18n, + isBlocked, + isMe, + isGroup, + isArchived, + isPublic, + onResetSession, + onSetDisappearingMessages, + // onShowAllMedia, + onShowGroupMembers, + onShowSafetyNumber, + onArchive, + onMoveToInbox, + timerOptions, + onBlockUser, + onUnblockUser, + hasNickname, + onClearNickname, + onChangeNickname, + } = this.props; + + const disappearingTitle = i18n('disappearingMessages') as any; + + const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser'); + const blockHandler = isBlocked ? onUnblockUser : onBlockUser; + + const disappearingMessagesMenuItem = ( + + {(timerOptions || []).map(item => ( + { + onSetDisappearingMessages(item.value); + }} + > + {item.name} + + ))} + + ); + const showMembersMenuItem = isGroup && ( + {i18n('showMembers')} + ); + const showSafetyNumberMenuItem = !isGroup && + !isMe && ( + + {i18n('showSafetyNumber')} + + ); + const resetSessionMenuItem = !isGroup && ( + {i18n('resetSession')} + ); + const blockHandlerMenuItem = !isMe && ( + {blockTitle} + ); + const changeNicknameMenuItem = !isMe && ( + {i18n('changeNickname')} + ); + const clearNicknameMenuItem = !isMe && + hasNickname && ( + {i18n('clearNickname')} + ); + const archiveConversationMenuItem = isArchived ? ( + + {i18n('moveConversationToInbox')} + + ) : ( + {i18n('archiveConversation')} + ); + + return ( + !isPublic && ( + + {/* {i18n('viewAllMedia')} */} + {disappearingMessagesMenuItem} + {showMembersMenuItem} + {showSafetyNumberMenuItem} + {resetSessionMenuItem} + {blockHandlerMenuItem} + {changeNicknameMenuItem} + {clearNicknameMenuItem} + {archiveConversationMenuItem} + + ) + ); + } } diff --git a/ts/components/conversation/MessageDetail.tsx b/ts/components/conversation/MessageDetail.tsx index 1a18a780a..deca2a6b4 100644 --- a/ts/components/conversation/MessageDetail.tsx +++ b/ts/components/conversation/MessageDetail.tsx @@ -56,18 +56,16 @@ export class MessageDetail extends React.Component { public renderDeleteButton() { const { i18n, message } = this.props; - return ( - message.isDeletable ? ( -
- -
- ) : null - ); + return message.isDeletable ? ( +
+ +
+ ) : null; } public renderContact(contact: Contact) {