Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-14403 Remove channel from unreads section properly when clicking o…
Browse files Browse the repository at this point in the history
…n permalink (#2495)

* Remove channel from unreads section properly when clicking on permalink

* Update unit tests
  • Loading branch information
jwilander authored and hanzei committed Mar 16, 2019
1 parent ca081c7 commit 56b6f13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/permalink_view/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function focusPost(postId, returnTo = '') {
dispatch({
type: ActionTypes.RECEIVED_FOCUSED_POST,
data: postId,
channelId,
});

dispatch(loadChannelsForCurrentUser());
Expand Down
5 changes: 3 additions & 2 deletions components/permalink_view/permalink_view.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ describe('components/PermalinkView', () => {
expect(testStore.getActions()).toEqual([
{type: 'MOCK_GET_POST_THREAD', data: {posts: {postid1: {id: 'postid1', message: 'some message', channel_id: 'channelid1'}}, order: ['postid1']}},
{type: 'MOCK_SELECT_CHANNEL', args: ['channelid1']},
{type: 'RECEIVED_FOCUSED_POST', data: 'postid1'},
{type: 'RECEIVED_FOCUSED_POST', data: 'postid1', channelId: 'channelid1'},
{type: 'MOCK_LOAD_CHANNELS_FOR_CURRENT_USER'},
{type: 'MOCK_GET_CHANNEL_STATS', args: ['channelid1']},
]);
});

test('should focus post in not loaded channel', async () => {
const testStore = await mockStore(initialState);

await testStore.dispatch(focusPost('postid2'));

expect(getPostThread).toHaveBeenCalledWith('postid2');
Expand All @@ -154,7 +155,7 @@ describe('components/PermalinkView', () => {
{type: 'MOCK_GET_CHANNEL', data: {id: 'channelid2', type: 'O', team_id: 'current_team_id'}},
{type: 'MOCK_JOIN_CHANNEL', args: ['current_user_id', null, 'channelid2']},
{type: 'MOCK_SELECT_CHANNEL', args: ['channelid2']},
{type: 'RECEIVED_FOCUSED_POST', data: 'postid2'},
{type: 'RECEIVED_FOCUSED_POST', data: 'postid2', channelId: 'channelid2'},
{type: 'MOCK_LOAD_CHANNELS_FOR_CURRENT_USER'},
{type: 'MOCK_GET_CHANNEL_STATS', args: ['channelid2']},
]);
Expand Down
7 changes: 7 additions & 0 deletions reducers/views/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ function keepChannelIdAsUnread(state = null, action) {
return null;
}

case ActionTypes.RECEIVED_FOCUSED_POST: {
if (state && action.channelId !== state.id) {
return null;
}
return state;
}

case UserTypes.LOGOUT_SUCCESS:
return null;
default:
Expand Down

0 comments on commit 56b6f13

Please sign in to comment.