mirror of
https://github.com/zulip/zulip.git
synced 2025-10-26 17:43:58 +00:00
Fix how we find if streams are muted.
This commit changes stream_data.in_home_view() to take a stream_id parameter, which will make it more robust to stream name changes. This fixes a bug. Now when an admin renames a stream you are looking at, it will correctly show itself to be un-muted. (Even with this fix, though, the stream appears to be inactive.) Some callers still do lookups by name, and they will call name_in_home_view() for now, which we can hopefully deprecate over time.
This commit is contained in:
@@ -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'}));
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user