From 3c23a07d8b9bb3acefadd09e44dac2b97283df59 Mon Sep 17 00:00:00 2001 From: Chris Duarte Date: Fri, 8 Dec 2017 13:19:48 -0800 Subject: [PATCH] Add ability to copy post permalink (#1255) --- app/components/post/index.js | 2 ++ app/components/post/post.js | 9 +++++++++ app/components/post_body/post_body.js | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/app/components/post/index.js b/app/components/post/index.js index 31fbaf4c8..85e88a3a2 100644 --- a/app/components/post/index.js +++ b/app/components/post/index.js @@ -8,6 +8,7 @@ import {createPost, deletePost, removePost} from 'mattermost-redux/actions/posts import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; import {getMyPreferences, getTheme} from 'mattermost-redux/selectors/entities/preferences'; +import {getCurrentTeamUrl} from 'mattermost-redux/selectors/entities/teams'; import {isPostFlagged} from 'mattermost-redux/utils/post_utils'; import {insertToDraft, setPostTooltipVisible} from 'app/actions/views/channel'; @@ -49,6 +50,7 @@ function mapStateToProps(state, ownProps) { return { config, + currentTeamUrl: getCurrentTeamUrl(state), currentUserId: getCurrentUserId(state), post, isFirstReply, diff --git a/app/components/post/post.js b/app/components/post/post.js index d0d35bbd1..7bb6bdce9 100644 --- a/app/components/post/post.js +++ b/app/components/post/post.js @@ -39,6 +39,7 @@ class Post extends PureComponent { removePost: PropTypes.func.isRequired }).isRequired, config: PropTypes.object.isRequired, + currentTeamUrl: PropTypes.string.isRequired, currentUserId: PropTypes.string.isRequired, highlight: PropTypes.bool, intl: intlShape.isRequired, @@ -337,6 +338,13 @@ class Post extends PureComponent { Clipboard.setString(textToCopy); } + handleCopyPermalink = () => { + const {currentTeamUrl, postId} = this.props; + const permalink = `${currentTeamUrl}/pl/${postId}`; + + Clipboard.setString(permalink); + } + render() { const { commentedOnPost, @@ -392,6 +400,7 @@ class Post extends PureComponent { isSearchResult={isSearchResult} navigator={this.props.navigator} onAddReaction={this.handleAddReaction} + onCopyPermalink={this.handleCopyPermalink} onCopyText={this.handleCopyText} onFailedPostPress={this.handleFailedPostPress} onPostDelete={this.handlePostDelete} diff --git a/app/components/post_body/post_body.js b/app/components/post_body/post_body.js index 9fa6df11e..0edaaf00a 100644 --- a/app/components/post_body/post_body.js +++ b/app/components/post_body/post_body.js @@ -47,6 +47,7 @@ class PostBody extends PureComponent { message: PropTypes.string, navigator: PropTypes.object.isRequired, onAddReaction: PropTypes.func, + onCopyPermalink: PropTypes.func, onCopyText: PropTypes.func, onFailedPostPress: PropTypes.func, onPostDelete: PropTypes.func, @@ -62,6 +63,7 @@ class PostBody extends PureComponent { static defaultProps = { fileIds: [], onAddReaction: emptyFunction, + onCopyPermalink: emptyFunction, onCopyText: emptyFunction, onFailedPostPress: emptyFunction, onPostDelete: emptyFunction, @@ -198,6 +200,11 @@ class PostBody extends PureComponent { if (canDelete && !hasBeenDeleted) { actions.push({text: formatMessage({id: 'post_info.del', defaultMessage: 'Delete'}), onPress: onPostDelete}); } + + actions.push({ + text: formatMessage({id: 'get_post_link_modal.title', defaultMessage: 'Copy Permalink'}), + onPress: this.props.onCopyPermalink + }); } let body;