diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index c80dc43177..8f78a8b158 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -270,8 +270,9 @@ function make_sub(name, stream_id) { predicate = get_predicate([['in', 'all']]); assert(predicate({})); + var unknown_stream_id = 999; predicate = get_predicate([['in', 'home']]); - assert(!predicate({stream: 'unsub'})); + assert(!predicate({stream_id: unknown_stream_id, stream: 'unknown'})); assert(predicate({type: 'private'})); global.page_params.narrow_stream = 'kiosk'; assert(predicate({stream: 'kiosk'})); diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index fb54a30005..bf24b6eb49 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -70,8 +70,8 @@ var people = global.people; 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')); - assert(!stream_data.in_home_view('denmark')); + assert(stream_data.in_home_view(social.stream_id)); + assert(!stream_data.in_home_view(denmark.stream_id)); }()); (function test_renames() { diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.js index 49815612f2..f840f5a7c9 100644 --- a/frontend_tests/node_tests/unread.js +++ b/frontend_tests/node_tests/unread.js @@ -151,6 +151,10 @@ var zero_counts = { assert.equal(count, 0); }()); +stream_data.get_stream_id = function () { + return 999; +}; + (function test_muting() { stream_data.is_subscribed = function () { return true; diff --git a/static/js/filter.js b/static/js/filter.js index fe3b3cd618..f2694ac901 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -41,7 +41,7 @@ function message_in_home(message) { return true; } - return stream_data.in_home_view(message.stream); + return stream_data.in_home_view(message.stream_id); } function message_matches_search_term(message, operator, operand) { diff --git a/static/js/notifications.js b/static/js/notifications.js index f3ad3edd9f..ed7b5d3149 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -417,7 +417,7 @@ function message_is_notifiable(message) { return true; } if ((message.type === "stream") && - !stream_data.in_home_view(message.stream)) { + !stream_data.in_home_view(message.stream_id)) { return false; } if ((message.type === "stream") && @@ -548,7 +548,7 @@ exports.possibly_notify_new_messages_outside_viewport = function (messages, loca if (row.length === 0) { if (message.type === "stream" && muting.is_topic_muted(message.stream, message.subject)) { note = "Sent! Your message was sent to a topic you have muted."; - } else if (message.type === "stream" && !stream_data.in_home_view(message.stream)) { + } else if (message.type === "stream" && !stream_data.in_home_view(message.stream_id)) { note = "Sent! Your message was sent to a stream you have muted."; } else { // offscreen because it is outside narrow diff --git a/static/js/stream_data.js b/static/js/stream_data.js index c55f070c7b..2336198314 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -180,11 +180,21 @@ exports.get_color = function (stream_name) { return sub.color; }; -exports.in_home_view = function (stream_name) { +exports.in_home_view = function (stream_id) { + var sub = exports.get_sub_by_id(stream_id); + return sub !== undefined && sub.in_home_view; +}; + +exports.name_in_home_view = function (stream_name) { var sub = exports.get_sub(stream_name); return sub !== undefined && sub.in_home_view; }; +exports.notifications_in_home_view = function () { + // TODO: add page_params.notifications_stream_id + return exports.name_in_home_view(page_params.notifications_stream); +}; + exports.is_subscribed = function (stream_name) { var sub = exports.get_sub(stream_name); return sub !== undefined && sub.subscribed; @@ -454,9 +464,12 @@ exports.get_newbie_stream = function () { if (exports.is_subscribed("new members")) { return "new members"; - } else if (exports.in_home_view(page_params.notifications_stream)) { + } + + if (exports.notifications_in_home_view()) { return page_params.notifications_stream; } + return undefined; }; diff --git a/static/js/stream_list.js b/static/js/stream_list.js index ccfa5c976a..a2c4f468c0 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -203,7 +203,7 @@ function build_stream_sidebar_li(sub) { var args = {name: name, id: sub.stream_id, uri: narrow.by_stream_uri(name), - not_in_home_view: (stream_data.in_home_view(name) === false), + not_in_home_view: (stream_data.in_home_view(sub.stream_id) === false), invite_only: sub.invite_only, color: stream_data.get_color(name), pin_to_top: sub.pin_to_top, diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js index b875eb70f9..9710439993 100644 --- a/static/js/tab_bar.js +++ b/static/js/tab_bar.js @@ -15,10 +15,22 @@ function make_tab_data() { var tabs = []; var filter = narrow_state.filter(); + function filtered_to_non_home_view_stream() { + if (!filter.has_operator('stream')) { + return false; + } + var stream_name = filter.operands('stream')[0]; + var stream_id = stream_data.get_stream_id(stream_name); + if (!stream_id) { + return true; + } + + return !stream_data.in_home_view(stream_id); + } + // Root breadcrumb item: Either Home or All Messages if (filter !== undefined && - ((filter.has_operator("stream") && - !stream_data.in_home_view(filter.operands("stream")[0])) || + (filtered_to_non_home_view_stream() || filter.has_operand("in", "all"))) { tabs.push(make_tab("All Messages", "#narrow/in/all", undefined, "root")); } else if (page_params.narrow !== undefined) { diff --git a/static/js/tutorial.js b/static/js/tutorial.js index 30df587742..478cbab7fc 100644 --- a/static/js/tutorial.js +++ b/static/js/tutorial.js @@ -355,7 +355,7 @@ function finale(skip) { // 'engineering' is the best possible stream since we used it in the // tutorial, but fall back to something else if we have to. var work_stream; - if (stream_data.in_home_view("engineering")) { + if (stream_data.name_in_home_view("engineering")) { work_stream = "engineering"; } else { work_stream = _.find(stream_data.home_view_stream_names(), @@ -364,7 +364,7 @@ function finale(skip) { }); } - if (stream_data.in_home_view(page_params.notifications_stream)) { + if (stream_data.notifications_in_home_view()) { send_delayed_stream_message(page_params.notifications_stream, "welcome", "Practice sending sending some messages here, or starting a new topic.", 15); send_delayed_stream_message(page_params.notifications_stream, "Zulip tips", "Here's a message on a new topic: `Zulip tips`.\n\nAs you settle into Zulip, customize your account and notifications on your [Settings page](#settings).", 30); send_delayed_stream_message(page_params.notifications_stream, "Zulip tips", "You might also enjoy:\n\n* Our lightweight !modal_link(#markdown-help, message formatting) (including emoji! :thumbsup:)\n* !modal_link(#keyboard-shortcuts, Keyboard shortcuts)\n* [Desktop and mobile apps](/apps)", 40); @@ -375,7 +375,7 @@ function finale(skip) { send_delayed_stream_message(work_stream, "projects", "Take a peek at our [integrations](/integrations). Now's a great time to set one up!", 65); } - if (stream_data.in_home_view("social")) { + if (stream_data.name_in_home_view("social")) { send_delayed_stream_message("social", "cute animals", "This is a message on stream `social` with the topic `cute animals`. Try uploading or pasting in some pictures. Here's a [guinea pig](/static/images/cute/guinea.jpg) to get you started:", 75); } } diff --git a/static/js/unread.js b/static/js/unread.js index 5488f29bb1..e256fc4693 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -86,7 +86,9 @@ exports.unread_topic_counter = (function () { } }); res.stream_count.set(stream, stream_count); - if (stream_data.in_home_view(stream)) { + + var stream_id = stream_data.get_stream_id(stream); + if (stream_data.in_home_view(stream_id)) { res.stream_unread_messages += stream_count; } }