diff --git a/app/screens/post_options/index.js b/app/screens/post_options/index.js index fb5de23a8..177ccd746 100644 --- a/app/screens/post_options/index.js +++ b/app/screens/post_options/index.js @@ -22,6 +22,7 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeamId, getCurrentTeamUrl} from 'mattermost-redux/selectors/entities/teams'; import {canEditPost} from 'mattermost-redux/utils/post_utils'; +import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers'; import {MAX_ALLOWED_REACTIONS} from 'app/constants/emoji'; import {THREAD} from 'app/constants/screen'; @@ -43,6 +44,8 @@ export function makeMapStateToProps() { const currentChannelId = getCurrentChannelId(state); const reactions = getReactionsForPostSelector(state, post.id); const channelIsArchived = channel.delete_at !== 0; + const {serverVersion} = state.entities.general; + const canMarkAsUnread = isMinimumServerVersion(serverVersion, 5, 18); let canAddReaction = true; let canReply = true; @@ -115,9 +118,9 @@ export function makeMapStateToProps() { canDelete, canFlag, canPin, + canMarkAsUnread, currentTeamUrl: getCurrentTeamUrl(state), currentUserId, - isMyPost: currentUserId === post.user_id, theme: getTheme(state), isLandscape: isLandscape(state), }; diff --git a/app/screens/post_options/index.test.js b/app/screens/post_options/index.test.js index d07bd1131..13b312e39 100644 --- a/app/screens/post_options/index.test.js +++ b/app/screens/post_options/index.test.js @@ -35,6 +35,9 @@ describe('makeMapStateToProps', () => { post_id: {}, }, }, + general: { + serverVersion: '5.18', + }, }, }; @@ -65,4 +68,25 @@ describe('makeMapStateToProps', () => { const props = mapStateToProps(baseState, ownProps); expect(props.canFlag).toBe(true); }); + + test('canMarkAsUnread is true when isMinimumServerVersion is 5.18v', () => { + const mapStateToProps = makeMapStateToProps(); + const props = mapStateToProps(baseState, baseOwnProps); + expect(props.canMarkAsUnread).toBe(true); + }); + + test('canMarkAsUnread is false when isMinimumServerVersion is not 5.18v', () => { + const state = { + entities: { + ...baseState.entities, + general: { + serverVersion: '5.17', + }, + }, + }; + + const mapStateToProps = makeMapStateToProps(); + const props = mapStateToProps(state, baseOwnProps); + expect(props.canMarkAsUnread).toBe(false); + }); }); diff --git a/app/screens/post_options/post_options.js b/app/screens/post_options/post_options.js index 050b4fdba..37632a481 100644 --- a/app/screens/post_options/post_options.js +++ b/app/screens/post_options/post_options.js @@ -38,12 +38,12 @@ export default class PostOptions extends PureComponent { canFlag: PropTypes.bool, canPin: PropTypes.bool, canEdit: PropTypes.bool, + canMarkAsUnread: PropTypes.bool, //#backwards-compatibility:5.18v canEditUntil: PropTypes.number.isRequired, currentTeamUrl: PropTypes.string.isRequired, currentUserId: PropTypes.string.isRequired, deviceHeight: PropTypes.number.isRequired, isFlagged: PropTypes.bool, - isMyPost: PropTypes.bool, post: PropTypes.object.isRequired, theme: PropTypes.object.isRequired, isLandscape: PropTypes.bool.isRequired, @@ -231,7 +231,7 @@ export default class PostOptions extends PureComponent { const {post, isLandscape, theme} = this.props; const {formatMessage} = this.context.intl; - if (!isSystemMessage(post)) { + if (!isSystemMessage(post) && this.props.canMarkAsUnread) { return ( { canDelete: true, canPin: true, canEdit: true, + canMarkAsUnread: true, canEditUntil: -1, channelIsReadOnly: false, currentTeamUrl: 'http://localhost:8065/team-name', @@ -45,7 +46,6 @@ describe('PostOptions', () => { deviceHeight: 600, hasBeenDeleted: false, isFlagged: false, - isMyPost: true, isSystemMessage: false, managedConfig: {}, post, @@ -98,6 +98,12 @@ describe('PostOptions', () => { expect(wrapper.findWhere((node) => node.key() === 'reply')).toMatchObject({}); }); + test('should not show mark as unread option', () => { + const wrapper = getWrapper({canMarkAsUnread: false}); + + expect(wrapper.findWhere((node) => node.key() === 'markUnread')).toMatchObject({}); + }); + test('should remove post after delete', () => { const wrapper = getWrapper();