Skip to content

Commit

Permalink
Do not mark messages in outbox as read (#1814)
Browse files Browse the repository at this point in the history
  • Loading branch information
borisyankov authored Jan 27, 2018
1 parent cb254de commit 6a8bf51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/utils/__tests__/unread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ describe('filterUnreadMessagesInRange', () => {
expect(actualUnread).toEqual(expectedUnread);
});

test('messages in outbox are filtered out', () => {
const messages = [{ id: 1 }, { id: 2 }, { id: 34567, isOutbox: true }];
const flags = {};
const expectedUnread = [1, 2];

const actualUnread = filterUnreadMessagesInRange(messages, flags, 1, Number.MAX_SAFE_INTEGER);

expect(actualUnread).toEqual(expectedUnread);
});

test('messages are not read if not in flags object, regardless of message property', () => {
const messages = [{ id: 1 }];
const flags = {};
Expand Down
4 changes: 3 additions & 1 deletion src/utils/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const filterUnreadMessagesInRange = (
fromId: number,
toId: number,
): Message[] => {
const messagesInRange = messages.filter(msg => msg.id >= fromId && msg.id <= toId);
const messagesInRange = messages
.filter(msg => !msg.isOutbox)
.filter(msg => msg.id >= fromId && msg.id <= toId);
return filterUnreadMessageIds(messagesInRange.map(x => x.id), flags);
};

Expand Down

0 comments on commit 6a8bf51

Please sign in to comment.