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)
This commit is contained in:
Steve Howell 2013-09-27 17:39:12 -04:00
parent 8d3f4366f8
commit c7b7f8d79a
2 changed files with 17 additions and 12 deletions

View File

@ -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') {

View File

@ -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() {