2013-05-06 02:54:15 +02:00
|
|
|
var stream_list = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-11-22 21:04:49 +01:00
|
|
|
var zoomed_to_topics = false;
|
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-16 23:40:07 +02:00
|
|
|
var last_private_message_count = 0;
|
2013-05-31 19:07:59 +02:00
|
|
|
var last_mention_count = 0;
|
2013-05-07 19:07:05 +02:00
|
|
|
var previous_sort_order;
|
2013-05-16 23:40:07 +02:00
|
|
|
|
2013-11-22 21:04:49 +01:00
|
|
|
function active_stream_name() {
|
|
|
|
if (narrow.active()) {
|
|
|
|
var op_streams = narrow.filter().operands('stream');
|
|
|
|
if (op_streams) {
|
|
|
|
return op_streams[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:05:34 +01:00
|
|
|
exports.build_stream_list = function () {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
var sort_recent = (streams.length > 40);
|
|
|
|
|
2013-07-05 17:43:56 +02:00
|
|
|
streams.sort(function (a, b) {
|
2013-05-06 02:54:15 +02:00
|
|
|
if (sort_recent) {
|
2013-08-07 23:56:51 +02:00
|
|
|
if (recent_subjects.has(b) && ! recent_subjects.has(a)) {
|
2013-05-06 02:54:15 +02:00
|
|
|
return 1;
|
2013-08-07 23:56:51 +02:00
|
|
|
} else if (! recent_subjects.has(b) && recent_subjects.has(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
|
|
|
});
|
|
|
|
|
2013-05-07 19:07:05 +02:00
|
|
|
if (previous_sort_order !== undefined
|
|
|
|
&& util.array_compare(previous_sort_order, streams)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
previous_sort_order = streams;
|
|
|
|
|
2013-05-06 23:36:22 +02:00
|
|
|
var parent = $('#stream_filters');
|
2013-05-06 02:54:15 +02:00
|
|
|
parent.empty();
|
|
|
|
|
2013-05-06 23:36:22 +02:00
|
|
|
var elems = [];
|
2013-07-30 00:35:44 +02:00
|
|
|
_.each(streams, function (stream) {
|
2013-08-15 21:11:07 +02:00
|
|
|
var li = $(stream_data.get_sub(stream).sidebar_li);
|
2013-05-06 02:54:15 +02:00
|
|
|
if (sort_recent) {
|
2013-08-07 23:56:51 +02:00
|
|
|
if (! recent_subjects.has(stream)) {
|
2013-05-06 23:36:22 +02:00
|
|
|
li.addClass('inactive_stream');
|
2013-05-06 02:54:15 +02:00
|
|
|
} else {
|
2013-05-06 23:36:22 +02:00
|
|
|
li.removeClass('inactive_stream');
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
}
|
2013-05-06 23:36:22 +02:00
|
|
|
elems.push(li.get(0));
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
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-06-05 20:29:31 +02:00
|
|
|
// TODO: Now that the unread count functions support the user sidebar
|
|
|
|
// as well, we probably should consider moving them to a different file.
|
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-06-05 20:29:31 +02:00
|
|
|
} else if (type === "private") {
|
2013-10-18 00:56:49 +02:00
|
|
|
if (name.indexOf(",") < 0) {
|
|
|
|
return $("li.user_sidebar_entry[data-email='" + name + "']");
|
|
|
|
} else {
|
|
|
|
return $("li.group-pms-sidebar-entry[data-emails='" + name + "']");
|
|
|
|
}
|
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();
|
|
|
|
zoomed_to_topics = true;
|
2015-12-11 08:24:00 +01:00
|
|
|
$("#streams_list").expectOne().removeClass("zoom-out").addClass("zoom-in");
|
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
|
|
|
zoomed_stream = active_stream_name();
|
|
|
|
|
|
|
|
$("#stream_filters li.narrow-filter").each(function () {
|
|
|
|
var elt = $(this);
|
|
|
|
|
|
|
|
if (elt.attr('data-name') === zoomed_stream) {
|
|
|
|
elt.show();
|
|
|
|
} else {
|
|
|
|
elt.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function zoom_out() {
|
|
|
|
popovers.hide_all();
|
|
|
|
zoomed_to_topics = false;
|
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:11 +01:00
|
|
|
function remove_expanded_subjects() {
|
|
|
|
popovers.hide_topic_sidebar_popover();
|
|
|
|
$("ul.expanded_subjects").remove();
|
|
|
|
}
|
|
|
|
|
2015-12-11 08:35:36 +01:00
|
|
|
function reset_to_unnarrowed(narrowed_within_same_stream) {
|
|
|
|
if (zoomed_to_topics && narrowed_within_same_stream !== true) {
|
|
|
|
zoom_out();
|
|
|
|
}
|
|
|
|
|
|
|
|
$("ul.filters li").removeClass('active-filter active-subject-filter');
|
|
|
|
remove_expanded_subjects();
|
|
|
|
}
|
|
|
|
|
2013-05-06 22:18:01 +02:00
|
|
|
function get_subject_filter_li(stream, subject) {
|
|
|
|
var stream_li = get_filter_li('stream', 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
|
|
|
return iterate_to_find(".expanded_subjects li.expanded_subject", subject, stream_li);
|
2013-05-06 22:18:01 +02:00
|
|
|
}
|
2013-05-06 02:54:15 +02: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");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-16 23:14:55 +01:00
|
|
|
function build_stream_sidebar_row(name) {
|
2014-02-07 16:55:54 +01:00
|
|
|
var sub = stream_data.get_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,
|
2013-08-27 21:05:32 +02:00
|
|
|
color: stream_data.get_color(name)
|
|
|
|
};
|
|
|
|
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));
|
2014-01-16 23:09:46 +01:00
|
|
|
$("#stream_filters").append(list_item);
|
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
|
|
|
|
2014-01-16 22:59:30 +01:00
|
|
|
exports.add_stream_to_sidebar = function (stream_name) {
|
|
|
|
if (exports.get_stream_li(stream_name).length) {
|
2013-10-21 22:26:19 +02:00
|
|
|
// already exists
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-16 23:14:55 +01:00
|
|
|
return build_stream_sidebar_row(stream_name);
|
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,
|
|
|
|
dark_background: dark_background
|
|
|
|
};
|
|
|
|
|
2014-02-18 19:47:37 +01:00
|
|
|
if (sub.invite_only) {
|
|
|
|
swatch.addClass("private-stream-swatch");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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-05-06 02:54:15 +02:00
|
|
|
exports.get_count = function (type, name) {
|
2013-05-06 22:18:01 +02:00
|
|
|
return get_filter_li(type, name).find('.count .value').text();
|
2013-05-06 02:54:15 +02:00
|
|
|
};
|
|
|
|
|
2013-05-16 22:38:09 +02:00
|
|
|
function update_count_in_dom(count_span, value_span, count) {
|
2013-05-07 20:02:24 +02:00
|
|
|
if (count === 0) {
|
2013-05-16 22:38:09 +02:00
|
|
|
count_span.hide();
|
2013-09-06 07:39:40 +02:00
|
|
|
if (count_span.parent().hasClass("subscription_block")) {
|
|
|
|
count_span.parent(".subscription_block").removeClass("stream-with-count");
|
|
|
|
}
|
|
|
|
else if (count_span.parent().hasClass("user_sidebar_entry")) {
|
|
|
|
count_span.parent(".user_sidebar_entry").removeClass("user-with-count");
|
|
|
|
}
|
2013-10-18 00:56:49 +02:00
|
|
|
else if (count_span.parent().hasClass("group-pms-sidebar-entry")) {
|
|
|
|
count_span.parent(".group-pms-sidebar-entry").removeClass("group-with-count");
|
|
|
|
}
|
2013-05-16 22:38:09 +02:00
|
|
|
value_span.text('');
|
|
|
|
return;
|
2013-05-07 20:02:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
count_span.show();
|
2013-09-06 07:39:40 +02:00
|
|
|
|
|
|
|
if (count_span.parent().hasClass("subscription_block")) {
|
|
|
|
count_span.parent(".subscription_block").addClass("stream-with-count");
|
|
|
|
}
|
|
|
|
else if (count_span.parent().hasClass("user_sidebar_entry")) {
|
|
|
|
count_span.parent(".user_sidebar_entry").addClass("user-with-count");
|
|
|
|
}
|
2013-10-18 00:56:49 +02:00
|
|
|
else if (count_span.parent().hasClass("group-pms-sidebar-entry")) {
|
|
|
|
count_span.parent(".group-pms-sidebar-entry").addClass("group-with-count");
|
|
|
|
}
|
2013-05-07 20:02:24 +02:00
|
|
|
value_span.text(count);
|
|
|
|
}
|
|
|
|
|
2013-08-22 21:05:18 +02:00
|
|
|
function set_count(type, name, count) {
|
2013-05-06 22:18:01 +02:00
|
|
|
var count_span = get_filter_li(type, name).find('.count');
|
2013-05-06 02:54:15 +02:00
|
|
|
var value_span = count_span.find('.value');
|
2013-05-16 22:38:09 +02:00
|
|
|
update_count_in_dom(count_span, value_span, count);
|
2013-08-22 21:05:18 +02:00
|
|
|
}
|
2013-05-07 20:02:24 +02:00
|
|
|
|
2013-09-03 17:40:34 +02:00
|
|
|
function set_count_toggle_button(elem, count) {
|
|
|
|
if (count === 0) {
|
|
|
|
if (elem.is(':animated')) {
|
|
|
|
return elem.stop(true, true).hide();
|
|
|
|
}
|
|
|
|
return elem.hide(500);
|
|
|
|
} else if ((count > 0) && (count < 1000)) {
|
|
|
|
elem.show(500);
|
|
|
|
return elem.text(count);
|
|
|
|
} else {
|
|
|
|
elem.show(500);
|
|
|
|
return elem.text("1k+");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 20:02:24 +02:00
|
|
|
exports.set_subject_count = function (stream, subject, count) {
|
2013-06-07 16:56:05 +02:00
|
|
|
var subject_li = get_subject_filter_li(stream, subject);
|
|
|
|
var count_span = subject_li.find('.subject_count');
|
2013-05-07 20:02:24 +02:00
|
|
|
var value_span = count_span.find('.value');
|
|
|
|
|
|
|
|
if (count_span.length === 0 || value_span.length === 0) {
|
|
|
|
return;
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
|
2013-06-07 02:46:01 +02:00
|
|
|
count_span.removeClass("zero_count");
|
2013-05-16 22:38:09 +02:00
|
|
|
update_count_in_dom(count_span, value_span, count);
|
2013-05-06 02:54:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.remove_narrow_filter = function (name, type) {
|
2013-05-06 22:18:01 +02:00
|
|
|
get_filter_li(type, name).remove();
|
2013-05-06 02:54:15 +02:00
|
|
|
};
|
|
|
|
|
2013-11-26 16:39:58 +01:00
|
|
|
exports._build_subject_list = function (stream, active_topic, max_subjects) {
|
2013-08-07 23:56:51 +02:00
|
|
|
var subjects = recent_subjects.get(stream) || [];
|
2013-05-22 18:06:40 +02:00
|
|
|
|
2013-09-30 19:14:56 +02:00
|
|
|
if (active_topic) {
|
|
|
|
active_topic = active_topic.toLowerCase();
|
|
|
|
}
|
|
|
|
|
2013-09-30 17:27:32 +02:00
|
|
|
var display_subjects = [];
|
2013-11-25 19:48:08 +01:00
|
|
|
var hiding_topics = false;
|
2013-09-30 17:27:32 +02:00
|
|
|
|
|
|
|
_.each(subjects, function (subject_obj, idx) {
|
2013-09-30 19:03:30 +02:00
|
|
|
var topic_name = subject_obj.subject;
|
2013-09-30 17:27:32 +02:00
|
|
|
var num_unread = unread.num_unread_for_subject(stream, subject_obj.canon_subject);
|
2013-05-06 02:54:15 +02:00
|
|
|
|
2013-06-27 16:26:33 +02:00
|
|
|
// Show the most recent subjects, as well as any with unread messages
|
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 always_visible = (idx < max_subjects) || (num_unread > 0) || (active_topic === topic_name);
|
|
|
|
|
|
|
|
if (!always_visible) {
|
2013-11-25 19:48:08 +01:00
|
|
|
hiding_topics = true;
|
|
|
|
}
|
2013-05-17 21:32:26 +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
|
|
|
var display_subject = {
|
|
|
|
topic_name: topic_name,
|
|
|
|
unread: num_unread,
|
|
|
|
is_zero: num_unread === 0,
|
|
|
|
is_muted: muting.is_topic_muted(stream, topic_name),
|
|
|
|
zoom_out_hide: !always_visible,
|
|
|
|
url: narrow.by_stream_subject_uri(stream, topic_name)
|
|
|
|
};
|
|
|
|
display_subjects.push(display_subject);
|
|
|
|
});
|
2013-11-25 19:48:08 +01:00
|
|
|
|
2013-11-22 18:50:10 +01:00
|
|
|
var topic_dom = templates.render('sidebar_subject_list',
|
2013-06-27 16:26:33 +02:00
|
|
|
{subjects: display_subjects,
|
2013-12-26 22:07:55 +01:00
|
|
|
want_show_more_topics_links: hiding_topics,
|
2013-11-22 18:50:10 +01:00
|
|
|
stream: stream});
|
|
|
|
|
|
|
|
return topic_dom;
|
2013-11-26 16:39:58 +01:00
|
|
|
};
|
2013-11-22 18:50:10 +01:00
|
|
|
|
|
|
|
function rebuild_recent_subjects(stream, active_topic) {
|
|
|
|
// TODO: Call rebuild_recent_subjects less, not on every new
|
|
|
|
// message.
|
|
|
|
remove_expanded_subjects();
|
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 max_subjects = 5;
|
2013-11-22 18:50:10 +01:00
|
|
|
var stream_li = get_filter_li('stream', stream);
|
|
|
|
|
2013-11-26 16:39:58 +01:00
|
|
|
var topic_dom = exports._build_subject_list(stream, active_topic, max_subjects);
|
2013-11-22 18:50:10 +01:00
|
|
|
stream_li.append(topic_dom);
|
2013-06-07 02:46:01 +02:00
|
|
|
|
2013-09-30 17:41:08 +02:00
|
|
|
if (active_topic) {
|
|
|
|
get_subject_filter_li(stream, active_topic).addClass('active-subject-filter');
|
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');
|
2013-07-16 22:52:02 +02:00
|
|
|
var op_subject = narrow.filter().operands('topic');
|
2013-05-06 02:54:15 +02:00
|
|
|
var subject;
|
|
|
|
if (op_stream.length !== 0) {
|
|
|
|
if (op_subject.length !== 0) {
|
|
|
|
subject = op_subject[0];
|
|
|
|
}
|
2013-08-15 21:11:07 +02:00
|
|
|
if (stream_data.is_subscribed(op_stream[0])) {
|
2013-05-06 02:54:15 +02:00
|
|
|
rebuild_recent_subjects(op_stream[0], subject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-31 19:07:59 +02:00
|
|
|
function do_new_messages_animation(message_type) {
|
|
|
|
var li = get_filter_li("global", message_type);
|
|
|
|
li.addClass("new_messages");
|
2013-05-16 23:40:07 +02:00
|
|
|
function mid_animation() {
|
2013-05-31 19:07:59 +02:00
|
|
|
li.removeClass("new_messages");
|
|
|
|
li.addClass("new_messages_fadeout");
|
2013-05-16 23:40:07 +02:00
|
|
|
}
|
|
|
|
function end_animation() {
|
2013-05-31 19:07:59 +02:00
|
|
|
li.removeClass("new_messages_fadeout");
|
2013-05-16 23:40:07 +02:00
|
|
|
}
|
|
|
|
setTimeout(mid_animation, 3000);
|
|
|
|
setTimeout(end_animation, 6000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function animate_private_message_changes(new_private_message_count) {
|
|
|
|
if (new_private_message_count > last_private_message_count) {
|
2013-07-10 03:22:34 +02:00
|
|
|
do_new_messages_animation('private');
|
2013-05-16 23:40:07 +02:00
|
|
|
}
|
|
|
|
last_private_message_count = new_private_message_count;
|
|
|
|
}
|
|
|
|
|
2013-05-31 19:07:59 +02:00
|
|
|
function animate_mention_changes(new_mention_count) {
|
|
|
|
if (new_mention_count > last_mention_count) {
|
2013-07-10 03:07:01 +02:00
|
|
|
do_new_messages_animation('mentioned');
|
2013-05-31 19:07:59 +02:00
|
|
|
}
|
|
|
|
last_mention_count = new_mention_count;
|
|
|
|
}
|
|
|
|
|
2013-08-22 19:06:04 +02:00
|
|
|
|
2013-08-22 21:28:34 +02:00
|
|
|
exports.set_presence_list_count = function (person, count) {
|
|
|
|
set_count("private", person, count);
|
2013-08-22 19:06:04 +02:00
|
|
|
};
|
|
|
|
|
2013-05-14 03:58:07 +02:00
|
|
|
exports.update_dom_with_unread_counts = function (counts) {
|
|
|
|
// counts is just a data object that gets calculated elsewhere
|
|
|
|
// Our job is to update some DOM elements.
|
|
|
|
|
|
|
|
// 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
|
|
|
});
|
|
|
|
|
|
|
|
// counts.subject_count maps streams to hashes of subjects to counts
|
2013-08-15 16:16:12 +02:00
|
|
|
counts.subject_count.each(function (subject_hash, stream) {
|
|
|
|
subject_hash.each(function (count, subject) {
|
2013-05-14 03:58:07 +02:00
|
|
|
exports.set_subject_count(stream, subject, count);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-22 21:28:34 +02:00
|
|
|
|
|
|
|
counts.pm_count.each(function (count, person) {
|
|
|
|
exports.set_presence_list_count(person, count);
|
|
|
|
});
|
2013-06-05 20:29:31 +02:00
|
|
|
|
2013-05-14 03:58:07 +02:00
|
|
|
// integer counts
|
2013-08-22 21:05:18 +02:00
|
|
|
set_count("global", "private", counts.private_message_count);
|
|
|
|
set_count("global", "mentioned", counts.mentioned_message_count);
|
|
|
|
set_count("global", "home", counts.home_unread_messages);
|
2013-05-16 23:40:07 +02:00
|
|
|
|
2013-09-03 17:40:34 +02:00
|
|
|
set_count_toggle_button($("#streamlist-toggle-unreadcount"), counts.home_unread_messages);
|
|
|
|
set_count_toggle_button($("#userlist-toggle-unreadcount"), counts.private_message_count);
|
|
|
|
|
2013-05-16 23:40:07 +02:00
|
|
|
animate_private_message_changes(counts.private_message_count);
|
2013-05-31 19:07:59 +02:00
|
|
|
animate_mention_changes(counts.mentioned_message_count);
|
2013-05-14 03:58:07 +02:00
|
|
|
};
|
|
|
|
|
2013-10-21 22:26:19 +02:00
|
|
|
exports.rename_stream = function (sub) {
|
2014-01-16 23:14:55 +01:00
|
|
|
sub.sidebar_li = build_stream_sidebar_row(sub.name);
|
2013-11-22 20:05:34 +01:00
|
|
|
exports.build_stream_list(); // big hammer
|
2013-10-21 22:26:19 +02:00
|
|
|
};
|
|
|
|
|
2013-05-06 02:54:15 +02:00
|
|
|
$(function () {
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('narrow_activated.zulip', function (event) {
|
2015-12-11 08:35:36 +01:00
|
|
|
reset_to_unnarrowed(active_stream_name() === 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) {
|
2013-07-10 03:22:34 +02:00
|
|
|
if (['private', '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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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');
|
2013-05-06 02:54:15 +02:00
|
|
|
var subject;
|
|
|
|
if (op_subject.length !== 0) {
|
|
|
|
subject = op_subject[0];
|
|
|
|
} else {
|
|
|
|
stream_li.addClass('active-filter');
|
|
|
|
}
|
|
|
|
rebuild_recent_subjects(op_stream[0], subject);
|
2014-01-31 17:44:21 +01:00
|
|
|
unread.process_visible();
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
2013-08-12 23:05:20 +02:00
|
|
|
var op_pm = event.filter.operands('pm-with');
|
|
|
|
if (op_pm.length === 1) {
|
|
|
|
$("#user_presences li[data-email='" + op_pm[0] + "']").addClass('active-filter');
|
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('narrow_deactivated.zulip', function (event) {
|
2015-12-11 08:35:36 +01:00
|
|
|
reset_to_unnarrowed();
|
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('sub_obj_created.zulip', function (event) {
|
2013-05-06 02:54:15 +02:00
|
|
|
if (event.sub.subscribed) {
|
|
|
|
var stream_name = event.sub.name;
|
2014-01-16 22:59:30 +01:00
|
|
|
var li = exports.add_stream_to_sidebar(stream_name);
|
2013-05-06 23:36:22 +02:00
|
|
|
if (li) {
|
|
|
|
event.sub.sidebar_li = li;
|
|
|
|
}
|
2013-05-06 02:54:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-25 22:48:55 +02:00
|
|
|
$(document).on('subscription_add_done.zulip', function (event) {
|
2013-05-06 02:54:15 +02:00
|
|
|
var stream_name = event.sub.name;
|
2014-01-16 22:59:30 +01:00
|
|
|
var li = exports.add_stream_to_sidebar(stream_name);
|
2013-05-06 23:36:22 +02:00
|
|
|
if (li) {
|
|
|
|
event.sub.sidebar_li = li;
|
|
|
|
}
|
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) {
|
2013-05-06 02:54:15 +02:00
|
|
|
var stream_name = event.sub.name;
|
|
|
|
exports.remove_narrow_filter(stream_name, 'stream');
|
2013-05-13 17:23:07 +02:00
|
|
|
// We need to make sure we resort if the removed sub gets added again
|
|
|
|
previous_sort_order = undefined;
|
2013-05-06 02:54:15 +02:00
|
|
|
});
|
2013-11-22 22:25:31 +01:00
|
|
|
|
2013-11-25 17:05:42 +01:00
|
|
|
$('.show-all-streams').on('click', function (e) {
|
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
|
|
|
zoom_out();
|
2013-11-25 17:05:42 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-11-25 19:48:08 +01:00
|
|
|
$('#stream_filters').on('click', '.show-more-topics', function (e) {
|
|
|
|
var stream = $(e.target).parents('.show-more-topics').attr('data-name');
|
|
|
|
|
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
|
|
|
zoom_in();
|
2013-11-25 19:48:08 +01:00
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2013-11-22 22:25:31 +01:00
|
|
|
$('#stream_filters').on('click', 'li .subscription_block', function (e) {
|
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ui.home_tab_obscured()) {
|
|
|
|
ui.change_tab_to('#home');
|
|
|
|
}
|
|
|
|
var stream = $(e.target).parents('li').attr('data-name');
|
2013-11-22 21:04:49 +01:00
|
|
|
|
2013-11-22 22:25:31 +01:00
|
|
|
narrow.by('stream', stream, {select_first_unread: true, trigger: 'sidebar'});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#stream_filters').on('click', '.subject_box', function (e) {
|
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ui.home_tab_obscured()) {
|
|
|
|
ui.change_tab_to('#home');
|
|
|
|
}
|
|
|
|
|
|
|
|
var stream = $(e.target).parents('ul').attr('data-stream');
|
|
|
|
var subject = $(e.target).parents('li').attr('data-name');
|
|
|
|
|
2014-02-10 20:53:38 +01:00
|
|
|
narrow.activate([{operator: 'stream', operand: stream},
|
|
|
|
{operator: 'topic', operand: subject}],
|
2013-11-22 22:25:31 +01:00
|
|
|
{select_first_unread: true, trigger: 'sidebar'});
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
}
|