From c7b7f8d79a5b3ebfaadc1eebc304e4903c91eef2 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 27 Sep 2013 17:39:12 -0400 Subject: [PATCH] Inlined unread_hashkey() function. The indirection was more confusing than helpful, especially since the function had side effects, despite its getter-like name. (imported from commit 85d9cf642b4177f62488136f0e0f7f6c9304942e) --- static/js/unread.js | 18 ++++++------------ zerver/tests/frontend/node/unread.js | 11 +++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) 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() {