muting: Use stream_id for internal data structures.

This fixes the most core data structures inside of
muting.js.  We still use stream names for incoming
data to set_muted_topics and outgoing data from
get_muted_topics.

This will make us more resilient to stream name changes.
Before, if you were logged on when a stream rename
occured, topics that were muted under that stream would
appear to be unmuted.  (You could fix it with a reload,
but it can be jarring to have a bunch of unread messages
appear in your feed suddenly.)

Fixes #11033
This commit is contained in:
Steve Howell
2018-12-13 21:26:10 +00:00
committed by Tim Abbott
parent 69da22d998
commit a8718c9051
15 changed files with 149 additions and 84 deletions

View File

@@ -22,6 +22,14 @@ var me = {
people.add(me);
people.initialize_current_user(me.user_id);
var social = {
stream_id: 200,
name: 'social',
subscribed: true,
in_home_view: true,
};
stream_data.add_sub('social', social);
var zero_counts = {
private_message_count: 0,
home_unread_messages: 0,
@@ -177,25 +185,11 @@ run_test('changing_subjects', () => {
});
run_test('muting', () => {
stream_data.is_subscribed = function () {
return true;
};
stream_data.in_home_view = function () {
return true;
};
unread.declare_bankruptcy();
var stream_id = 101;
var stream_id = social.stream_id;
var unknown_stream_id = 555;
stream_data.get_sub_by_id = function (stream_id) {
if (stream_id === 101) {
return {name: 'social'};
}
};
var message = {
id: 15,
type: 'stream',
@@ -211,7 +205,7 @@ run_test('muting', () => {
assert.equal(unread.num_unread_for_stream(stream_id), 1);
assert.deepEqual(unread.get_msg_ids_for_stream(stream_id), [message.id]);
muting.add_muted_topic('social', 'test_muting');
muting.add_muted_topic(social.stream_id, 'test_muting');
counts = unread.get_counts();
assert.equal(counts.stream_count.get(stream_id), 0);
assert.equal(counts.home_unread_messages, 0);