Skip to content

Commit

Permalink
Consistent sorting for messages in reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Sep 28, 2021
1 parent cb2d2c2 commit 029cb74
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ts/state/ducks/conversations.ts
Expand Up @@ -2329,17 +2329,22 @@ export function reducer(
: 0;

const lookup = fromPairs(messages.map(message => [message.id, message]));
const sorted = orderBy(
values(lookup),
['received_at', 'sent_at'],
['ASC', 'ASC']
);

let { newest, oldest } = metrics;

// If our metrics are a little out of date, we'll fix them up
if (messages.length > 0) {
const first = messages[0];
if (sorted.length > 0) {
const first = sorted[0];
if (first && (!oldest || first.received_at <= oldest.received_at)) {
oldest = pick(first, ['id', 'received_at', 'sent_at']);
}

const last = messages[messages.length - 1];
const last = sorted[sorted.length - 1];
if (
last &&
(!newest || unboundedFetch || last.received_at >= newest.received_at)
Expand All @@ -2348,11 +2353,6 @@ export function reducer(
}
}

const sorted = orderBy(
values(lookup),
['received_at', 'sent_at'],
['ASC', 'ASC']
);
const messageIds = sorted.map(message => message.id);

return {
Expand Down

0 comments on commit 029cb74

Please sign in to comment.