Skip to content

Commit

Permalink
[MM-17065] dot menu unread from post (mattermost#3427)
Browse files Browse the repository at this point in the history
* [MM-17065] unread since given post from dots menu

* [MM-17065] add i18n

* [MM-17754] remove unneeded dispatch

* [MM-17754] only allow unreading from center

* [MM-17065] clarify function name

* [MM-17065] add redux dep
  • Loading branch information
Willyfrog authored and hmhealey committed Aug 27, 2019
1 parent 62213e8 commit 75f827d
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 1 deletion.
8 changes: 8 additions & 0 deletions actions/post_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ export function setEditingPost(postId = '', commentCount = 0, refocusId = '', ti
};
}

export function markPostAsUnread(post) {
return async (dispatch, getState) => {
const state = getState();
const userId = getCurrentUserId(state);
await dispatch(PostActions.setUnreadPost(userId, post.id));
};
}

export function hideEditPostModal() {
return {
type: ActionTypes.HIDE_EDIT_POST_MODAL,
Expand Down
12 changes: 12 additions & 0 deletions components/dot_menu/__snapshots__/dot_menu.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ exports[`components/dot_menu/DotMenu should match snapshot, canDelete 1`] = `
show={true}
text="Pin"
/>
<MenuItemAction
id="unread_post_post_id_1"
onClick={[Function]}
show={true}
text="Mark as Unread"
/>
<MenuItemAction
id="delete_post_post_id_1"
onClick={[Function]}
Expand Down Expand Up @@ -204,6 +210,12 @@ exports[`components/dot_menu/DotMenu should match snapshot, on Center 1`] = `
show={true}
text="Pin"
/>
<MenuItemAction
id="unread_post_post_id_1"
onClick={[Function]}
show={true}
text="Mark as Unread"
/>
<MenuItemAction
id="delete_post_post_id_1"
onClick={[Function]}
Expand Down
16 changes: 16 additions & 0 deletions components/dot_menu/dot_menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export default class DotMenu extends Component {
* Function to open a modal
*/
openModal: PropTypes.func.isRequired,

/*
* Function to set the unread mark at given post
*/
markPostAsUnread: PropTypes.func.isRequired,
}).isRequired,
}

Expand Down Expand Up @@ -160,6 +165,11 @@ export default class DotMenu extends Component {
}
}

handleUnreadMenuItemActivated = (e) => {
e.preventDefault();
this.props.actions.markPostAsUnread(this.props.post);
}

handleDeleteMenuItemActivated = (e) => {
e.preventDefault();

Expand Down Expand Up @@ -303,6 +313,12 @@ export default class DotMenu extends Component {
text={Utils.localizeMessage('post_info.pin', 'Pin')}
onClick={this.handlePinMenuItemActivated}
/>
<MenuItemAction
id={`unread_post_${this.props.post.id}`}
show={!isSystemMessage && this.props.location === Locations.CENTER}
text={Utils.localizeMessage('post_info.unread', 'Mark as Unread')}
onClick={this.handleUnreadMenuItemActivated}
/>
<MenuItemAction
id={`delete_post_${this.props.post.id}`}
show={this.state.canDelete}
Expand Down
1 change: 1 addition & 0 deletions components/dot_menu/dot_menu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('components/dot_menu/DotMenu', () => {
pinPost: jest.fn(),
unpinPost: jest.fn(),
openModal: jest.fn(),
markPostAsUnread: jest.fn(),
},
};

Expand Down
1 change: 1 addition & 0 deletions components/dot_menu/dot_menu_empty.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('components/dot_menu/DotMenu returning empty ("")', () => {
pinPost: jest.fn(),
unpinPost: jest.fn(),
openModal: jest.fn(),
markPostAsUnread: jest.fn(),
},
};

Expand Down
1 change: 1 addition & 0 deletions components/dot_menu/dot_menu_mobile.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('components/dot_menu/DotMenu on mobile view', () => {
pinPost: jest.fn(),
unpinPost: jest.fn(),
openModal: jest.fn(),
markPostAsUnread: jest.fn(),
},
};

Expand Down
2 changes: 2 additions & 0 deletions components/dot_menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
pinPost,
unpinPost,
setEditingPost,
markPostAsUnread,
} from 'actions/post_actions.jsx';

import DotMenu from './dot_menu.jsx';
Expand All @@ -36,6 +37,7 @@ function mapDispatchToProps(dispatch) {
pinPost,
unpinPost,
openModal,
markPostAsUnread,
}, dispatch),
};
}
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2787,6 +2787,7 @@
"post_info.system": "System",
"post_info.tooltip.add_reactions": "Add Reaction",
"post_info.unpin": "Un-pin from channel",
"post_info.unread": "Mark as Unread",
"post_message_view.edited": "(edited)",
"post.ariaLabel.attachment": ", 1 attachment",
"post.ariaLabel.attachmentMultiple": ", {attachmentCount} attachments",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"localforage-observable": "2.0.0",
"mark.js": "8.11.1",
"marked": "github:mattermost/marked#3a9d0a5bd6d735df1a716ab50f73d58a1d865bdb",
"mattermost-redux": "github:mattermost/mattermost-redux#490adb0a14aeb8d6e917e2b016c1390f0457cbec",
"mattermost-redux": "github:mattermost/mattermost-redux#983aeb29b5870fc41d5441cd5d2b80055bbf8733",
"moment-timezone": "0.5.26",
"pdfjs-dist": "2.0.489",
"perfect-scrollbar": "0.8.1",
Expand Down
5 changes: 5 additions & 0 deletions reducers/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ function lastChannelViewTime(state = {}, action) {
return state;
}

case ActionTypes.POST_UNREAD_SUCCESS: {
const data = action.data;
return {...state, [data.channelId]: data.lastViewedAt};
}

default:
return state;
}
Expand Down
2 changes: 2 additions & 0 deletions utils/constants.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export const ActionTypes = keyMirror({
CHANNEL_POSTS_STATUS: null,
CHANNEL_SYNC_STATUS: null,
ALL_CHANNEL_SYNC_STATUS: null,

POST_UNREAD_SUCCESS: null,
});

export const PostRequestTypes = keyMirror({
Expand Down

0 comments on commit 75f827d

Please sign in to comment.