Skip to content

Commit

Permalink
unreads: Fix latent bug with unread self-PMs.
Browse files Browse the repository at this point in the history
If the server sends us a message that isn't marked as read, we should
always add it to unreads. However, we previously didn't do this in the
case of a self-PM.

This commit fixes this, even though we don't expect this to ever happen.
  • Loading branch information
WesleyAC committed May 21, 2021
1 parent 062d64c commit faaaac2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/unread/__tests__/unreadPmsReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,31 @@ describe('unreadPmsReducer', () => {
expect(actualState).toBe(initialState);
});

test('if message is marked unread in self-PM, append to state', () => {
const initialState = deepFreeze([]);
const message1 = eg.pmMessage({
sender: eg.selfUser,
recipients: [eg.selfUser],
});

const action = deepFreeze({
...eg.eventNewMessageActionBase,
message: message1,
ownUserId: eg.selfUser.user_id,
});

const expectedState = [
{
sender_id: eg.selfUser.user_id,
unread_message_ids: [message1.id],
},
];

const actualState = unreadPmsReducer(initialState, action);

expect(actualState).toEqual(expectedState);
});

test('if message id does not exist, append to state', () => {
const message1 = eg.pmMessage({ id: 1, sender_id: 1 });
const message2 = eg.pmMessage({ id: 2, sender_id: 1 });
Expand Down
2 changes: 1 addition & 1 deletion src/unread/unreadPmsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const eventNewMessage = (state, action) => {
return state;
}

if (recipientsOfPrivateMessage(action.message).length !== 2) {
if (recipientsOfPrivateMessage(action.message).length > 2) {
return state;
}

Expand Down

0 comments on commit faaaac2

Please sign in to comment.