Merge pull request #474 from BeaudanBrown/hide-menus

Remove most of the right click and cog menu options for the public chats
pull/478/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit e70b875226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1041,11 +1041,27 @@
"message": "Delete messages", "message": "Delete messages",
"description": "Menu item for deleting messages, title case." "description": "Menu item for deleting messages, title case."
}, },
"deletePublicConversationConfirmation": {
"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."
},
"deleteConversationConfirmation": { "deleteConversationConfirmation": {
"message": "Permanently delete this conversation?", "message": "Permanently delete this conversation?",
"description": "description":
"Confirmation dialog text that asks the user if they really wish to delete the conversation. Answer buttons use the strings 'ok' and 'cancel'. The deletion is permanent, i.e. it cannot be undone." "Confirmation dialog text that asks the user if they really wish to delete the conversation. Answer buttons use the strings 'ok' and 'cancel'. The deletion is permanent, i.e. it cannot be undone."
}, },
"deletePublicChannel": {
"message": "Leave public channel",
"description":
"Confirmation dialog title that asks the user if they really wish to delete a public channel. Answer buttons use the strings 'ok' and 'cancel'. The deletion is permanent, i.e. it cannot be undone."
},
"deletePublicChannelConfirmation": {
"message": "Leave this public channel?",
"description":
"Confirmation dialog text that tells the user what will happen if they leave the public channel."
},
"deleteContact": { "deleteContact": {
"message": "Delete contact", "message": "Delete contact",
"description": "description":

@ -195,7 +195,7 @@
return this.id === this.ourNumber; return this.id === this.ourNumber;
}, },
isPublic() { isPublic() {
return this.id.match(/^publicChat:/); return this.id && this.id.match(/^publicChat:/);
}, },
isClosable() { isClosable() {
return !this.isRss() || this.get('closable'); return !this.isRss() || this.get('closable');
@ -445,6 +445,7 @@
color, color,
type: this.isPrivate() ? 'direct' : 'group', type: this.isPrivate() ? 'direct' : 'group',
isMe: this.isMe(), isMe: this.isMe(),
isPublic: this.isPublic(),
isClosable: this.isClosable(), isClosable: this.isClosable(),
isTyping: typingKeys.length > 0, isTyping: typingKeys.length > 0,
lastUpdated: this.get('timestamp'), lastUpdated: this.get('timestamp'),
@ -2311,10 +2312,17 @@
}, },
deleteContact() { deleteContact() {
if (this.isPublic()) {
Whisper.events.trigger('showConfirmationDialog', {
message: i18n('deletePublicChannelConfirmation'),
onOk: () => ConversationController.deleteContact(this.id),
});
} else {
Whisper.events.trigger('showConfirmationDialog', { Whisper.events.trigger('showConfirmationDialog', {
message: i18n('deleteContactConfirmation'), message: i18n('deleteContactConfirmation'),
onOk: () => ConversationController.deleteContact(this.id), onOk: () => ConversationController.deleteContact(this.id),
}); });
}
}, },
async deletePublicMessage(message) { async deletePublicMessage(message) {
@ -2343,10 +2351,17 @@
}, },
deleteMessages() { deleteMessages() {
if (this.isPublic()) {
Whisper.events.trigger('showConfirmationDialog', {
message: i18n('deletePublicConversationConfirmation'),
onOk: () => ConversationController.deleteContact(this.id),
});
} else {
Whisper.events.trigger('showConfirmationDialog', { Whisper.events.trigger('showConfirmationDialog', {
message: i18n('deleteConversationConfirmation'), message: i18n('deleteContactConfirmation'),
onOk: () => this.destroyMessages(), onOk: () => ConversationController.deleteContact(this.id),
}); });
}
}, },
async destroyMessages() { async destroyMessages() {

@ -206,6 +206,7 @@
isGroup: !this.model.isPrivate(), isGroup: !this.model.isPrivate(),
isOnline: this.model.isOnline(), isOnline: this.model.isOnline(),
isArchived: this.model.get('isArchived'), isArchived: this.model.get('isArchived'),
isPublic: this.model.isPublic(),
expirationSettingName, expirationSettingName,
showBackButton: Boolean(this.panels && this.panels.length), showBackButton: Boolean(this.panels && this.panels.length),
@ -1510,6 +1511,22 @@
}, },
destroyMessages() { destroyMessages() {
if (this.model.isPublic()) {
Whisper.events.trigger('showConfirmationDialog', {
message: i18n('deletePublicConversationConfirmation'),
onOk: async () => {
try {
await this.model.destroyMessages();
this.unload('delete messages');
} catch (error) {
window.log.error(
'destroyMessages: Failed to successfully delete conversation',
error && error.stack ? error.stack : error
);
}
},
});
} else {
Whisper.events.trigger('showConfirmationDialog', { Whisper.events.trigger('showConfirmationDialog', {
message: i18n('deleteConversationConfirmation'), message: i18n('deleteConversationConfirmation'),
onOk: async () => { onOk: async () => {
@ -1524,6 +1541,7 @@
} }
}, },
}); });
}
}, },
showSendConfirmationDialog(e, contacts) { showSendConfirmationDialog(e, contacts) {

@ -21,6 +21,7 @@ export type PropsData = {
type: 'group' | 'direct'; type: 'group' | 'direct';
avatarPath?: string; avatarPath?: string;
isMe: boolean; isMe: boolean;
isPublic?: boolean;
isClosable?: boolean; isClosable?: boolean;
lastUpdated: number; lastUpdated: number;
@ -165,6 +166,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
isBlocked, isBlocked,
isMe, isMe,
isClosable, isClosable,
isPublic,
hasNickname, hasNickname,
onDeleteContact, onDeleteContact,
onDeleteMessages, onDeleteMessages,
@ -180,21 +182,31 @@ export class ConversationListItem extends React.PureComponent<Props> {
return ( return (
<ContextMenu id={triggerId}> <ContextMenu id={triggerId}>
{!isMe ? ( {!isPublic && !isMe ? (
<MenuItem onClick={blockHandler}>{blockTitle}</MenuItem> <MenuItem onClick={blockHandler}>{blockTitle}</MenuItem>
) : null} ) : null}
{!isMe ? ( {!isPublic && !isMe ? (
<MenuItem onClick={onChangeNickname}> <MenuItem onClick={onChangeNickname}>
{i18n('changeNickname')} {i18n('changeNickname')}
</MenuItem> </MenuItem>
) : null} ) : null}
{!isMe && hasNickname ? ( {!isPublic && !isMe && hasNickname ? (
<MenuItem onClick={onClearNickname}>{i18n('clearNickname')}</MenuItem> <MenuItem onClick={onClearNickname}>{i18n('clearNickname')}</MenuItem>
) : null} ) : null}
{!isPublic ? (
<MenuItem onClick={onCopyPublicKey}>{i18n('copyPublicKey')}</MenuItem> <MenuItem onClick={onCopyPublicKey}>{i18n('copyPublicKey')}</MenuItem>
) : null}
<MenuItem onClick={onDeleteMessages}>{i18n('deleteMessages')}</MenuItem> <MenuItem onClick={onDeleteMessages}>{i18n('deleteMessages')}</MenuItem>
{!isMe && isClosable ? ( {!isMe && isClosable ? (
<MenuItem onClick={onDeleteContact}>{i18n('deleteContact')}</MenuItem> !isPublic ? (
<MenuItem onClick={onDeleteContact}>
{i18n('deleteContact')}
</MenuItem>
) : (
<MenuItem onClick={onDeleteContact}>
{i18n('deletePublicChannel')}
</MenuItem>
)
) : null} ) : null}
</ContextMenu> </ContextMenu>
); );

@ -29,6 +29,7 @@ interface Props {
isClosable?: boolean; isClosable?: boolean;
isGroup: boolean; isGroup: boolean;
isArchived: boolean; isArchived: boolean;
isPublic: boolean;
expirationSettingName?: string; expirationSettingName?: string;
showBackButton: boolean; showBackButton: boolean;
@ -200,13 +201,62 @@ export class ConversationHeader extends React.Component<Props> {
public renderMenu(triggerId: string) { public renderMenu(triggerId: string) {
const { const {
i18n, i18n,
isBlocked,
isMe, isMe,
isClosable, isClosable,
isGroup, isPublic,
isArchived,
onDeleteMessages, onDeleteMessages,
onDeleteContact, onDeleteContact,
onCopyPublicKey,
} = this.props;
return (
<ContextMenu id={triggerId}>
{this.renderPublicMenuItems()}
<MenuItem onClick={onCopyPublicKey}>{i18n('copyPublicKey')}</MenuItem>
<MenuItem onClick={onDeleteMessages}>{i18n('deleteMessages')}</MenuItem>
{!isMe && isClosable ? (
!isPublic ? (
<MenuItem onClick={onDeleteContact}>
{i18n('deleteContact')}
</MenuItem>
) : (
<MenuItem onClick={onDeleteContact}>
{i18n('deletePublicChannel')}
</MenuItem>
)
) : null}
</ContextMenu>
);
}
public render() {
const { id } = this.props;
const triggerId = `conversation-${id}`;
return (
<div className="module-conversation-header">
{this.renderBackButton()}
<div className="module-conversation-header__title-container">
<div className="module-conversation-header__title-flex">
{this.renderAvatar()}
{this.renderTitle()}
</div>
</div>
{this.renderExpirationLength()}
{this.renderGear(triggerId)}
{this.renderMenu(triggerId)}
</div>
);
}
private renderPublicMenuItems() {
const {
i18n,
isBlocked,
isMe,
isGroup,
isArchived,
isPublic,
onResetSession, onResetSession,
onSetDisappearingMessages, onSetDisappearingMessages,
// onShowAllMedia, // onShowAllMedia,
@ -220,16 +270,18 @@ export class ConversationHeader extends React.Component<Props> {
hasNickname, hasNickname,
onClearNickname, onClearNickname,
onChangeNickname, onChangeNickname,
onCopyPublicKey,
} = this.props; } = this.props;
if (isPublic) {
return null;
}
const disappearingTitle = i18n('disappearingMessages') as any; const disappearingTitle = i18n('disappearingMessages') as any;
const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser'); const blockTitle = isBlocked ? i18n('unblockUser') : i18n('blockUser');
const blockHandler = isBlocked ? onUnblockUser : onBlockUser; const blockHandler = isBlocked ? onUnblockUser : onBlockUser;
return ( const disappearingMessagesMenuItem = (
<ContextMenu id={triggerId}>
<SubMenu title={disappearingTitle}> <SubMenu title={disappearingTitle}>
{(timerOptions || []).map(item => ( {(timerOptions || []).map(item => (
<MenuItem <MenuItem
@ -242,65 +294,49 @@ export class ConversationHeader extends React.Component<Props> {
</MenuItem> </MenuItem>
))} ))}
</SubMenu> </SubMenu>
{/* <MenuItem onClick={onShowAllMedia}>{i18n('viewAllMedia')}</MenuItem> */} );
{isGroup ? ( const showMembersMenuItem = isGroup && (
<MenuItem onClick={onShowGroupMembers}> <MenuItem onClick={onShowGroupMembers}>{i18n('showMembers')}</MenuItem>
{i18n('showMembers')} );
</MenuItem> const showSafetyNumberMenuItem = !isGroup &&
) : null} !isMe && (
{!isGroup && !isMe ? (
<MenuItem onClick={onShowSafetyNumber}> <MenuItem onClick={onShowSafetyNumber}>
{i18n('showSafetyNumber')} {i18n('showSafetyNumber')}
</MenuItem> </MenuItem>
) : null} );
{!isGroup ? ( const resetSessionMenuItem = !isGroup && (
<MenuItem onClick={onResetSession}>{i18n('resetSession')}</MenuItem> <MenuItem onClick={onResetSession}>{i18n('resetSession')}</MenuItem>
) : null} );
{/* Only show the block on other conversations */} const blockHandlerMenuItem = !isMe && (
{!isMe ? (
<MenuItem onClick={blockHandler}>{blockTitle}</MenuItem> <MenuItem onClick={blockHandler}>{blockTitle}</MenuItem>
) : null} );
{!isMe ? ( const changeNicknameMenuItem = !isMe && (
<MenuItem onClick={onChangeNickname}> <MenuItem onClick={onChangeNickname}>{i18n('changeNickname')}</MenuItem>
{i18n('changeNickname')} );
</MenuItem> const clearNicknameMenuItem = !isMe &&
) : null} hasNickname && (
{!isMe && hasNickname ? (
<MenuItem onClick={onClearNickname}>{i18n('clearNickname')}</MenuItem> <MenuItem onClick={onClearNickname}>{i18n('clearNickname')}</MenuItem>
) : null} );
<MenuItem onClick={onCopyPublicKey}>{i18n('copyPublicKey')}</MenuItem> const archiveConversationMenuItem = isArchived ? (
{isArchived ? (
<MenuItem onClick={onMoveToInbox}> <MenuItem onClick={onMoveToInbox}>
{i18n('moveConversationToInbox')} {i18n('moveConversationToInbox')}
</MenuItem> </MenuItem>
) : ( ) : (
<MenuItem onClick={onArchive}>{i18n('archiveConversation')}</MenuItem> <MenuItem onClick={onArchive}>{i18n('archiveConversation')}</MenuItem>
)}
<MenuItem onClick={onDeleteMessages}>{i18n('deleteMessages')}</MenuItem>
{!isMe && isClosable ? (
<MenuItem onClick={onDeleteContact}>{i18n('deleteContact')}</MenuItem>
) : null}
</ContextMenu>
); );
}
public render() {
const { id } = this.props;
const triggerId = `conversation-${id}`;
return ( return (
<div className="module-conversation-header"> <React.Fragment>
{this.renderBackButton()} {/* <MenuItem onClick={onShowAllMedia}>{i18n('viewAllMedia')}</MenuItem> */}
<div className="module-conversation-header__title-container"> {disappearingMessagesMenuItem}
<div className="module-conversation-header__title-flex"> {showMembersMenuItem}
{this.renderAvatar()} {showSafetyNumberMenuItem}
{this.renderTitle()} {resetSessionMenuItem}
</div> {blockHandlerMenuItem}
</div> {changeNicknameMenuItem}
{this.renderExpirationLength()} {clearNicknameMenuItem}
{this.renderGear(triggerId)} {archiveConversationMenuItem}
{this.renderMenu(triggerId)} </React.Fragment>
</div>
); );
} }
} }

@ -45,6 +45,7 @@ export type ConversationType = {
phoneNumber: string; phoneNumber: string;
type: 'direct' | 'group'; type: 'direct' | 'group';
isMe: boolean; isMe: boolean;
isPublic?: boolean;
isClosable?: boolean; isClosable?: boolean;
lastUpdated: number; lastUpdated: number;
unreadCount: number; unreadCount: number;

Loading…
Cancel
Save