2013-05-06 02:54:15 +02:00
|
|
|
var stream_list = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
var zoomed_stream = '';
|
2013-05-07 19:07:05 +02:00
|
|
|
var previous_sort_order;
|
2016-07-01 07:26:09 +02:00
|
|
|
var previous_unpinned_order;
|
2013-05-16 23:40:07 +02:00
|
|
|
|
2017-01-15 17:02:29 +01:00
|
|
|
function update_count_in_dom(unread_count_elem, count) {
|
|
|
|
var count_span = unread_count_elem.find('.count');
|
|
|
|
var value_span = count_span.find('.value');
|
|
|
|
|
|
|
|
if (count === 0) {
|
|
|
|
count_span.hide();
|
|
|
|
if (count_span.parent().hasClass("subscription_block")) {
|
|
|
|
count_span.parent(".subscription_block").removeClass("stream-with-count");
|
|
|
|
}
|
|
|
|
value_span.text('');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count_span.show();
|
|
|
|
|
|
|
|
if (count_span.parent().hasClass("subscription_block")) {
|
|
|
|
count_span.parent(".subscription_block").addClass("stream-with-count");
|
|
|
|
}
|
|
|
|
value_span.text(count);
|
|
|
|
}
|
|
|
|
|
2016-06-13 22:06:12 +02:00
|
|
|
function filter_streams_by_search(streams) {
|
|
|
|
var search_box = $(".stream-list-filter");
|
|
|
|
|
|
|
|
var search_term = search_box.expectOne().val().trim();
|
|
|
|
|
|
|
|
if (search_term === '') {
|
|
|
|
return streams;
|
|
|
|
}
|
|
|
|
|
|
|
|
var search_terms = search_term.toLowerCase().split(",");
|
|
|
|
search_terms = _.map(search_terms, function (s) {
|
|
|
|
return s.trim();
|
|
|
|
});
|
|
|
|
|
|
|
|
var filtered_streams = _.filter(streams, function (stream) {
|
|
|
|
return _.any(search_terms, function (search_term) {
|
|
|
|
var lower_stream_name = stream.toLowerCase().split(" ");
|
|
|
|
return _.any(lower_stream_name, function (name) {
|
|
|
|
return name.indexOf(search_term) === 0;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return filtered_streams;
|
|
|
|
}
|
|
|
|
|
2016-11-11 14:20:19 +01:00
|
|
|
exports.stream_sidebar = (function () {
|
|
|
|
var self = {};
|
|
|
|
|
|
|
|
self.rows = new Dict(); // stream id -> row widget
|
|
|
|
|
|
|
|
self.set_row = function (stream_id, widget) {
|
|
|
|
self.rows.set(stream_id, widget);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.get_row = function (stream_id) {
|
|
|
|
return self.rows.get(stream_id);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.has_row_for = function (stream_id) {
|
|
|
|
return self.rows.has(stream_id);
|
|
|
|
};
|
|
|
|
|
2016-11-11 15:09:08 +01:00
|
|
|
self.remove_row = function (stream_id) {
|
|
|
|
var widget = self.rows.get(stream_id);
|
|
|
|
if (!widget) {
|
|
|
|
blueslip.warn('Cannot remove stream id ' + stream_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
widget.remove();
|
|
|
|
self.rows.del(stream_id);
|
|
|
|
};
|
|
|
|
|
2016-11-11 14:20:19 +01:00
|
|
|
return self;
|
|
|
|
}());
|
|
|
|
|
2017-02-17 18:45:14 +01:00
|
|
|
exports.remove_sidebar_row = function (stream_id) {
|
|
|
|
exports.stream_sidebar.remove_row(stream_id);
|
|
|
|
// We need to make sure we resort if the removed sub gets added again
|
|
|
|
previous_sort_order = undefined;
|
|
|
|
previous_unpinned_order = undefined;
|
|
|
|
};
|
|
|
|
|
Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.
Now there is a clear separation of concerns, with these methods
being called in succession:
stream_data.initialize_from_page_params();
stream_list.create_initial_sidebar_rows();
The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict. Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.
Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
2016-10-17 19:34:58 +02:00
|
|
|
exports.create_initial_sidebar_rows = function () {
|
|
|
|
// This code is slightly opaque, but it ends up building
|
|
|
|
// up list items and attaching them to the "sub" data
|
|
|
|
// structures that are kept in stream_data.js.
|
|
|
|
var subs = stream_data.subscribed_subs();
|
|
|
|
|
|
|
|
_.each(subs, function (sub) {
|
|
|
|
exports.create_sidebar_row(sub);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-11-22 20:05:34 +01:00
|
|
|
exports.build_stream_list = function () {
|
Clean up startup code for streams.
The startup code in subs.js used to intermingle data
stuff and UI stuff in a loop inside a called function,
which made the code hard to reason about.
Now there is a clear separation of concerns, with these methods
being called in succession:
stream_data.initialize_from_page_params();
stream_list.create_initial_sidebar_rows();
The first method was mostly extracted from subs.js, but I simplified
some things, like not needing to make a copy of the hashes
we were passed in, plus I now garbage collect email_dict. Also,
the code path that initialize_from_page_params() mostly replaces
used to call create_sub(), which fired a trigger, but now it
just does data stuff.
Once the data structure is built up, it's a very simple matter
to build the initial sidebar rows, and that's what the second
method does.
2016-10-17 19:34:58 +02:00
|
|
|
// This function assumes we have already created the individual
|
|
|
|
// sidebar rows. Our job here is to build the bigger widget,
|
|
|
|
// which largely is a matter of arranging the individual rows in
|
|
|
|
// the right order.
|
2013-08-15 21:11:07 +02:00
|
|
|
var streams = stream_data.subscribed_streams();
|
2013-05-06 23:36:22 +02:00
|
|
|
if (streams.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-13 22:06:12 +02:00
|
|
|
streams = filter_streams_by_search(streams);
|
|
|
|
|
2013-05-06 23:36:22 +02:00
|
|
|
var sort_recent = (streams.length > 40);
|
2016-07-01 07:26:09 +02:00
|
|
|
var pinned_streams = [];
|
|
|
|
var unpinned_streams = [];
|
|
|
|
var parent = $('#stream_filters');
|
|
|
|
var elems = [];
|
2013-05-06 23:36:22 +02:00
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
function add_sidebar_li(stream) {
|
2016-11-11 14:20:19 +01:00
|
|
|
var sub = stream_data.get_sub(stream);
|
|
|
|
var sidebar_row = exports.stream_sidebar.get_row(sub.stream_id);
|
2016-07-01 07:26:09 +02:00
|
|
|
if (sort_recent) {
|
2016-11-11 02:39:22 +01:00
|
|
|
sidebar_row.update_whether_active();
|
2016-07-01 07:26:09 +02:00
|
|
|
}
|
2016-11-11 02:39:22 +01:00
|
|
|
elems.push(sidebar_row.get_li().get(0));
|
2016-07-01 07:26:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_.each(streams, function (stream) {
|
|
|
|
var pinned = stream_data.get_sub(stream).pin_to_top;
|
|
|
|
if (pinned) {
|
|
|
|
pinned_streams.push(stream);
|
|
|
|
} else {
|
|
|
|
unpinned_streams.push(stream);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
left-sidebar: Sort pinned streams by lowercase stream name.
The pinned streams were sorted in alphabetic order (i.e. Verona appears
before devel). The reason is that after we plucked pinned streams out from
stream_data.subscribed_streams(), we didn't sort them again, so they
remained in the alphabetic order used in stream_data.
However, we did sort unpinned streams explicitly by using custom compare
function in stream_list.js (by default sort by lowercase stream name,
but when there are more than 40 subscribed streams, sort active streams
first). That's why this issue only relates to pinned streams.
Changes were made to sort pinned streams by lowercase stream name, always,
whether they are active or not (different from unpinned streams).
Tests were added to ensure this overall sort order is correct, i.e.
1. pinned streams are always sorted by lowercase stream name.
2. pinned streams are always before unpinned streams.
3. unpinned streams are sorted by lowercase stream name, if there are more
than 40 subscribed streams, sort active streams at the top, among active
and inactive streams, still sorted by lowercase stream name.
Fixes #3701
2017-02-19 15:24:27 +01:00
|
|
|
pinned_streams.sort(util.strcmp);
|
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
unpinned_streams.sort(function (a, b) {
|
2013-05-06 02:54:15 +02:00
|
|
|
if (sort_recent) {
|
2016-10-28 17:18:56 +02:00
|
|
|
if (stream_data.is_active(b) && ! stream_data.is_active(a)) {
|
2013-05-06 02:54:15 +02:00
|
|
|
return 1;
|
2016-10-28 17:18:56 +02:00
|
|
|
} else if (! stream_data.is_active(b) && stream_data.is_active(a)) {
|
2013-05-06 02:54:15 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-05-06 23:36:22 +02:00
|
|
|
return util.strcmp(a, b);
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
streams = pinned_streams.concat(unpinned_streams);
|
|
|
|
|
2016-12-02 15:16:33 +01:00
|
|
|
if (previous_sort_order !== undefined &&
|
|
|
|
util.array_compare(previous_sort_order, streams) &&
|
|
|
|
util.array_compare(previous_unpinned_order, unpinned_streams)) {
|
2013-05-07 19:07:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
previous_sort_order = streams;
|
2016-07-01 07:26:09 +02:00
|
|
|
previous_unpinned_order = unpinned_streams;
|
2013-05-06 02:54:15 +02:00
|
|
|
parent.empty();
|
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
if (pinned_streams.length > 0) {
|
|
|
|
_.each(pinned_streams, add_sidebar_li);
|
|
|
|
elems.push($('<hr class="pinned-stream-split">').get(0));
|
|
|
|
}
|
|
|
|
if (unpinned_streams.length > 0) {
|
|
|
|
_.each(unpinned_streams, add_sidebar_li);
|
|
|
|
}
|
|
|
|
|
2013-05-06 23:36:22 +02:00
|
|
|
$(elems).appendTo(parent);
|
2013-05-06 02:54:15 +02:00
|
|
|
};
|
|
|
|
|
2013-06-07 16:56:05 +02:00
|
|
|
function iterate_to_find(selector, name_to_find, context) {
|
2013-07-30 00:35:44 +02:00
|
|
|
var lowercase_name = name_to_find.toLowerCase();
|
|
|
|
var found = _.find($(selector, context), function (elem) {
|
2013-08-03 00:18:04 +02:00
|
|
|
return $(elem).attr('data-name').toLowerCase() === lowercase_name;
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
2013-07-30 00:35:44 +02:00
|
|
|
return found ? $(found) : $();
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
|
2013-05-06 22:18:01 +02:00
|
|
|
function get_filter_li(type, name) {
|
2013-05-06 02:54:15 +02:00
|
|
|
if (type === 'stream') {
|
2014-02-07 16:55:54 +01:00
|
|
|
var sub = stream_data.get_sub(name);
|
|
|
|
return $("#stream_sidebar_" + sub.stream_id);
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
return iterate_to_find("#" + type + "_filters > li", name);
|
2013-05-06 22:18:01 +02:00
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
function zoom_in() {
|
|
|
|
popovers.hide_all();
|
2016-11-10 16:15:12 +01:00
|
|
|
topic_list.zoom_in();
|
2015-12-11 08:24:00 +01:00
|
|
|
$("#streams_list").expectOne().removeClass("zoom-out").addClass("zoom-in");
|
2016-11-10 18:49:36 +01:00
|
|
|
zoomed_stream = narrow.stream();
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
// Hide stream list titles and pinned stream splitter
|
|
|
|
$(".stream-filters-label").each(function () {
|
|
|
|
$(this).hide();
|
|
|
|
});
|
|
|
|
$(".pinned-stream-split").each(function () {
|
|
|
|
$(this).hide();
|
|
|
|
});
|
|
|
|
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
$("#stream_filters li.narrow-filter").each(function () {
|
|
|
|
var elt = $(this);
|
|
|
|
|
|
|
|
if (elt.attr('data-name') === zoomed_stream) {
|
|
|
|
elt.show();
|
|
|
|
} else {
|
|
|
|
elt.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-11-10 16:45:56 +01:00
|
|
|
function zoom_out(options) {
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
popovers.hide_all();
|
2016-11-10 16:45:56 +01:00
|
|
|
topic_list.zoom_out(options);
|
2016-11-10 16:15:12 +01:00
|
|
|
|
2016-07-01 07:26:09 +02:00
|
|
|
// Show stream list titles and pinned stream splitter
|
|
|
|
$(".stream-filters-label").each(function () {
|
|
|
|
$(this).show();
|
|
|
|
});
|
|
|
|
$(".pinned-stream-split").each(function () {
|
|
|
|
$(this).show();
|
|
|
|
});
|
|
|
|
|
2015-12-11 08:24:00 +01:00
|
|
|
$("#streams_list").expectOne().removeClass("zoom-in").addClass("zoom-out");
|
Rewrite topic zoom to fix bugs and make cleaner.
In the first cut at topic zoom, I was re-rendering the
streams list, but this created glitches with orphaned
list items. The reproducible bug was that unread counts
on unshown streams weren't updating.
In the new approach, I keep the elements more permanent, and
I just hide and show them as needed, either through jQuery
show/hide or permanent CSS selectors.
I got rid of toggle_zoom(), so that we just explicitly zoom
in and zoom out in all situations. In particular, when we
narrow, it's more clear now that only stay zoomed in when
we're narrowing to the same stream as before (including topic
narrows within that stream).
When you zoom in, the number of topics is no longer limited
to 30, since that was kind of arbitrary anyway. (In practice,
the number of topics is usually well under 30, anyway, due to
the way we track them on the client.)
(imported from commit 5b6c143dee9ba9fe557d8cc36335ff28efb4b0de)
2013-11-26 23:06:39 +01:00
|
|
|
$("#stream_filters li.narrow-filter").show();
|
|
|
|
}
|
|
|
|
|
2015-12-11 08:35:36 +01:00
|
|
|
function reset_to_unnarrowed(narrowed_within_same_stream) {
|
2016-11-10 16:15:12 +01:00
|
|
|
if (topic_list.is_zoomed() && narrowed_within_same_stream !== true) {
|
2016-11-10 16:45:56 +01:00
|
|
|
zoom_out({clear_topics: true});
|
|
|
|
} else {
|
|
|
|
topic_list.remove_expanded_topics();
|
2015-12-11 08:35:36 +01:00
|
|
|
}
|
2015-11-25 18:41:32 +01:00
|
|
|
}
|
|
|
|
|
2013-06-12 00:07:35 +02:00
|
|
|
exports.set_in_home_view = function (stream, in_home) {
|
|
|
|
var li = get_filter_li('stream', stream);
|
|
|
|
if (in_home) {
|
|
|
|
li.removeClass("out_of_home_view");
|
|
|
|
} else {
|
|
|
|
li.addClass("out_of_home_view");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-11 02:39:22 +01:00
|
|
|
function build_stream_sidebar_li(sub) {
|
|
|
|
var name = sub.name;
|
2013-05-30 20:50:32 +02:00
|
|
|
var args = {name: name,
|
2014-02-07 16:55:54 +01:00
|
|
|
id: sub.stream_id,
|
2013-05-30 20:50:32 +02:00
|
|
|
uri: narrow.by_stream_uri(name),
|
2013-08-15 21:11:07 +02:00
|
|
|
not_in_home_view: (stream_data.in_home_view(name) === false),
|
2014-02-07 16:55:54 +01:00
|
|
|
invite_only: sub.invite_only,
|
2016-07-01 07:26:09 +02:00
|
|
|
color: stream_data.get_color(name),
|
2017-01-12 00:17:43 +01:00
|
|
|
pin_to_top: sub.pin_to_top,
|
2013-08-27 21:05:32 +02:00
|
|
|
};
|
|
|
|
args.dark_background = stream_color.get_color_class(args.color);
|
2013-06-12 18:03:16 +02:00
|
|
|
var list_item = $(templates.render('stream_sidebar_row', args));
|
2013-05-06 23:36:22 +02:00
|
|
|
return list_item;
|
2013-05-06 22:18:01 +02:00
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2016-11-11 02:39:22 +01:00
|
|
|
function build_stream_sidebar_row(sub) {
|
|
|
|
var self = {};
|
|
|
|
var list_item = build_stream_sidebar_li(sub);
|
|
|
|
var stream_name = sub.name;
|
|
|
|
|
|
|
|
self.update_whether_active = function () {
|
|
|
|
if (stream_data.is_active(stream_name)) {
|
|
|
|
list_item.removeClass('inactive_stream');
|
|
|
|
} else {
|
|
|
|
list_item.addClass('inactive_stream');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
self.get_li = function () {
|
|
|
|
return list_item;
|
|
|
|
};
|
|
|
|
|
2016-11-11 15:09:08 +01:00
|
|
|
self.remove = function () {
|
|
|
|
list_item.remove();
|
|
|
|
};
|
|
|
|
|
2017-01-15 17:09:16 +01:00
|
|
|
|
|
|
|
self.update_unread_count = function () {
|
|
|
|
var count = unread.num_unread_for_stream(stream_name);
|
|
|
|
update_count_in_dom(list_item, count);
|
|
|
|
};
|
|
|
|
|
|
|
|
self.update_unread_count();
|
|
|
|
|
2016-11-11 14:20:19 +01:00
|
|
|
exports.stream_sidebar.set_row(sub.stream_id, self);
|
2016-11-11 02:39:22 +01:00
|
|
|
}
|
|
|
|
|
2016-10-17 20:02:32 +02:00
|
|
|
exports.create_sidebar_row = function (sub) {
|
2016-11-11 14:20:19 +01:00
|
|
|
if (exports.stream_sidebar.has_row_for(sub.stream_id)) {
|
2013-10-21 22:26:19 +02:00
|
|
|
// already exists
|
2016-11-11 14:20:19 +01:00
|
|
|
blueslip.warn('Dup try to build sidebar row for stream ' + sub.stream_id);
|
2016-10-17 20:02:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-11-11 02:39:22 +01:00
|
|
|
build_stream_sidebar_row(sub);
|
2014-01-16 21:38:40 +01:00
|
|
|
};
|
|
|
|
|
2014-01-17 18:23:39 +01:00
|
|
|
exports.redraw_stream_privacy = function (stream_name) {
|
|
|
|
var li = exports.get_stream_li(stream_name);
|
|
|
|
var div = li.find('.stream-privacy');
|
2014-02-18 19:47:37 +01:00
|
|
|
var swatch = li.find('.streamlist_swatch');
|
2014-01-17 18:23:39 +01:00
|
|
|
var sub = stream_data.get_sub(stream_name);
|
|
|
|
var color = stream_data.get_color(stream_name);
|
|
|
|
var dark_background = stream_color.get_color_class(color);
|
|
|
|
|
|
|
|
var args = {
|
|
|
|
invite_only: sub.invite_only,
|
2017-01-12 00:17:43 +01:00
|
|
|
dark_background: dark_background,
|
2014-01-17 18:23:39 +01:00
|
|
|
};
|
|
|
|
|
2014-02-18 19:47:37 +01:00
|
|
|
if (sub.invite_only) {
|
|
|
|
swatch.addClass("private-stream-swatch");
|
2016-06-09 23:02:49 +02:00
|
|
|
} else {
|
2014-02-18 19:47:37 +01:00
|
|
|
swatch.removeClass("private-stream-swatch");
|
|
|
|
}
|
|
|
|
|
2014-01-17 18:23:39 +01:00
|
|
|
var html = templates.render('stream_privacy', args);
|
|
|
|
div.html(html);
|
|
|
|
};
|
|
|
|
|
2014-01-16 21:38:40 +01:00
|
|
|
exports.get_stream_li = function (stream_name) {
|
|
|
|
return get_filter_li('stream', stream_name);
|
|
|
|
};
|
|
|
|
|
2013-08-22 21:05:18 +02:00
|
|
|
function set_count(type, name, count) {
|
2017-01-15 16:24:49 +01:00
|
|
|
var unread_count_elem = get_filter_li(type, name);
|
|
|
|
update_count_in_dom(unread_count_elem, count);
|
2013-08-22 21:05:18 +02:00
|
|
|
}
|
2013-05-07 20:02:24 +02:00
|
|
|
|
2016-11-10 19:24:20 +01:00
|
|
|
function rebuild_recent_topics(stream) {
|
2016-08-27 04:08:43 +02:00
|
|
|
// TODO: Call rebuild_recent_topics less, not on every new
|
2013-11-22 18:50:10 +01:00
|
|
|
// message.
|
|
|
|
var stream_li = get_filter_li('stream', stream);
|
2016-11-10 19:24:20 +01:00
|
|
|
topic_list.rebuild(stream_li, stream);
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.update_streams_sidebar = function () {
|
2013-11-22 20:05:34 +01:00
|
|
|
exports.build_stream_list();
|
2013-05-06 02:54:15 +02:00
|
|
|
|
|
|
|
if (! narrow.active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var op_stream = narrow.filter().operands('stream');
|
|
|
|
if (op_stream.length !== 0) {
|
2013-08-15 21:11:07 +02:00
|
|
|
if (stream_data.is_subscribed(op_stream[0])) {
|
2016-11-10 19:24:20 +01:00
|
|
|
rebuild_recent_topics(op_stream[0]);
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-14 03:58:07 +02:00
|
|
|
exports.update_dom_with_unread_counts = function (counts) {
|
2016-11-14 17:14:59 +01:00
|
|
|
// We currently handle these message categories:
|
|
|
|
// home, starred, mentioned, streams, and topics
|
|
|
|
//
|
|
|
|
// Note that similar methods elsewhere in the code update
|
|
|
|
// the "Private Message" section in the upper left corner
|
|
|
|
// and the buddy lists in the right sidebar.
|
2013-05-14 03:58:07 +02:00
|
|
|
|
|
|
|
// counts.stream_count maps streams to counts
|
2013-08-15 16:16:12 +02:00
|
|
|
counts.stream_count.each(function (count, stream) {
|
2013-08-22 21:05:18 +02:00
|
|
|
set_count("stream", stream, count);
|
2013-05-14 03:58:07 +02:00
|
|
|
});
|
|
|
|
|
2016-10-28 19:07:25 +02:00
|
|
|
// counts.subject_count maps streams to hashes of topics to counts
|
2013-08-15 16:16:12 +02:00
|
|
|
counts.subject_count.each(function (subject_hash, stream) {
|
|
|
|
subject_hash.each(function (count, subject) {
|
2016-10-29 21:01:07 +02:00
|
|
|
topic_list.set_count(stream, subject, count);
|
2013-05-14 03:58:07 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// integer counts
|
2013-08-22 21:05:18 +02:00
|
|
|
set_count("global", "mentioned", counts.mentioned_message_count);
|
|
|
|
set_count("global", "home", counts.home_unread_messages);
|
2013-05-16 23:40:07 +02:00
|
|
|
|
2016-11-14 17:14:59 +01:00
|
|
|
unread_ui.set_count_toggle_button($("#streamlist-toggle-unreadcount"),
|
|
|
|
counts.home_unread_messages);
|
2013-09-03 17:40:34 +02:00
|
|
|
|
2016-11-14 17:14:59 +01:00
|
|
|
unread_ui.animate_mention_changes(get_filter_li('global', 'mentioned'),
|
|
|
|
counts.mentioned_message_count);
|
2013-05-14 03:58:07 +02:00
|
|
|
};
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
exports.rename_stream = function (sub) {
|
|
|
|
// The sub object is expected to already have the updated name
|
2016-11-11 02:39:22 +01:00
|
|
|
build_stream_sidebar_row(sub);
|
2013-11-22 20:05:34 +01:00
|
|
|
exports.build_stream_list(); // big hammer
|
2013-10-21 22:26:19 +02:00
|
|
|
};
|
|
|
|
|
2016-10-26 06:56:10 +02:00
|
|
|
exports.refresh_pinned_or_unpinned_stream = function (sub) {
|
|
|
|
// Pinned/unpinned streams require re-ordering.
|
|
|
|
// We use kind of brute force now, which is probably fine.
|
2016-11-11 02:39:22 +01:00
|
|
|
build_stream_sidebar_row(sub);
|
2016-07-01 07:26:09 +02:00
|
|
|
exports.update_streams_sidebar();
|
|
|
|
};
|
|
|
|
|
2017-02-06 22:50:38 +01:00
|
|
|
function deselect_top_left_corner_items() {
|
|
|
|
$("ul.filters li").removeClass('active-filter active-sub-filter');
|
|
|
|
}
|
|
|
|
|
2013-05-06 02:54:15 +02:00
|
|
|
$(function () {
|
2016-10-27 03:47:05 +02:00
|
|
|
// TODO, Eventually topic_list won't be a big singleton,
|
|
|
|
// and we can create more component-based click handlers for
|
|
|
|
// each stream.
|
|
|
|
topic_list.set_click_handlers({
|
|
|
|
zoom_in: zoom_in,
|
2017-01-12 00:17:43 +01:00
|
|
|
zoom_out: zoom_out,
|
2016-10-27 03:47:05 +02:00
|
|
|
});
|
|
|
|
|
2016-11-11 12:33:51 +01:00
|
|
|
pm_list.set_click_handlers();
|
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('narrow_activated.zulip', function (event) {
|
2017-02-06 22:50:38 +01:00
|
|
|
deselect_top_left_corner_items();
|
2016-11-10 18:49:36 +01:00
|
|
|
reset_to_unnarrowed(narrow.stream() === zoomed_stream);
|
2013-05-06 02:54:15 +02:00
|
|
|
|
|
|
|
// TODO: handle confused filters like "in:all stream:foo"
|
|
|
|
var op_in = event.filter.operands('in');
|
|
|
|
if (op_in.length !== 0) {
|
|
|
|
if (['all', 'home'].indexOf(op_in[0]) !== -1) {
|
|
|
|
$("#global_filters li[data-name='" + op_in[0] + "']").addClass('active-filter');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var op_is = event.filter.operands('is');
|
|
|
|
if (op_is.length !== 0) {
|
2015-11-25 18:41:32 +01:00
|
|
|
if (['starred', 'mentioned'].indexOf(op_is[0]) !== -1) {
|
2013-05-06 02:54:15 +02:00
|
|
|
$("#global_filters li[data-name='" + op_is[0] + "']").addClass('active-filter');
|
|
|
|
}
|
|
|
|
}
|
2015-11-25 18:41:32 +01:00
|
|
|
|
|
|
|
var op_pm = event.filter.operands('pm-with');
|
|
|
|
if ((op_is.length !== 0 && _.contains(op_is, "private")) || op_pm.length !== 0) {
|
2016-11-11 12:33:51 +01:00
|
|
|
pm_list.expand(op_pm);
|
2016-12-17 01:14:07 +01:00
|
|
|
} else {
|
|
|
|
pm_list.close();
|
2015-11-25 18:41:32 +01:00
|
|
|
}
|
|
|
|
|
2013-05-06 02:54:15 +02:00
|
|
|
var op_stream = event.filter.operands('stream');
|
2013-08-15 21:11:07 +02:00
|
|
|
if (op_stream.length !== 0 && stream_data.is_subscribed(op_stream[0])) {
|
2013-05-06 22:18:01 +02:00
|
|
|
var stream_li = get_filter_li('stream', op_stream[0]);
|
2013-07-16 22:52:02 +02:00
|
|
|
var op_subject = event.filter.operands('topic');
|
2016-11-10 19:24:20 +01:00
|
|
|
if (op_subject.length === 0) {
|
2013-05-06 02:54:15 +02:00
|
|
|
stream_li.addClass('active-filter');
|
|
|
|
}
|
2016-11-10 19:24:20 +01:00
|
|
|
rebuild_recent_topics(op_stream[0]);
|
2017-03-18 01:41:56 +01:00
|
|
|
unread_ops.process_visible();
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-15 07:26:09 +01:00
|
|
|
$(document).on('narrow_deactivated.zulip', function () {
|
2017-02-06 22:50:38 +01:00
|
|
|
deselect_top_left_corner_items();
|
2015-12-11 08:35:36 +01:00
|
|
|
reset_to_unnarrowed();
|
2016-12-17 01:14:07 +01:00
|
|
|
pm_list.close();
|
2013-05-06 02:54:15 +02:00
|
|
|
$("#global_filters li[data-name='home']").addClass('active-filter');
|
|
|
|
});
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('subscription_add_done.zulip', function (event) {
|
2016-10-17 20:02:32 +02:00
|
|
|
exports.create_sidebar_row(event.sub);
|
2013-11-22 20:05:34 +01:00
|
|
|
exports.build_stream_list();
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('subscription_remove_done.zulip', function (event) {
|
2017-02-17 18:45:14 +01:00
|
|
|
exports.remove_sidebar_row(event.sub.stream_id);
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
2013-11-22 22:25:31 +01:00
|
|
|
|
2017-02-17 18:45:14 +01:00
|
|
|
|
2013-11-22 22:25:31 +01:00
|
|
|
$('#stream_filters').on('click', 'li .subscription_block', function (e) {
|
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-18 21:11:12 +01:00
|
|
|
if (ui_state.home_tab_obscured()) {
|
2013-11-22 22:25:31 +01:00
|
|
|
ui.change_tab_to('#home');
|
|
|
|
}
|
|
|
|
var stream = $(e.target).parents('li').attr('data-name');
|
2016-12-19 23:38:19 +01:00
|
|
|
popovers.hide_all();
|
2013-11-22 22:25:31 +01:00
|
|
|
narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar'});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
|
|
|
|
2016-06-13 22:06:12 +02:00
|
|
|
function actually_update_streams_for_search() {
|
|
|
|
exports.update_streams_sidebar();
|
|
|
|
resize.resize_page_components();
|
|
|
|
}
|
|
|
|
|
|
|
|
var update_streams_for_search = _.throttle(actually_update_streams_for_search, 50);
|
|
|
|
|
|
|
|
exports.searching = function () {
|
|
|
|
return $('.stream-list-filter').expectOne().is(':focus');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.escape_search = function () {
|
|
|
|
var filter = $('.stream-list-filter').expectOne();
|
|
|
|
if (filter.val() === '') {
|
|
|
|
exports.clear_and_hide_search();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
filter.val('');
|
|
|
|
update_streams_for_search();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.initiate_search = function () {
|
|
|
|
var filter = $('.stream-list-filter').expectOne();
|
|
|
|
filter.removeClass('notdisplayed');
|
|
|
|
filter.focus();
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.clear_and_hide_search = function () {
|
|
|
|
var filter = $('.stream-list-filter');
|
|
|
|
if (filter.val() !== '') {
|
|
|
|
filter.val('');
|
|
|
|
update_streams_for_search();
|
|
|
|
}
|
|
|
|
filter.blur();
|
|
|
|
filter.addClass('notdisplayed');
|
|
|
|
};
|
|
|
|
|
2016-12-05 07:02:18 +01:00
|
|
|
function focus_stream_filter(e) {
|
2016-06-13 22:06:12 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2016-12-05 07:02:18 +01:00
|
|
|
function maybe_select_stream(e) {
|
2016-06-13 22:06:12 +02:00
|
|
|
if (e.keyCode === 13) {
|
|
|
|
// Enter key was pressed
|
|
|
|
|
|
|
|
var topStream = $('#stream_filters li.narrow-filter').first().data('name');
|
|
|
|
if (topStream !== undefined) {
|
|
|
|
// undefined if there are no results
|
2017-03-18 21:11:12 +01:00
|
|
|
if (ui_state.home_tab_obscured()) {
|
2016-06-13 22:06:12 +02:00
|
|
|
ui.change_tab_to('#home');
|
|
|
|
}
|
|
|
|
exports.clear_and_hide_search();
|
|
|
|
narrow.by('stream', topStream, {select_first_unread: true, trigger: 'sidebar enter key'});
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_filter_displayed(e) {
|
|
|
|
if (e.target.id === 'streams_inline_cog') {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-05 03:39:24 +01:00
|
|
|
if ($('.stream-list-filter.notdisplayed').length === 0) {
|
2016-06-13 22:06:12 +02:00
|
|
|
exports.clear_and_hide_search();
|
|
|
|
} else {
|
|
|
|
exports.initiate_search();
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
$(".stream-list-filter").expectOne()
|
|
|
|
.on('click', focus_stream_filter)
|
|
|
|
.on('input', update_streams_for_search)
|
|
|
|
.on('keydown', maybe_select_stream);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
$("#streams_header").expectOne()
|
|
|
|
.on('click', toggle_filter_displayed);
|
|
|
|
});
|
|
|
|
|
2013-05-06 02:54:15 +02:00
|
|
|
return exports;
|
|
|
|
}());
|
2013-11-26 16:39:58 +01:00
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = stream_list;
|
|
|
|
}
|