mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
Use real stream ids in our stream-related UI widgets.
Before this change, we were using sequentially generated ids on the client side to identify streams. Now we just use the ids from the server. The goal here is to reduce the confusion of having two different ids attached to a stream. Also, not that it matters a ton, but this also means that the browser basically has an immutable id for each stream that is future-proof to reloads, multiple create_sub calls, etc. It also a bit easier to grep for ".stream_id" than ".id". (imported from commit 057f9e50dfee127edfe3facd52da93108241666a)
This commit is contained in:
@@ -416,7 +416,8 @@ exports.register_click_handlers = function () {
|
||||
}
|
||||
|
||||
$(elt).popover("show");
|
||||
var popover = $('.streams_popover[data-id=' + stream_data.get_sub(stream).id + ']');
|
||||
var data_id = stream_data.get_sub(stream).stream_id;
|
||||
var popover = $('.streams_popover[data-id=' + data_id + ']');
|
||||
update_spectrum(popover, function (colorpicker) {
|
||||
colorpicker.spectrum(stream_color.sidebar_popover_colorpicker_options);
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@ exports.set_colorpicker_color = function (colorpicker, color) {
|
||||
exports.update_stream_color = function (sub, stream_name, color, opts) {
|
||||
opts = _.defaults({}, opts, {update_historical: false});
|
||||
sub.color = color;
|
||||
var id = parseInt(sub.id, 10);
|
||||
var id = parseInt(sub.stream_id, 10);
|
||||
// The swatch in the subscription row header.
|
||||
$("#subscription_" + id + " .color_swatch").css('background-color', color);
|
||||
// The swatch in the color picker.
|
||||
@@ -95,7 +95,7 @@ exports.update_stream_color = function (sub, stream_name, color, opts) {
|
||||
if (opts.update_historical) {
|
||||
update_historical_message_color(stream_name, color);
|
||||
}
|
||||
update_stream_sidebar_swatch_color(sub.id, color);
|
||||
update_stream_sidebar_swatch_color(id, color);
|
||||
tab_bar.colorize_tab_bar();
|
||||
};
|
||||
|
||||
|
||||
@@ -74,7 +74,8 @@ function iterate_to_find(selector, name_to_find, context) {
|
||||
// as well, we probably should consider moving them to a different file.
|
||||
function get_filter_li(type, name) {
|
||||
if (type === 'stream') {
|
||||
return $("#stream_sidebar_" + subs.stream_id(name));
|
||||
var sub = stream_data.get_sub(name);
|
||||
return $("#stream_sidebar_" + sub.stream_id);
|
||||
} else if (type === "private") {
|
||||
if (name.indexOf(",") < 0) {
|
||||
return $("li.user_sidebar_entry[data-email='" + name + "']");
|
||||
@@ -126,11 +127,12 @@ exports.set_in_home_view = function (stream, in_home) {
|
||||
};
|
||||
|
||||
function build_stream_sidebar_row(name) {
|
||||
var sub = stream_data.get_sub(name);
|
||||
var args = {name: name,
|
||||
id: subs.stream_id(name),
|
||||
id: sub.stream_id,
|
||||
uri: narrow.by_stream_uri(name),
|
||||
not_in_home_view: (stream_data.in_home_view(name) === false),
|
||||
invite_only: stream_data.get_sub(name).invite_only,
|
||||
invite_only: sub.invite_only,
|
||||
color: stream_data.get_color(name)
|
||||
};
|
||||
args.dark_background = stream_color.get_color_class(args.color);
|
||||
|
||||
@@ -2,8 +2,6 @@ var subs = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
var next_sub_id = 0;
|
||||
|
||||
function add_admin_options(sub) {
|
||||
return _.extend(sub, {
|
||||
'is_admin': page_params.is_admin,
|
||||
@@ -45,7 +43,7 @@ exports.stream_id = function (stream_name) {
|
||||
blueslip.error("Tried to get subs.stream_id for a stream user is not subscribed to!");
|
||||
return 0;
|
||||
}
|
||||
return parseInt(sub.id, 10);
|
||||
return parseInt(sub.stream_id, 10);
|
||||
};
|
||||
|
||||
function set_stream_property(stream_name, property, value) {
|
||||
@@ -111,7 +109,7 @@ function update_in_home_view(sub, value) {
|
||||
|
||||
stream_list.set_in_home_view(sub.name, sub.in_home_view);
|
||||
|
||||
var not_in_home_view_checkbox = $("#subscription_" + sub.id + " #sub_setting_not_in_home_view .sub_setting_control");
|
||||
var not_in_home_view_checkbox = $("#subscription_" + sub.stream_id + " #sub_setting_not_in_home_view .sub_setting_control");
|
||||
not_in_home_view_checkbox.attr('checked', !value);
|
||||
}
|
||||
|
||||
@@ -122,7 +120,7 @@ exports.toggle_home = function (stream_name) {
|
||||
};
|
||||
|
||||
function update_stream_notifications(sub, value) {
|
||||
var in_home_view_checkbox = $("#subscription_" + sub.id + " #sub_setting_notifications .sub_setting_control");
|
||||
var in_home_view_checkbox = $("#subscription_" + sub.stream_id + " #sub_setting_notifications .sub_setting_control");
|
||||
in_home_view_checkbox.attr('checked', value);
|
||||
sub.notifications = value;
|
||||
}
|
||||
@@ -146,7 +144,7 @@ function update_stream_name(sub, new_name) {
|
||||
function update_stream_description(sub, description) {
|
||||
sub.description = description;
|
||||
|
||||
var sub_settings_selector = '.subscription_row[data-subscription-id=' + sub.id + ']';
|
||||
var sub_settings_selector = '.subscription_row[data-subscription-id=' + sub.stream_id + ']';
|
||||
$(sub_settings_selector + ' .subscription_description').text(description);
|
||||
$(sub_settings_selector + ' input.description').val(description);
|
||||
}
|
||||
@@ -173,6 +171,12 @@ function create_sub(stream_name, attrs) {
|
||||
return sub;
|
||||
}
|
||||
|
||||
if (!attrs.stream_id) {
|
||||
// fail fast (blueslip.fatal will throw an error on our behalf)
|
||||
blueslip.fatal("We cannot create a sub without a stream_id");
|
||||
return; // this line is never actually reached
|
||||
}
|
||||
|
||||
// Our internal data structure for subscriptions is mostly plain dictionaries,
|
||||
// so we just reuse the attrs that are passed in to us, but we encapsulate how
|
||||
// we handle subscribers.
|
||||
@@ -181,7 +185,6 @@ function create_sub(stream_name, attrs) {
|
||||
|
||||
sub = _.defaults(raw_attrs, {
|
||||
name: stream_name,
|
||||
id: next_sub_id++,
|
||||
render_subscribers: page_params.domain !== 'mit.edu' || attrs.invite_only === true,
|
||||
subscribed: true,
|
||||
in_home_view: true,
|
||||
@@ -202,12 +205,12 @@ function create_sub(stream_name, attrs) {
|
||||
}
|
||||
|
||||
function button_for_sub(sub) {
|
||||
var id = parseInt(sub.id, 10);
|
||||
var id = parseInt(sub.stream_id, 10);
|
||||
return $("#subscription_" + id + " .sub_unsub_button");
|
||||
}
|
||||
|
||||
function settings_for_sub(sub) {
|
||||
var id = parseInt(sub.id, 10);
|
||||
var id = parseInt(sub.stream_id, 10);
|
||||
return $("#subscription_settings_" + id);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{! Contents of the "stream actions" popup }}
|
||||
<ul class="nav nav-list streams_popover" data-id="{{ stream.id }}" data-name="{{ stream.name }}">
|
||||
<ul class="nav nav-list streams_popover" data-id="{{ stream.stream_id }}" data-name="{{ stream.name }}">
|
||||
<li>
|
||||
<a class="narrow_to_stream">
|
||||
<i class="icon-vector-bullhorn"></i>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{! Client-side Mustache template for rendering subscriptions.}}
|
||||
{{#with this}}
|
||||
<div class="subscription_row" id="subscription_{{id}}" data-subscription-id="{{id}}">
|
||||
<div class="subscription_table_elem subscription_header collapsed" data-toggle="collapse" data-target="#subscription_settings_{{id}}">
|
||||
<div class="subscription_row" id="subscription_{{stream_id}}" data-subscription-id="{{stream_id}}">
|
||||
<div class="subscription_table_elem subscription_header collapsed" data-toggle="collapse" data-target="#subscription_settings_{{stream_id}}">
|
||||
<span class="subscription-setting-icon">
|
||||
{{partial "subscription_setting_icon"}}
|
||||
</span>
|
||||
@@ -21,7 +21,7 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="subscription_settings_{{id}}" class="collapse subscription_settings">
|
||||
<div id="subscription_settings_{{stream_id}}" class="collapse subscription_settings">
|
||||
<div class="regular_subscription_settings collapse {{#subscribed}}in{{/subscribed}}">
|
||||
<div class="subscription-type">
|
||||
{{partial "subscription_type"}}
|
||||
@@ -30,13 +30,13 @@
|
||||
<ul>
|
||||
<li>
|
||||
<div id="sub_setting_not_in_home_view" class="sub_setting_checkbox">
|
||||
<input id="mutestream-{{id}}" class="sub_setting_control" type="checkbox" tabindex="-1" {{#unless in_home_view}}checked{{/unless}} />
|
||||
<input id="mutestream-{{stream_id}}" class="sub_setting_control" type="checkbox" tabindex="-1" {{#unless in_home_view}}checked{{/unless}} />
|
||||
<label class="subscription-control-label">Mute stream</label>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<div id="sub_setting_notifications" class="sub_setting_checkbox">
|
||||
<input id="notifystream-{{id}}" class="sub_setting_control" type="checkbox" tabindex="-1" {{#if notifications}}checked{{/if}} />
|
||||
<input id="notifystream-{{stream_id}}" class="sub_setting_control" type="checkbox" tabindex="-1" {{#if notifications}}checked{{/if}} />
|
||||
<label class="subscription-control-label">Show desktop notifications<br/>for traffic on this stream</label>
|
||||
</div>
|
||||
</li>
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
{{#if_and subscribed email_address}}
|
||||
<div class="stream-email-box">
|
||||
<span class="sub_settings_title">Email address <i class="icon-vector-question-sign stream-email-hint" id="email-address-hint-{{id}}"></i></span>
|
||||
<span class="sub_settings_title">Email address <i class="icon-vector-question-sign stream-email-hint" id="email-address-hint-{{stream_id}}"></i></span>
|
||||
<div class="stream-email">
|
||||
<span class="email-address">{{email_address}}</span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user