From 784d02bf6058afdb94b93c285149f1b1d4a18aa3 Mon Sep 17 00:00:00 2001 From: Yashashvi Dave Date: Tue, 21 May 2019 13:03:21 +0530 Subject: [PATCH] static/js/stream_data: Rename `in_home_view` functions. --- frontend_tests/node_tests/stream_data.js | 16 ++++++++-------- frontend_tests/node_tests/topic_generator.js | 4 ++-- frontend_tests/node_tests/unread.js | 4 ++-- static/js/filter.js | 3 ++- static/js/notifications.js | 4 ++-- static/js/stream_data.js | 20 ++++++++++++++------ static/js/stream_list.js | 2 +- static/js/tab_bar.js | 2 +- static/js/topic_generator.js | 2 +- static/js/unread.js | 2 +- 10 files changed, 34 insertions(+), 25 deletions(-) diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index 05830bb54d..4c1148074a 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -79,8 +79,8 @@ run_test('basics', () => { assert.equal(stream_data.get_name('denMARK'), 'Denmark'); assert.equal(stream_data.get_name('unknown Stream'), 'unknown Stream'); - assert(stream_data.in_home_view(social.stream_id)); - assert(!stream_data.in_home_view(denmark.stream_id)); + assert(!stream_data.is_muted(social.stream_id)); + assert(stream_data.is_muted(denmark.stream_id)); assert.equal(stream_data.maybe_get_stream_name(), undefined); assert.equal(stream_data.maybe_get_stream_name(social.stream_id), 'social'); @@ -600,17 +600,17 @@ run_test('is_muted', () => { stream_data.add_sub('tony', tony); stream_data.add_sub('jazy', jazy); - assert(stream_data.name_in_home_view('tony')); - assert(!stream_data.name_in_home_view('jazy')); - assert(!stream_data.name_in_home_view('EEXISTS')); + assert(!stream_data.is_stream_muted_by_name('tony')); + assert(stream_data.is_stream_muted_by_name('jazy')); + assert(stream_data.is_stream_muted_by_name('EEXISTS')); }); -run_test('notifications_in_home_view', () => { +run_test('is_notifications_stream_muted', () => { page_params.notifications_stream = 'tony'; - assert(stream_data.notifications_in_home_view()); + assert(!stream_data.is_notifications_stream_muted()); page_params.notifications_stream = 'jazy'; - assert(!stream_data.notifications_in_home_view()); + assert(stream_data.is_notifications_stream_muted()); }); run_test('remove_default_stream', () => { diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.js index 4b8c01602f..9ce9a26e26 100644 --- a/frontend_tests/node_tests/topic_generator.js +++ b/frontend_tests/node_tests/topic_generator.js @@ -282,8 +282,8 @@ run_test('topics', () => { return stream_id_dct[stream_name]; }; - global.stream_data.name_in_home_view = function (stream_name) { - return stream_name !== 'muted'; + global.stream_data.is_stream_muted_by_name = function (stream_name) { + return stream_name === 'muted'; }; global.unread.topic_has_any_unread = function (stream_id) { diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.js index 4d3c29c46f..1f0495c4d3 100644 --- a/frontend_tests/node_tests/unread.js +++ b/frontend_tests/node_tests/unread.js @@ -303,8 +303,8 @@ run_test('home_messages', () => { stream_data.is_subscribed = function () { return true; }; - stream_data.in_home_view = function () { - return true; + stream_data.is_muted = function () { + return false; }; var stream_id = 401; diff --git a/static/js/filter.js b/static/js/filter.js index 5a746c21e7..c9b7d2a4e2 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -41,7 +41,8 @@ function message_in_home(message) { return true; } - return stream_data.in_home_view(message.stream_id); + // We don't display muted streams in 'All messages' view + return !stream_data.is_muted(message.stream_id); } function message_matches_search_term(message, operator, operand) { diff --git a/static/js/notifications.js b/static/js/notifications.js index 6df04e19af..66182ce56e 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -443,7 +443,7 @@ exports.message_is_notifiable = function (message) { // Messages to muted streams that don't mention us specifically // are not notifiable. if (message.type === "stream" && - !stream_data.in_home_view(message.stream_id)) { + stream_data.is_muted(message.stream_id)) { return false; } @@ -576,7 +576,7 @@ exports.get_local_notify_mix_reason = function (message) { return i18n.t("Sent! Your message was sent to a topic you have muted."); } - if (message.type === "stream" && !stream_data.in_home_view(message.stream_id)) { + if (message.type === "stream" && stream_data.is_muted(message.stream_id)) { return i18n.t("Sent! Your message was sent to a stream you have muted."); } diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 4b75d0fb7f..f84ffb2d52 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -355,19 +355,27 @@ exports.get_color = function (stream_name) { return sub.color; }; -exports.in_home_view = function (stream_id) { +exports.is_muted = function (stream_id) { var sub = exports.get_sub_by_id(stream_id); - return sub !== undefined && !sub.is_muted; + // Return true for undefined streams + if (sub === undefined) { + return true; + } + return sub.is_muted; }; -exports.name_in_home_view = function (stream_name) { +exports.is_stream_muted_by_name = function (stream_name) { var sub = exports.get_sub(stream_name); - return sub !== undefined && !sub.is_muted; + // Return true for undefined streams + if (sub === undefined) { + return true; + } + return sub.is_muted; }; -exports.notifications_in_home_view = function () { +exports.is_notifications_stream_muted = function () { // TODO: add page_params.notifications_stream_id - return exports.name_in_home_view(page_params.notifications_stream); + return exports.is_stream_muted_by_name(page_params.notifications_stream); }; exports.is_subscribed = function (stream_name) { diff --git a/static/js/stream_list.js b/static/js/stream_list.js index d71a989d57..994660efa1 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -215,7 +215,7 @@ function build_stream_sidebar_li(sub) { name: name, id: sub.stream_id, uri: hash_util.by_stream_uri(sub.stream_id), - is_muted: stream_data.in_home_view(sub.stream_id) === false, + is_muted: stream_data.is_muted(sub.stream_id) === true, invite_only: sub.invite_only, is_web_public: sub.is_web_public, color: stream_data.get_color(name), diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js index 42ad3df020..8b9b7b9361 100644 --- a/static/js/tab_bar.js +++ b/static/js/tab_bar.js @@ -25,7 +25,7 @@ function make_tab_data() { return true; } - return !stream_data.in_home_view(stream_id); + return stream_data.is_muted(stream_id); } function in_all() { diff --git a/static/js/topic_generator.js b/static/js/topic_generator.js index 8f5891990e..f7760c053c 100644 --- a/static/js/topic_generator.js +++ b/static/js/topic_generator.js @@ -198,7 +198,7 @@ exports.get_next_topic = function (curr_stream, curr_topic) { var my_streams = stream_sort.get_streams(); my_streams = _.filter(my_streams, function (stream_name) { - if (stream_data.name_in_home_view(stream_name)) { + if (!stream_data.is_stream_muted_by_name(stream_name)) { return true; } if (stream_name === curr_stream) { diff --git a/static/js/unread.js b/static/js/unread.js index 30d9bdb4fb..30691666c4 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -305,7 +305,7 @@ exports.unread_topic_counter = (function () { } }); res.stream_count.set(stream_id, stream_count); - if (stream_data.in_home_view(stream_id)) { + if (!stream_data.is_muted(stream_id)) { res.stream_unread_messages += stream_count; }