[important] Fix stacktrace in unread.js.

There is a scenario where we call process_read_message()
for a message that we haven't recorded as unread before.
I'm not sure how it happens, but I put back code to
guard against crashing.  The regression happened in
5752458c821.

(imported from commit 5ce15d2e236b738b445ed88f1733aa0612be0ff3)
This commit is contained in:
Steve Howell 2013-09-28 17:09:29 -04:00
parent bbfc8c886a
commit 8f1498c766
2 changed files with 20 additions and 1 deletions

View File

@ -72,7 +72,13 @@ exports.process_read_message = function (message) {
if (message.type === 'stream') {
var canon_stream = stream_data.canonicalized_name(message.stream);
var canon_subject = stream_data.canonicalized_name(message.subject);
unread_subjects.get(canon_stream).get(canon_subject).del(message.id);
var stream_dict = unread_subjects.get(canon_stream);
if (stream_dict) {
var subject_dict = stream_dict.get(canon_subject);
if (subject_dict) {
subject_dict.del(message.id);
}
}
}
unread_mentioned.del(message.id);
};

View File

@ -215,6 +215,19 @@ var zero_counts = {
}());
(function test_phantom_messages() {
var message = {
id: 999,
type: 'stream',
stream: 'foo',
subject: 'phantom'
};
unread.process_read_message(message);
var counts = unread.get_counts();
assert.equal(counts.home_unread_messages, 0);
}());
(function test_private_messages() {
narrow.active = function () {
return false;