diff --git a/static/js/unread.js b/static/js/unread.js index 562e3b6a4f..69c8d6583a 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -6,14 +6,6 @@ var unread_mentioned = new Dict(); var unread_subjects = new Dict({fold_case: true}); var unread_privates = new Dict(); -function unread_hashkey(message) { - var hashkey = message.reply_to; - - unread_privates.setdefault(hashkey, new Dict()); - - return hashkey; -} - exports.message_unread = function (message) { if (message === undefined) { return false; @@ -49,8 +41,8 @@ exports.process_loaded_messages = function (messages) { } if (message.type === 'private') { - var hashkey = unread_hashkey(message); - unread_privates.get(hashkey).set(message.id, true); + unread_privates.setdefault(message.reply_to, new Dict()); + unread_privates.get(message.reply_to).set(message.id, true); } if (message.type === 'stream') { @@ -71,8 +63,10 @@ exports.process_loaded_messages = function (messages) { exports.process_read_message = function (message) { if (message.type === 'private') { - var hashkey = unread_hashkey(message); - unread_privates.get(hashkey).del(message.id); + var dict = unread_privates.get(message.reply_to); + if (dict) { + dict.del(message.id); + } } if (message.type === 'stream') { diff --git a/zerver/tests/frontend/node/unread.js b/zerver/tests/frontend/node/unread.js index f1e0ab3128..cdbd34bbb8 100644 --- a/zerver/tests/frontend/node/unread.js +++ b/zerver/tests/frontend/node/unread.js @@ -207,6 +207,17 @@ var zero_counts = { unread.process_read_message(message); counts = unread.get_counts(); assert.equal(counts.private_message_count, 0); + + // Test unknown message is harmless + message = { + id: 9, + type: 'private', + reply_to: 'unknown@zulip.com' + }; + + unread.process_read_message(message); + counts = unread.get_counts(); + assert.equal(counts.private_message_count, 0); }()); (function test_num_unread_for_person() {