From 76b8fba358cc0106a54fbc968239dd1a3c8e3513 Mon Sep 17 00:00:00 2001 From: enahum Date: Mon, 2 Oct 2017 15:27:51 -0300 Subject: [PATCH] Remove context menu for system and ephemeral messages (#981) --- .../options_context.android.js | 4 +-- .../options_context/options_context.ios.js | 25 ++++++++++++++++--- app/components/post/post.js | 10 +++++--- app/components/post_body/index.js | 3 ++- app/components/post_body/post_body.js | 5 ++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/app/components/options_context/options_context.android.js b/app/components/options_context/options_context.android.js index 4017e2d53..0d84ddd5d 100644 --- a/app/components/options_context/options_context.android.js +++ b/app/components/options_context/options_context.android.js @@ -39,11 +39,11 @@ export default class OptionsContext extends PureComponent { }; handleHideUnderlay = () => { - this.props.toggleSelected(false); + this.props.toggleSelected(false, this.props.actions.length > 0); }; handleShowUnderlay = () => { - this.props.toggleSelected(true); + this.props.toggleSelected(true, this.props.actions.length > 0); }; render() { diff --git a/app/components/options_context/options_context.ios.js b/app/components/options_context/options_context.ios.js index c70e88450..17b441850 100644 --- a/app/components/options_context/options_context.ios.js +++ b/app/components/options_context/options_context.ios.js @@ -17,12 +17,24 @@ export default class OptionsContext extends PureComponent { actions: [] }; + handleHideUnderlay = () => { + if (!this.isShowing) { + this.props.toggleSelected(false, false); + } + }; + + handleShowUnderlay = () => { + this.props.toggleSelected(true, false); + }; + handleHide = () => { - this.props.toggleSelected(false); + this.isShowing = false; + this.props.toggleSelected(false, this.props.actions.length > 0); }; handleShow = () => { - this.props.toggleSelected(true); + this.isShowing = this.props.actions.length > 0; + this.props.toggleSelected(true, this.isShowing); }; hide = () => { @@ -33,14 +45,21 @@ export default class OptionsContext extends PureComponent { this.refs.toolTip.showMenu(); }; + handlePress = () => { + this.props.toggleSelected(false, this.props.actions.length > 0); + this.props.onPress(); + }; + render() { return ( { - const {isSearchResult} = this.props; + const {isSearchResult, tooltipVisible} = this.props; - if (!isSearchResult) { + if (!isSearchResult && !tooltipVisible) { preventDoubleTap(this.goToUserProfile, this); } }; - toggleSelected = (selected) => { - this.props.actions.setPostTooltipVisible(selected); + toggleSelected = (selected, tooltip) => { + if (tooltip) { + this.props.actions.setPostTooltipVisible(selected); + } this.setState({selected}); }; diff --git a/app/components/post_body/index.js b/app/components/post_body/index.js index 83a577299..c1ff4ce99 100644 --- a/app/components/post_body/index.js +++ b/app/components/post_body/index.js @@ -8,7 +8,7 @@ import {flagPost, unflagPost} from 'mattermost-redux/actions/posts'; import {Posts} from 'mattermost-redux/constants'; import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; -import {isPostFlagged, isSystemMessage} from 'mattermost-redux/utils/post_utils'; +import {isPostFlagged, isPostEphemeral, isSystemMessage} from 'mattermost-redux/utils/post_utils'; import {getTheme} from 'app/selectors/preferences'; @@ -27,6 +27,7 @@ function mapStateToProps(state, ownProps) { isFailed: post.failed, isFlagged: isPostFlagged(post.id, myPreferences), isPending: post.id === post.pending_post_id, + isPostEphemeral: isPostEphemeral(post), isSystemMessage: isSystemMessage(post), message: post.message, theme: getTheme(state) diff --git a/app/components/post_body/post_body.js b/app/components/post_body/post_body.js index 006f797d3..a108eea3b 100644 --- a/app/components/post_body/post_body.js +++ b/app/components/post_body/post_body.js @@ -39,6 +39,7 @@ class PostBody extends PureComponent { isFailed: PropTypes.bool, isFlagged: PropTypes.bool, isPending: PropTypes.bool, + isPostEphemeral: PropTypes.bool, isSearchResult: PropTypes.bool, isSystemMessage: PropTypes.bool, message: PropTypes.string, @@ -133,6 +134,7 @@ class PostBody extends PureComponent { isFailed, isFlagged, isPending, + isPostEphemeral, isSearchResult, isSystemMessage, intl, @@ -157,7 +159,7 @@ class PostBody extends PureComponent { const isPendingOrFailedPost = isPending || isFailed; // we should check for the user roles and permissions - if (!isPendingOrFailedPost && !isSearchResult) { + if (!isPendingOrFailedPost && !isSearchResult && !isSystemMessage && !isPostEphemeral) { if (isFlagged) { actions.push({ text: formatMessage({id: 'post_info.mobile.unflag', defaultMessage: 'Unflag'}), @@ -219,7 +221,6 @@ class PostBody extends PureComponent { body = (