Skip to content

Commit

Permalink
Fix regression with stream_has_topics().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Steve Howell authored and timabbott committed May 21, 2018
1 parent 0816f25 commit d81419c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
20 changes: 20 additions & 0 deletions frontend_tests/node_tests/topic_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 11 additions & 1 deletion static/js/topic_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ 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) {
var topics = new Dict({fold_case: true});

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;
Expand Down

0 comments on commit d81419c

Please sign in to comment.