mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 02:48:00 +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);
|
||||
});
|
||||
|
||||
const tony = {
|
||||
stream_id: 999,
|
||||
name: 'tony',
|
||||
subscribed: true,
|
||||
is_muted: false,
|
||||
};
|
||||
|
||||
const jazy = {
|
||||
stream_id: 500,
|
||||
name: 'jazy',
|
||||
subscribed: false,
|
||||
is_muted: true,
|
||||
};
|
||||
|
||||
run_test('is_muted', () => {
|
||||
const tony = {
|
||||
stream_id: 999,
|
||||
name: 'tony',
|
||||
subscribed: true,
|
||||
is_muted: false,
|
||||
};
|
||||
|
||||
const jazy = {
|
||||
stream_id: 500,
|
||||
name: 'jazy',
|
||||
subscribed: false,
|
||||
is_muted: true,
|
||||
};
|
||||
|
||||
stream_data.add_sub(tony);
|
||||
stream_data.add_sub(jazy);
|
||||
assert(!stream_data.is_stream_muted_by_name('tony'));
|
||||
@@ -798,10 +798,13 @@ run_test('is_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());
|
||||
|
||||
page_params.notifications_stream = 'jazy';
|
||||
page_params.realm_notifications_stream_id = jazy.stream_id;
|
||||
assert(stream_data.is_notifications_stream_muted());
|
||||
});
|
||||
|
||||
@@ -904,12 +907,12 @@ run_test('initialize', () => {
|
||||
assert(stream_names.includes('subscriptions'));
|
||||
assert(stream_names.includes('unsubscribed'));
|
||||
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
|
||||
page_params.realm_notifications_stream_id = 89;
|
||||
initialize();
|
||||
assert.equal(page_params.notifications_stream, "");
|
||||
assert.equal(stream_data.get_notifications_stream(), "");
|
||||
|
||||
// Now actually subscribe the user to the stream
|
||||
initialize();
|
||||
@@ -920,7 +923,7 @@ run_test('initialize', () => {
|
||||
|
||||
stream_data.add_sub(foo);
|
||||
initialize();
|
||||
assert.equal(page_params.notifications_stream, "foo");
|
||||
assert.equal(stream_data.get_notifications_stream(), "foo");
|
||||
});
|
||||
|
||||
run_test('filter inactives', () => {
|
||||
|
||||
@@ -135,7 +135,7 @@ exports.get_invite_streams = function () {
|
||||
function update_subscription_checkboxes() {
|
||||
const data = {
|
||||
streams: exports.get_invite_streams(),
|
||||
notifications_stream: page_params.notifications_stream,
|
||||
notifications_stream: stream_data.get_notifications_stream(),
|
||||
};
|
||||
const html = render_invite_subscription(data);
|
||||
$('#streams_to_add').html(html);
|
||||
|
||||
@@ -101,7 +101,7 @@ const stream_name_error = (function () {
|
||||
function update_announce_stream_state() {
|
||||
|
||||
// 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();
|
||||
return;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ function create_stream() {
|
||||
}
|
||||
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');
|
||||
data.announce = JSON.stringify(announce);
|
||||
|
||||
@@ -274,7 +274,7 @@ exports.show_new_stream_modal = function () {
|
||||
// public, "announce stream" on.
|
||||
$('#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 input').prop('disabled', false);
|
||||
$('#announce-new-stream input').prop('checked', true);
|
||||
@@ -437,7 +437,8 @@ exports.set_up_handlers = function () {
|
||||
announce_stream_docs.popover({
|
||||
placement: "right",
|
||||
content: render_announce_stream_docs({
|
||||
notifications_stream: page_params.notifications_stream}),
|
||||
notifications_stream: stream_data.get_notifications_stream(),
|
||||
}),
|
||||
html: true,
|
||||
trigger: "manual"});
|
||||
announce_stream_docs.popover('show');
|
||||
|
||||
@@ -512,8 +512,7 @@ exports.is_stream_muted_by_name = function (stream_name) {
|
||||
};
|
||||
|
||||
exports.is_notifications_stream_muted = function () {
|
||||
// TODO: add page_params.notifications_stream_id
|
||||
return exports.is_stream_muted_by_name(page_params.notifications_stream);
|
||||
return exports.is_muted(page_params.realm_notifications_stream_id);
|
||||
};
|
||||
|
||||
exports.is_subscribed = function (stream_name) {
|
||||
@@ -865,6 +864,19 @@ exports.get_streams_for_admin = function () {
|
||||
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) {
|
||||
/*
|
||||
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(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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user