Skip to content

Commit

Permalink
narrowsReducer [nfc]: Add a few comments.
Browse files Browse the repository at this point in the history
These comments have been true for a while; I just noticed that they
were missing while working on the adjacent code.
  • Loading branch information
chrisbobbe committed Dec 10, 2020
1 parent 11e67af commit 4342d55
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/chat/narrowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ const eventNewMessage = (state, action) => {
return; // i.e., continue
}

// Don't add a message to the end of the list unless we know
// it's the most recent message, i.e., unless we know we're
// currently looking at (caught up with) the newest messages in
// the narrow.
const isCaughtUp = action.caughtUp[key] && action.caughtUp[key].newer;
// Don't add a message that's already been added. It's probably
// very rare for a message to have already been added when we
// get an EVENT_NEW_MESSAGE, and perhaps impossible. (TODO:
// investigate?)
const messageDoesNotExist = value.find(id => action.message.id === id) === undefined;
if (isCaughtUp && messageDoesNotExist) {
stateMutable.set(key, [...value, message.id]);
Expand Down

0 comments on commit 4342d55

Please sign in to comment.