Skip to content

Commit

Permalink
[MM-24376] Show channel (and team) as unread if system message is add…
Browse files Browse the repository at this point in the history
…ing current user to channel (mattermost#5427)

* show as unread if system message is adding current user
* fix failing tests
* temp redux commit hash
* move add-to-channel logic to shouldIgnorePost()
* temp redux commit hash
* fix linting
* update redux commit hash
  • Loading branch information
bradjcoughlin committed May 20, 2020
1 parent 957c9a9 commit 7431aae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
12 changes: 9 additions & 3 deletions actions/post_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,27 @@ export function lastPostActions(post, websocketMessageProps) {

// Still needed to update unreads

dispatch(setChannelReadAndView(post, websocketMessageProps));
dispatch(setChannelReadAndViewed(post, websocketMessageProps));

dispatch(sendDesktopNotification(post, websocketMessageProps));
};
}

export function setChannelReadAndView(post, websocketMessageProps) {
export function setChannelReadAndViewed(post, websocketMessageProps) {
return (dispatch, getState) => {
const state = getState();
if (shouldIgnorePost(post)) {
const currentUserId = getCurrentUserId(state);

// ignore system message posts, except when added to a team
if (shouldIgnorePost(post, currentUserId)) {
return;
}

let markAsRead = false;
let markAsReadOnServer = false;

// Skip marking a channel as read (when the user is viewing a channel)
// if they have manually marked it as unread.
if (!isManuallyUnread(getState(), post.channel_id)) {
if (
post.user_id === getCurrentUserId(state) &&
Expand Down
18 changes: 9 additions & 9 deletions actions/post_utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('actions/post_utils', () => {

test('completePostReceive', async () => {
const testStore = await mockStore(initialState);
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL, user_id: 'some_user_id', create_at: POST_CREATED_TIME};
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL, user_id: 'some_user_id', create_at: POST_CREATED_TIME, props: {addedUserId: 'other_user_id'}};
const websocketProps = {team_id: 'team_id', mentions: ['current_user_id']};

await testStore.dispatch(PostActionsUtils.completePostReceive(newPost, websocketProps));
Expand All @@ -96,7 +96,7 @@ describe('actions/post_utils', () => {

test('lastPostActions', async () => {
const testStore = await mockStore(initialState);
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL, user_id: 'some_user_id', create_at: POST_CREATED_TIME};
const newPost = {id: 'new_post_id', channel_id: 'current_channel_id', message: 'new message', type: Constants.PostTypes.ADD_TO_CHANNEL, user_id: 'some_user_id', create_at: POST_CREATED_TIME, props: {addedUserId: 'other_user_id'}};
const websocketProps = {team_id: 'team_id', mentions: ['current_user_id']};

await testStore.dispatch(PostActionsUtils.lastPostActions(newPost, websocketProps));
Expand All @@ -110,7 +110,7 @@ describe('actions/post_utils', () => {
]);
});

describe('setChannelReadAndView', () => {
describe('setChannelReadAndViewed', () => {
test('should mark channel as read when viewing channel', async () => {
const channelId = 'channel';
const currentUserId = 'user';
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('actions/post_utils', () => {

window.isActive = true;

await testStore.dispatch(PostActionsUtils.setChannelReadAndView(post2, {}));
await testStore.dispatch(PostActionsUtils.setChannelReadAndViewed(post2, {}));

expect(testStore.getActions()).toEqual([{
type: 'MOCK_MARK_CHANNEL_AS_READ',
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('actions/post_utils', () => {

window.isActive = false;

await testStore.dispatch(PostActionsUtils.setChannelReadAndView(post2, {}));
await testStore.dispatch(PostActionsUtils.setChannelReadAndViewed(post2, {}));

expect(testStore.getActions()).toEqual([{
type: 'MOCK_MARK_CHANNEL_AS_UNREAD',
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('actions/post_utils', () => {

window.isActive = true;

await testStore.dispatch(PostActionsUtils.setChannelReadAndView(post2, {}));
await testStore.dispatch(PostActionsUtils.setChannelReadAndViewed(post2, {}));

expect(testStore.getActions()).toEqual([{
type: 'MOCK_MARK_CHANNEL_AS_UNREAD',
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('actions/post_utils', () => {
},
});

await testStore.dispatch(PostActionsUtils.setChannelReadAndView(post2, {}));
await testStore.dispatch(PostActionsUtils.setChannelReadAndViewed(post2, {}));

expect(testStore.getActions()).toEqual([{
type: 'MOCK_MARK_CHANNEL_AS_READ',
Expand Down Expand Up @@ -296,7 +296,7 @@ describe('actions/post_utils', () => {
},
});

await testStore.dispatch(PostActionsUtils.setChannelReadAndView(post2, {}));
await testStore.dispatch(PostActionsUtils.setChannelReadAndViewed(post2, {}));

expect(testStore.getActions()).toEqual([{
type: 'MOCK_MARK_CHANNEL_AS_UNREAD',
Expand Down Expand Up @@ -333,7 +333,7 @@ describe('actions/post_utils', () => {
},
});

await testStore.dispatch(PostActionsUtils.setChannelReadAndView(post2, {}));
await testStore.dispatch(PostActionsUtils.setChannelReadAndViewed(post2, {}));

expect(testStore.getActions()).toEqual([{
type: 'MOCK_MARK_CHANNEL_AS_UNREAD',
Expand Down

0 comments on commit 7431aae

Please sign in to comment.