Fix regression with stream_has_topics().

Our logic for stream_has_topics never accounted for
us creating essentially "empty" stream buckets that
don't have topics, but we recently added some code
related to unread counts that violated the original
assumptions of the code.

Now we check deeper into the stream bucket to find
actual topics.

This bug manifested in the left sidebar where users
were seeing streams as recently active just because
some muted topics had unread counts, when in fact
the stream was inactive for practical purposes.
This commit is contained in:
Steve Howell
2018-05-21 19:29:39 +00:00
committed by Tim Abbott
parent 0816f2552b
commit d81419c79d
2 changed files with 31 additions and 1 deletions

View File

@@ -164,6 +164,26 @@ run_test('server_history', () => {
assert.deepEqual(history, ['toPic1', 'unread1', 'topic2', 'UNREAD2']);
}());
(function test_stream_has_topics() {
var stream_id = 88;
assert.equal(topic_data.stream_has_topics(stream_id), false);
topic_data.find_or_create(stream_id);
// This was a bug before--just creating a bucket does not
// mean we have actual topics.
assert.equal(topic_data.stream_has_topics(stream_id), false);
topic_data.add_message({
stream_id: stream_id,
message_id: 888,
topic_name: 'whatever',
});
assert.equal(topic_data.stream_has_topics(stream_id), true);
}());
run_test('server_history_end_to_end', () => {
topic_data.reset();

View File

@@ -5,7 +5,13 @@ var exports = {};
var stream_dict = new Dict(); // stream_id -> array of objects
exports.stream_has_topics = function (stream_id) {
return stream_dict.has(stream_id);
if (!stream_dict.has(stream_id)) {
return false;
}
var history = stream_dict.get(stream_id);
return history.has_topics();
};
exports.topic_history = function (stream_id) {
@@ -13,6 +19,10 @@ exports.topic_history = function (stream_id) {
var self = {};
self.has_topics = function () {
return !topics.is_empty();
};
self.add_or_update = function (opts) {
var name = opts.name;
var message_id = opts.message_id || 0;