mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
unread: Use reverse_lookup in unread_topic_counter.
This commit is contained in:
@@ -466,14 +466,5 @@ stream_data.get_stream_id = function () {
|
|||||||
unread.process_read_message(message);
|
unread.process_read_message(message);
|
||||||
var counts = unread.get_counts();
|
var counts = unread.get_counts();
|
||||||
assert.equal(counts.private_message_count, 0);
|
assert.equal(counts.private_message_count, 0);
|
||||||
|
|
||||||
// Test undefined stream_id
|
|
||||||
message = { type: 'stream' };
|
|
||||||
|
|
||||||
global.blueslip.error = function (msg) {
|
|
||||||
assert.equal(msg, 'No stream_id found for message undefined');
|
|
||||||
};
|
|
||||||
|
|
||||||
unread.process_read_message(message);
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
@@ -77,30 +77,30 @@ exports.unread_topic_counter = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var unread_topics = num_dict(); // dict of stream -> topic -> msg id
|
var unread_topics = num_dict(); // dict of stream -> topic -> msg id
|
||||||
|
var reverse_lookup = num_dict();
|
||||||
|
|
||||||
self.clear = function () {
|
self.clear = function () {
|
||||||
unread_topics = num_dict();
|
unread_topics = num_dict();
|
||||||
|
reverse_lookup = num_dict();
|
||||||
};
|
};
|
||||||
|
|
||||||
self.update = function (stream_id, topic, new_topic, msg_id) {
|
self.update = function (msg_id, stream_id, new_topic) {
|
||||||
self.del(stream_id, topic, msg_id);
|
self.del(msg_id);
|
||||||
self.add(stream_id, new_topic, msg_id);
|
self.add(stream_id, new_topic, msg_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.add = function (stream_id, topic, msg_id) {
|
self.add = function (stream_id, topic, msg_id) {
|
||||||
unread_topics.setdefault(stream_id, str_dict());
|
unread_topics.setdefault(stream_id, str_dict());
|
||||||
unread_topics.get(stream_id).setdefault(topic, num_dict());
|
var dict = unread_topics.get(stream_id).setdefault(topic, num_dict());
|
||||||
unread_topics.get(stream_id).get(topic).set(msg_id, true);
|
dict.set(msg_id, true);
|
||||||
|
reverse_lookup.set(msg_id, dict);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
self.del = function (msg_id) {
|
||||||
self.del = function (stream_id, topic, msg_id) {
|
var dict = reverse_lookup.get(msg_id);
|
||||||
var stream_dict = unread_topics.get(stream_id);
|
if (dict) {
|
||||||
if (stream_dict) {
|
dict.del(msg_id);
|
||||||
var topic_dict = stream_dict.get(topic);
|
reverse_lookup.del(msg_id);
|
||||||
if (topic_dict) {
|
|
||||||
topic_dict.del(msg_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -219,10 +219,9 @@ exports.message_unread = function (message) {
|
|||||||
exports.update_unread_topics = function (msg, event) {
|
exports.update_unread_topics = function (msg, event) {
|
||||||
if (event.subject !== undefined) {
|
if (event.subject !== undefined) {
|
||||||
exports.unread_topic_counter.update(
|
exports.unread_topic_counter.update(
|
||||||
|
msg.id,
|
||||||
msg.stream_id,
|
msg.stream_id,
|
||||||
msg.subject,
|
event.subject
|
||||||
event.subject,
|
|
||||||
msg.id
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -259,15 +258,7 @@ exports.process_read_message = function (message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'stream') {
|
if (message.type === 'stream') {
|
||||||
if (message.stream_id === undefined) {
|
exports.unread_topic_counter.del(message.id);
|
||||||
blueslip.error('No stream_id found for message ' + message.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
exports.unread_topic_counter.del(
|
|
||||||
message.stream_id,
|
|
||||||
message.subject,
|
|
||||||
message.id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.unread_mentions_counter.del(message.id);
|
exports.unread_mentions_counter.del(message.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user