PLT-7379: Timestamp on deleted, ephemeral, or pending post is a permalink (#7295)

* Removed permalink from system messages, general cleanup

* Removed permalink from deleted messages

* Removed permalink from pending messages

* Fixed post_info tests

* Changed permalink logic to remove permalinks from ephemeral messages, but leave them in place for system messages.

* Fixed check style
Этот коммит содержится в:
Jonathan
2017-08-30 08:06:29 -04:00
коммит произвёл Saturnino Abril
родитель 213a072b38
Коммит 4c1f467442
4 изменённых файлов: 35 добавлений и 17 удалений

Просмотреть файл

@@ -9,6 +9,7 @@ import DotMenu from 'components/dot_menu';
import * as Utils from 'utils/utils.jsx'; import * as Utils from 'utils/utils.jsx';
import * as PostUtils from 'utils/post_utils.jsx'; import * as PostUtils from 'utils/post_utils.jsx';
import * as ReduxPostUtils from 'mattermost-redux/utils/post_utils';
import {emitEmojiPosted} from 'actions/post_actions.jsx'; import {emitEmojiPosted} from 'actions/post_actions.jsx';
import Constants from 'utils/constants.jsx'; import Constants from 'utils/constants.jsx';
import {Posts} from 'mattermost-redux/constants'; import {Posts} from 'mattermost-redux/constants';
@@ -77,7 +78,7 @@ export default class PostInfo extends React.PureComponent {
*/ */
addReaction: PropTypes.func.isRequired addReaction: PropTypes.func.isRequired
}).isRequired }).isRequired
} };
constructor(props) { constructor(props) {
super(props); super(props);
@@ -96,12 +97,12 @@ export default class PostInfo extends React.PureComponent {
this.setState({showEmojiPicker}); this.setState({showEmojiPicker});
this.props.handleDropdownOpened(showEmojiPicker); this.props.handleDropdownOpened(showEmojiPicker);
} };
hideEmojiPicker = () => { hideEmojiPicker = () => {
this.setState({showEmojiPicker: false}); this.setState({showEmojiPicker: false});
this.props.handleDropdownOpened(false); this.props.handleDropdownOpened(false);
} };
removePost() { removePost() {
this.props.actions.removePost(this.props.post); this.props.actions.removePost(this.props.post);
@@ -131,7 +132,7 @@ export default class PostInfo extends React.PureComponent {
getDotMenu = () => { getDotMenu = () => {
return this.refs.dotMenu; return this.refs.dotMenu;
} };
render() { render() {
const post = this.props.post; const post = this.props.post;
@@ -242,10 +243,16 @@ export default class PostInfo extends React.PureComponent {
); );
} }
// timestamp should not be a permalink if the post has been deleted, is ephemeral message, or is pending
const isPermalink = !(isEphemeral ||
Posts.POST_DELETED === this.props.post.state ||
ReduxPostUtils.isPostPendingOrFailed(this.props.post));
return ( return (
<div className='post__header--info'> <div className='post__header--info'>
<div className='col'> <div className='col'>
<PostTime <PostTime
isPermalink={isPermalink}
eventTime={post.create_at} eventTime={post.create_at}
useMilitaryTime={this.props.useMilitaryTime} useMilitaryTime={this.props.useMilitaryTime}
postId={post.id} postId={post.id}

Просмотреть файл

@@ -12,6 +12,11 @@ import TeamStore from 'stores/team_store.jsx';
export default class PostTime extends React.PureComponent { export default class PostTime extends React.PureComponent {
static propTypes = { static propTypes = {
/*
* If true, time will be rendered as a permalink to the post
*/
isPermalink: PropTypes.bool.isRequired,
/* /*
* The time to display * The time to display
*/ */
@@ -26,12 +31,12 @@ export default class PostTime extends React.PureComponent {
* The post id of posting being rendered * The post id of posting being rendered
*/ */
postId: PropTypes.string postId: PropTypes.string
} };
static defaultProps = { static defaultProps = {
eventTime: 0, eventTime: 0,
useMilitaryTime: false useMilitaryTime: false
} };
constructor(props) { constructor(props) {
super(props); super(props);
@@ -74,7 +79,7 @@ export default class PostTime extends React.PureComponent {
} }
render() { render() {
if (isMobile()) { if (isMobile() || !this.props.isPermalink) {
return this.renderTimeTag(); return this.renderTimeTag();
} }

Просмотреть файл

@@ -9,6 +9,7 @@ exports[`components/post_view/PostInfo should match snapshot 1`] = `
> >
<PostTime <PostTime
eventTime={1502715365009} eventTime={1502715365009}
isPermalink={true}
postId="e584uzbwwpny9kengqayx5ayzw" postId="e584uzbwwpny9kengqayx5ayzw"
useMilitaryTime={false} useMilitaryTime={false}
/> />
@@ -98,6 +99,7 @@ exports[`components/post_view/PostInfo should match snapshot, compact display 1`
> >
<PostTime <PostTime
eventTime={1502715365009} eventTime={1502715365009}
isPermalink={true}
postId="e584uzbwwpny9kengqayx5ayzw" postId="e584uzbwwpny9kengqayx5ayzw"
useMilitaryTime={false} useMilitaryTime={false}
/> />
@@ -187,6 +189,7 @@ exports[`components/post_view/PostInfo should match snapshot, ephemeral deleted
> >
<PostTime <PostTime
eventTime={1502715365009} eventTime={1502715365009}
isPermalink={false}
postId="e584uzbwwpny9kengqayx5ayzw" postId="e584uzbwwpny9kengqayx5ayzw"
useMilitaryTime={false} useMilitaryTime={false}
/> />
@@ -222,6 +225,7 @@ exports[`components/post_view/PostInfo should match snapshot, ephemeral post 1`]
> >
<PostTime <PostTime
eventTime={1502715365009} eventTime={1502715365009}
isPermalink={false}
postId="e584uzbwwpny9kengqayx5ayzw" postId="e584uzbwwpny9kengqayx5ayzw"
useMilitaryTime={false} useMilitaryTime={false}
/> />
@@ -266,6 +270,7 @@ exports[`components/post_view/PostInfo should match snapshot, flagged post 1`] =
> >
<PostTime <PostTime
eventTime={1502715365009} eventTime={1502715365009}
isPermalink={true}
postId="e584uzbwwpny9kengqayx5ayzw" postId="e584uzbwwpny9kengqayx5ayzw"
useMilitaryTime={false} useMilitaryTime={false}
/> />
@@ -355,6 +360,7 @@ exports[`components/post_view/PostInfo should match snapshot, military time 1`]
> >
<PostTime <PostTime
eventTime={1502715365009} eventTime={1502715365009}
isPermalink={true}
postId="e584uzbwwpny9kengqayx5ayzw" postId="e584uzbwwpny9kengqayx5ayzw"
useMilitaryTime={true} useMilitaryTime={true}
/> />
@@ -418,6 +424,7 @@ exports[`components/post_view/PostInfo should match snapshot, pinned post 1`] =
> >
<PostTime <PostTime
eventTime={1502715365009} eventTime={1502715365009}
isPermalink={true}
postId="e584uzbwwpny9kengqayx5ayzw" postId="e584uzbwwpny9kengqayx5ayzw"
useMilitaryTime={false} useMilitaryTime={false}
/> />

Просмотреть файл

@@ -9,7 +9,7 @@ import UserStore from 'stores/user_store.jsx';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
export function isSystemMessage(post) { export function isSystemMessage(post) {
return post.type && (post.type.lastIndexOf(Constants.SYSTEM_MESSAGE_PREFIX) === 0); return Boolean(post.type && (post.type.lastIndexOf(Constants.SYSTEM_MESSAGE_PREFIX) === 0));
} }
export function isFromWebhook(post) { export function isFromWebhook(post) {
@@ -53,11 +53,11 @@ export function getProfilePicSrcForPost(post, user) {
} }
export function canDeletePost(post) { export function canDeletePost(post) {
var isOwner = isPostOwner(post); const isOwner = isPostOwner(post);
var isSystemAdmin = UserStore.isSystemAdminForCurrentUser(); const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
var isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam() || isSystemAdmin; const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam() || isSystemAdmin;
var isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel() || isTeamAdmin; const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel() || isTeamAdmin;
var isAdmin = isChannelAdmin || isTeamAdmin || isSystemAdmin; const isAdmin = isChannelAdmin || isTeamAdmin || isSystemAdmin;
if (global.window.mm_license.IsLicensed === 'true') { if (global.window.mm_license.IsLicensed === 'true') {
return (global.window.mm_config.RestrictPostDelete === Constants.PERMISSIONS_DELETE_POST_ALL && (isOwner || isChannelAdmin)) || return (global.window.mm_config.RestrictPostDelete === Constants.PERMISSIONS_DELETE_POST_ALL && (isOwner || isChannelAdmin)) ||
@@ -69,15 +69,14 @@ export function canDeletePost(post) {
} }
export function canEditPost(post, editDisableAction) { export function canEditPost(post, editDisableAction) {
var isOwner = isPostOwner(post); const isOwner = isPostOwner(post);
let canEdit = isOwner && !isSystemMessage(post);
var canEdit = isOwner && !isSystemMessage(post);
if (canEdit && global.window.mm_license.IsLicensed === 'true') { if (canEdit && global.window.mm_license.IsLicensed === 'true') {
if (global.window.mm_config.AllowEditPost === Constants.ALLOW_EDIT_POST_NEVER) { if (global.window.mm_config.AllowEditPost === Constants.ALLOW_EDIT_POST_NEVER) {
canEdit = false; canEdit = false;
} else if (global.window.mm_config.AllowEditPost === Constants.ALLOW_EDIT_POST_TIME_LIMIT) { } else if (global.window.mm_config.AllowEditPost === Constants.ALLOW_EDIT_POST_TIME_LIMIT) {
var timeLeft = (post.create_at + (global.window.mm_config.PostEditTimeLimit * 1000)) - Utils.getTimestamp(); const timeLeft = (post.create_at + (global.window.mm_config.PostEditTimeLimit * 1000)) - Utils.getTimestamp();
if (timeLeft > 0) { if (timeLeft > 0) {
editDisableAction.fireAfter(timeLeft + 1000); editDisableAction.fireAfter(timeLeft + 1000);
} else { } else {