From 82da2bec107641998806b1855998c7e17f3546e4 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 10 Apr 2013 17:38:30 -0400 Subject: [PATCH] Add trailing bookend with current subscribed status in some narrows. This is basically just the logical extension of the previous commit for the case where the last thing we did was subscribe or unsubscribe. This even magically updates when you subscribe or unsubscribe from another window :). (imported from commit 2399329d11bf66aa0b614a21d2b3cf4035452279) --- zephyr/static/js/message_list.js | 46 +++++++++++++++++++ zephyr/static/js/narrow.js | 10 ++++ zephyr/static/js/subs.js | 9 ++++ zephyr/static/templates/message.handlebars | 8 ++++ .../templates/trailing_bookend.handlebars | 9 ++++ 5 files changed, 82 insertions(+) create mode 100644 zephyr/static/templates/trailing_bookend.handlebars diff --git a/zephyr/static/js/message_list.js b/zephyr/static/js/message_list.js index 461d4c2898..49b5620f79 100644 --- a/zephyr/static/js/message_list.js +++ b/zephyr/static/js/message_list.js @@ -76,6 +76,7 @@ MessageList.prototype = { _clear_rendering_state: function MessageList__clear_rendering_state() { this._message_groups = []; this._clear_table(); + this.last_message_historical = false; }, clear: function MessageList_clear(opts) { @@ -245,6 +246,11 @@ MessageList.prototype = { var current_group = []; var new_message_groups = []; + if (where === "bottom") { + // Remove the trailing bookend; it'll be re-added after we do our rendering + this.clear_trailing_bookend(); + } + if (where === 'top' && this.collapse_messages && this._message_groups.length > 0) { // Delete the current top message group, and add it back in with these // messages, in order to collapse properly. @@ -319,6 +325,7 @@ MessageList.prototype = { messages_to_render.push(message); prev = message; + self.last_message_historical = message.historical; }); if (messages_to_render.length === 0) { @@ -371,6 +378,8 @@ MessageList.prototype = { } else { table.append(rendered_elems); + this.update_trailing_bookend(); + // XXX: This is absolutely awful. There is a firefox bug // where when table rows as DOM elements are appended (as // opposed to as a string) a border is sometimes added to the @@ -430,6 +439,43 @@ MessageList.prototype = { } }, + clear_trailing_bookend: function MessageList_clear_trailing_bookend() { + var trailing_bookend = rows.get_table(this.table_name).find('#trailing_bookend'); + trailing_bookend.remove(); + }, + + // Maintains a trailing bookend element explaining any changes in + // your subscribed/unsubscribed status at the bottom of the + // message list. + update_trailing_bookend: function MessageList_update_trailing_bookend() { + this.clear_trailing_bookend(); + if (!this.narrowed) { + return; + } + var stream = narrow.stream(); + if (stream === undefined) { + return; + } + var trailing_bookend_content, subscribed = subs.have(stream); + if (subscribed) { + if (this.last_message_historical) { + trailing_bookend_content = "--- Subscribed to stream " + stream + " ---"; + } + } else { + if (!this.last_message_historical) { + trailing_bookend_content = "--- Unsubscribed from stream " + stream + " ---"; + } else { + trailing_bookend_content = "--- Not subscribed to stream " + stream + " ---"; + } + } + if (trailing_bookend_content !== undefined) { + var rendered_trailing_bookend = $(templates.render('trailing_bookend', { + trailing_bookend: trailing_bookend_content + })); + rows.get_table(this.table_name).append(rendered_trailing_bookend); + } + }, + append: function MessageList_append(messages) { this._items = this._items.concat(messages); this._add_to_hash(messages); diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index f2c8f63c69..b3c7ec6a7c 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -276,6 +276,16 @@ function build_filter(operators_mixed_case) { }; } +exports.stream = function () { + var j; + for (j = 0; j < current_operators.length; j++) { + if (current_operators[j][0] === "stream") { + return current_operators[j][1]; + } + } + return undefined; +}; + exports.activate = function (operators, opts) { opts = $.extend({}, { then_select_id: home_msg_list.selected_id(), diff --git a/zephyr/static/js/subs.js b/zephyr/static/js/subs.js index ba1f99d26f..02be006f02 100644 --- a/zephyr/static/js/subs.js +++ b/zephyr/static/js/subs.js @@ -301,6 +301,10 @@ function mark_subscribed(stream_name, attrs) { return; } + if (current_msg_list.narrowed) { + current_msg_list.update_trailing_bookend(); + } + // Update unread counts as the new stream in sidebar might // need its unread counts re-calculated process_loaded_for_unread(all_msg_list.all()); @@ -338,6 +342,11 @@ function mark_unsubscribed(stream_name) { // Already unsubscribed return; } + + if (current_msg_list.narrowed) { + current_msg_list.update_trailing_bookend(); + } + typeahead_helper.update_autocomplete(); } diff --git a/zephyr/static/templates/message.handlebars b/zephyr/static/templates/message.handlebars index ff1dc3aa1d..ebf7e9cdff 100644 --- a/zephyr/static/templates/message.handlebars +++ b/zephyr/static/templates/message.handlebars @@ -88,3 +88,11 @@ {{/with}} {{/each}} + +{{#if trailing_bookend}} + + +
{{trailing_bookend}}
+

+ +{{/if}} diff --git a/zephyr/static/templates/trailing_bookend.handlebars b/zephyr/static/templates/trailing_bookend.handlebars new file mode 100644 index 0000000000..23b34cf7c5 --- /dev/null +++ b/zephyr/static/templates/trailing_bookend.handlebars @@ -0,0 +1,9 @@ +{{! Client-side Mustache template for rendering the trailing bookend.}} + +{{#if trailing_bookend}} + + +
{{trailing_bookend}}
+

+ +{{/if}}