mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +00:00
stream_data: Remove page_params.notifications_stream.
We shouldn't add redundant data to page_params. Since we already have page_params.realm_notifications_stream_id, we can use that value instead of creating page_params.notifications_stream. We, however, still need the name of the notifications stream to render it in templates. Thus we create stream_data.get_notifications_stream().
This commit is contained in:
committed by
Tim Abbott
parent
fe5a1eeaeb
commit
e79935dbf7
@@ -775,21 +775,21 @@ run_test('notifications', () => {
|
|||||||
assert.deepEqual(unmatched_streams, expected_streams);
|
assert.deepEqual(unmatched_streams, expected_streams);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('is_muted', () => {
|
const tony = {
|
||||||
const tony = {
|
|
||||||
stream_id: 999,
|
stream_id: 999,
|
||||||
name: 'tony',
|
name: 'tony',
|
||||||
subscribed: true,
|
subscribed: true,
|
||||||
is_muted: false,
|
is_muted: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const jazy = {
|
const jazy = {
|
||||||
stream_id: 500,
|
stream_id: 500,
|
||||||
name: 'jazy',
|
name: 'jazy',
|
||||||
subscribed: false,
|
subscribed: false,
|
||||||
is_muted: true,
|
is_muted: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
run_test('is_muted', () => {
|
||||||
stream_data.add_sub(tony);
|
stream_data.add_sub(tony);
|
||||||
stream_data.add_sub(jazy);
|
stream_data.add_sub(jazy);
|
||||||
assert(!stream_data.is_stream_muted_by_name('tony'));
|
assert(!stream_data.is_stream_muted_by_name('tony'));
|
||||||
@@ -798,10 +798,13 @@ run_test('is_muted', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
run_test('is_notifications_stream_muted', () => {
|
run_test('is_notifications_stream_muted', () => {
|
||||||
page_params.notifications_stream = 'tony';
|
stream_data.add_sub(tony);
|
||||||
|
stream_data.add_sub(jazy);
|
||||||
|
|
||||||
|
page_params.realm_notifications_stream_id = tony.stream_id;
|
||||||
assert(!stream_data.is_notifications_stream_muted());
|
assert(!stream_data.is_notifications_stream_muted());
|
||||||
|
|
||||||
page_params.notifications_stream = 'jazy';
|
page_params.realm_notifications_stream_id = jazy.stream_id;
|
||||||
assert(stream_data.is_notifications_stream_muted());
|
assert(stream_data.is_notifications_stream_muted());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -904,12 +907,12 @@ run_test('initialize', () => {
|
|||||||
assert(stream_names.includes('subscriptions'));
|
assert(stream_names.includes('subscriptions'));
|
||||||
assert(stream_names.includes('unsubscribed'));
|
assert(stream_names.includes('unsubscribed'));
|
||||||
assert(stream_names.includes('never_subscribed'));
|
assert(stream_names.includes('never_subscribed'));
|
||||||
assert.equal(page_params.notifications_stream, "");
|
assert.equal(stream_data.get_notifications_stream(), "");
|
||||||
|
|
||||||
// Simulate a private stream the user isn't subscribed to
|
// Simulate a private stream the user isn't subscribed to
|
||||||
page_params.realm_notifications_stream_id = 89;
|
page_params.realm_notifications_stream_id = 89;
|
||||||
initialize();
|
initialize();
|
||||||
assert.equal(page_params.notifications_stream, "");
|
assert.equal(stream_data.get_notifications_stream(), "");
|
||||||
|
|
||||||
// Now actually subscribe the user to the stream
|
// Now actually subscribe the user to the stream
|
||||||
initialize();
|
initialize();
|
||||||
@@ -920,7 +923,7 @@ run_test('initialize', () => {
|
|||||||
|
|
||||||
stream_data.add_sub(foo);
|
stream_data.add_sub(foo);
|
||||||
initialize();
|
initialize();
|
||||||
assert.equal(page_params.notifications_stream, "foo");
|
assert.equal(stream_data.get_notifications_stream(), "foo");
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('filter inactives', () => {
|
run_test('filter inactives', () => {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ exports.get_invite_streams = function () {
|
|||||||
function update_subscription_checkboxes() {
|
function update_subscription_checkboxes() {
|
||||||
const data = {
|
const data = {
|
||||||
streams: exports.get_invite_streams(),
|
streams: exports.get_invite_streams(),
|
||||||
notifications_stream: page_params.notifications_stream,
|
notifications_stream: stream_data.get_notifications_stream(),
|
||||||
};
|
};
|
||||||
const html = render_invite_subscription(data);
|
const html = render_invite_subscription(data);
|
||||||
$('#streams_to_add').html(html);
|
$('#streams_to_add').html(html);
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ const stream_name_error = (function () {
|
|||||||
function update_announce_stream_state() {
|
function update_announce_stream_state() {
|
||||||
|
|
||||||
// If there is no notifications_stream, we simply hide the widget.
|
// If there is no notifications_stream, we simply hide the widget.
|
||||||
if (!page_params.notifications_stream) {
|
if (page_params.realm_notifications_stream_id === -1) {
|
||||||
$('#announce-new-stream').hide();
|
$('#announce-new-stream').hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ function create_stream() {
|
|||||||
}
|
}
|
||||||
data.stream_post_policy = JSON.stringify(stream_post_policy);
|
data.stream_post_policy = JSON.stringify(stream_post_policy);
|
||||||
|
|
||||||
const announce = !!page_params.notifications_stream &&
|
const announce = page_params.realm_notifications_stream_id !== -1 &&
|
||||||
$('#announce-new-stream input').prop('checked');
|
$('#announce-new-stream input').prop('checked');
|
||||||
data.announce = JSON.stringify(announce);
|
data.announce = JSON.stringify(announce);
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ exports.show_new_stream_modal = function () {
|
|||||||
// public, "announce stream" on.
|
// public, "announce stream" on.
|
||||||
$('#make-invite-only input:radio[value=public]').prop('checked', true);
|
$('#make-invite-only input:radio[value=public]').prop('checked', true);
|
||||||
|
|
||||||
if (page_params.notifications_stream) {
|
if (page_params.realm_notifications_stream_id !== -1) {
|
||||||
$('#announce-new-stream').show();
|
$('#announce-new-stream').show();
|
||||||
$('#announce-new-stream input').prop('disabled', false);
|
$('#announce-new-stream input').prop('disabled', false);
|
||||||
$('#announce-new-stream input').prop('checked', true);
|
$('#announce-new-stream input').prop('checked', true);
|
||||||
@@ -437,7 +437,8 @@ exports.set_up_handlers = function () {
|
|||||||
announce_stream_docs.popover({
|
announce_stream_docs.popover({
|
||||||
placement: "right",
|
placement: "right",
|
||||||
content: render_announce_stream_docs({
|
content: render_announce_stream_docs({
|
||||||
notifications_stream: page_params.notifications_stream}),
|
notifications_stream: stream_data.get_notifications_stream(),
|
||||||
|
}),
|
||||||
html: true,
|
html: true,
|
||||||
trigger: "manual"});
|
trigger: "manual"});
|
||||||
announce_stream_docs.popover('show');
|
announce_stream_docs.popover('show');
|
||||||
|
|||||||
@@ -512,8 +512,7 @@ exports.is_stream_muted_by_name = function (stream_name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.is_notifications_stream_muted = function () {
|
exports.is_notifications_stream_muted = function () {
|
||||||
// TODO: add page_params.notifications_stream_id
|
return exports.is_muted(page_params.realm_notifications_stream_id);
|
||||||
return exports.is_stream_muted_by_name(page_params.notifications_stream);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.is_subscribed = function (stream_name) {
|
exports.is_subscribed = function (stream_name) {
|
||||||
@@ -865,6 +864,19 @@ exports.get_streams_for_admin = function () {
|
|||||||
return subs;
|
return subs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.get_notifications_stream = function () {
|
||||||
|
const stream_id = page_params.realm_notifications_stream_id;
|
||||||
|
if (stream_id !== -1) {
|
||||||
|
const stream_obj = exports.get_sub_by_id(stream_id);
|
||||||
|
if (stream_obj) {
|
||||||
|
return stream_obj.name;
|
||||||
|
}
|
||||||
|
// We reach here when the notifications stream is a private
|
||||||
|
// stream the current user is not subscribed to.
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
|
||||||
exports.initialize = function (params) {
|
exports.initialize = function (params) {
|
||||||
/*
|
/*
|
||||||
We get `params` data, which is data that we "own"
|
We get `params` data, which is data that we "own"
|
||||||
@@ -904,22 +916,6 @@ exports.initialize = function (params) {
|
|||||||
populate_subscriptions(unsubscribed, false, true);
|
populate_subscriptions(unsubscribed, false, true);
|
||||||
populate_subscriptions(never_subscribed, false, false);
|
populate_subscriptions(never_subscribed, false, false);
|
||||||
|
|
||||||
// Migrate the notifications stream from the new API structure to
|
|
||||||
// what the frontend expects.
|
|
||||||
if (page_params.realm_notifications_stream_id !== -1) {
|
|
||||||
const notifications_stream_obj =
|
|
||||||
exports.get_sub_by_id(page_params.realm_notifications_stream_id);
|
|
||||||
if (notifications_stream_obj) {
|
|
||||||
// This happens when the notifications stream is a private
|
|
||||||
// stream the current user is not subscribed to.
|
|
||||||
page_params.notifications_stream = notifications_stream_obj.name;
|
|
||||||
} else {
|
|
||||||
page_params.notifications_stream = "";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
page_params.notifications_stream = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.set_filter_out_inactives();
|
exports.set_filter_out_inactives();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user