Skip to content

Commit

Permalink
unread: Cut obsolete countUnread.
Browse files Browse the repository at this point in the history
In the parent commit, we removed the one call site this had.
It's just as obsolete as that call site was.  Cut it out.
  • Loading branch information
gnprice committed Jul 17, 2019
1 parent b4a8977 commit dd31d12
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 86 deletions.
61 changes: 1 addition & 60 deletions src/utils/__tests__/unread-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { countUnread, filterUnreadMessageIds, filterUnreadMessagesInRange } from '../unread';
import { filterUnreadMessageIds, filterUnreadMessagesInRange } from '../unread';

describe('filterUnreadMessageIds', () => {
test('empty message list has no unread messages', () => {
Expand Down Expand Up @@ -101,62 +101,3 @@ describe('filterUnreadMessagesInRange', () => {
expect(actualUnread).toEqual(expectedUnread);
});
});

describe('countUnread', () => {
test('for an empty message list the unread count is zero', () => {
const messages = [];
const flags = {};

const actualCount = countUnread(messages, flags);

expect(actualCount).toEqual(0);
});

test('when no read flags are set, every message is unread', () => {
const messages = [1, 2, 3];
const flags = {};

const actualCount = countUnread(messages, flags);

expect(actualCount).toEqual(3);
});

test('every message present in read flags is not counted', () => {
const messages = [1, 2, 3];
const flags = {
1: true,
2: true,
};

const actualCount = countUnread(messages, flags);

expect(actualCount).toEqual(1);
});

test('counts all unread from specified message id to the end', () => {
const messages = [1, 2, 3, 4, 5];
const flags = {};

const actualCount = countUnread(messages, flags, 3);

expect(actualCount).toEqual(3);
});

test('counts all unread from beginning to given message id', () => {
const messages = [1, 2, 3, 4, 5];
const flags = {};

const actualCount = countUnread(messages, flags, -1, 4);

expect(actualCount).toEqual(4);
});

test('counts all unread from given message id to another id', () => {
const messages = [1, 2, 3, 4, 5, 6, 7, 8];
const flags = {};

const actualCount = countUnread(messages, flags, 3, 6);

expect(actualCount).toEqual(4);
});
});
26 changes: 0 additions & 26 deletions src/utils/unread.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,5 @@ export const filterUnreadMessagesInRange = (
return filterUnreadMessageIds(messagesInRange.map(x => x.id), flags);
};

export const countUnread = (
messageIds: number[],
readFlags: { [messageId: number]: boolean },
fromId: number = -1,
toId: number = -1,
): number => {
let count = 0;
// count starts from the beginning if fromId === -1
// and continues to the end if toId === -1
let started = fromId === -1;

for (let i = 0; i < messageIds.length; i++) {
if (messageIds[i] === fromId) {
started = true;
}
if (started && !readFlags[messageIds[i]]) {
count++;
}
if (messageIds[i] === toId) {
break;
}
}

return count;
};

export const unreadToLimitedCount = (count: number): string =>
count < 100 ? count.toString() : '99+';

0 comments on commit dd31d12

Please sign in to comment.