mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 18:06:44 +00:00
Simplify code to warn about private stream links.
This change does a few things:
* I use "early return" to make the code a bit flatter
and easier to comment.
* I added more comments.
* I removed some unneeded passing of `invite_only` into
the template.
This commit is contained in:
@@ -1089,7 +1089,6 @@ function test_with_mock_socket(test_params) {
|
|||||||
templates.render = function (template_name, context) {
|
templates.render = function (template_name, context) {
|
||||||
called = true;
|
called = true;
|
||||||
assert.equal(template_name, 'compose_private_stream_alert');
|
assert.equal(template_name, 'compose_private_stream_alert');
|
||||||
assert.equal(context.invite_only, true);
|
|
||||||
assert.equal(context.stream_name, 'Denmark');
|
assert.equal(context.stream_name, 'Denmark');
|
||||||
return 'fake-compose_private_stream_alert-template';
|
return 'fake-compose_private_stream_alert-template';
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -521,7 +521,6 @@ function render(template_name, args) {
|
|||||||
(function compose_private_stream_alert() {
|
(function compose_private_stream_alert() {
|
||||||
var args = {
|
var args = {
|
||||||
stream_name: 'Denmark',
|
stream_name: 'Denmark',
|
||||||
invite_only: true,
|
|
||||||
};
|
};
|
||||||
var html = render('compose_private_stream_alert', args);
|
var html = render('compose_private_stream_alert', args);
|
||||||
assert($(html).hasClass('compose_private_stream_alert'));
|
assert($(html).hasClass('compose_private_stream_alert'));
|
||||||
|
|||||||
@@ -640,24 +640,34 @@ exports.initialize = function () {
|
|||||||
|
|
||||||
// Show a warning if a private stream is linked
|
// Show a warning if a private stream is linked
|
||||||
$(document).on('streamname_completed.zulip', function (event, data) {
|
$(document).on('streamname_completed.zulip', function (event, data) {
|
||||||
|
// For PMs, we don't warn about links to private streams, since
|
||||||
|
// you are often specifically encouraging somebody to subscribe
|
||||||
|
// to the stream over PMs.
|
||||||
if (compose_state.get_message_type() !== 'stream') {
|
if (compose_state.get_message_type() !== 'stream') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data !== undefined && data.stream !== undefined) {
|
if (data === undefined || data.stream === undefined) {
|
||||||
var invite_only = data.stream.invite_only;
|
blueslip.error('Invalid options passed into handler.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// data.stream refers to the stream we're linking to in
|
||||||
|
// typeahead. If it's not invite-only, then it's public, and
|
||||||
|
// there is no need to warn about it, since all users can already
|
||||||
|
// see all the public streams.
|
||||||
|
if (!data.stream.invite_only) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var stream_name = data.stream.name;
|
var stream_name = data.stream.name;
|
||||||
|
|
||||||
if (invite_only) {
|
|
||||||
var warning_area = $("#compose_private_stream_alert");
|
var warning_area = $("#compose_private_stream_alert");
|
||||||
var context = { stream_name: stream_name, invite_only: invite_only };
|
var context = { stream_name: stream_name };
|
||||||
var new_row = templates.render("compose_private_stream_alert", context);
|
var new_row = templates.render("compose_private_stream_alert", context);
|
||||||
|
|
||||||
warning_area.append(new_row);
|
warning_area.append(new_row);
|
||||||
warning_area.show();
|
warning_area.show();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#compose_private_stream_alert").on('click', '.compose_private_stream_alert_close', function (event) {
|
$("#compose_private_stream_alert").on('click', '.compose_private_stream_alert_close', function (event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user