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)
This commit is contained in:
Tim Abbott 2013-04-10 17:38:30 -04:00
parent bad18f6971
commit 82da2bec10
5 changed files with 82 additions and 0 deletions

View File

@ -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);

View File

@ -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(),

View File

@ -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();
}

View File

@ -88,3 +88,11 @@
</tr>
{{/with}}
{{/each}}
{{#if trailing_bookend}}
<tr id="trailing_bookend" class="bookend_tr"><td/>
<td /><td class="bookend">
<center>{{trailing_bookend}}</center>
<span class="tiny"><p></p></span></td>
</tr>
{{/if}}

View File

@ -0,0 +1,9 @@
{{! Client-side Mustache template for rendering the trailing bookend.}}
{{#if trailing_bookend}}
<tr id="trailing_bookend" class="bookend_tr"><td/>
<td /><td class="bookend">
<center>{{trailing_bookend}}</center>
<span class="tiny"><p></p></span></td>
</tr>
{{/if}}