Ensure final message before 'empty' is ready for notification (#1522)

Without this change, there's a race condition for the notification we
show when we get the 'empty' event after a large backlog download. Four
messages may have come in, but the last might not be notified. So the
count shown would be three. And then, when the final message's notify()
call finishes, another notification would be shown.

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-09-29 09:58:37 -07:00 committed by GitHub
parent 10a38297b8
commit 38152042d5

View file

@ -493,12 +493,16 @@
// because we need to start expiration timers, etc.
message.markRead();
}
if (message.get('unread')) {
conversation.notify(message);
}
confirm();
return resolve();
if (message.get('unread')) {
conversation.notify(message).then(function() {
confirm();
return resolve();
}, handleError);
} else {
confirm();
return resolve();
}
}
catch (e) {
handleError(e);