diff --git a/zephyr/static/js/message_list.js b/zephyr/static/js/message_list.js index c4c1adee02..cd437ed1ce 100644 --- a/zephyr/static/js/message_list.js +++ b/zephyr/static/js/message_list.js @@ -1,5 +1,6 @@ /*jslint nomen: true */ -function MessageList(table_name) { +function MessageList(table_name, opts) { + $.extend(this, {collapse_messages: true}, opts); this._items = []; this._hash = {}; this.table_name = table_name; @@ -147,7 +148,7 @@ MessageList.prototype = { }); }, - _render: function MessageList__render(messages, where, allow_collapse) { + _render: function MessageList__render(messages, where) { if (messages.length === 0) return; @@ -162,7 +163,7 @@ MessageList.prototype = { var current_group = []; var new_message_groups = []; - if (where === 'top' && narrow.allow_collapse() && this._message_groups.length > 0) { + 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. // @@ -188,7 +189,7 @@ MessageList.prototype = { $.each(messages, function (index, message) { message.include_recipient = false; message.include_bookend = false; - if (util.same_recipient(prev, message) && allow_collapse) { + if (util.same_recipient(prev, message) && self.collapse_messages) { current_group.push(message.id); } else { if (current_group.length > 0) @@ -293,19 +294,19 @@ MessageList.prototype = { } }, - append: function MessageList_append(messages, allow_collapse) { + append: function MessageList_append(messages) { this._items = this._items.concat(messages); this._add_to_hash(messages); if (this.table_name) { - this._render(messages, 'bottom', allow_collapse); + this._render(messages, 'bottom'); } }, - prepend: function MessageList_prepend(messages, allow_collapse) { + prepend: function MessageList_prepend(messages) { this._items = messages.concat(this._items); this._add_to_hash(messages); if (this.table_name) { - this._render(messages, 'top', allow_collapse); + this._render(messages, 'top'); } }, diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index dd3c51de92..761ee59b73 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -37,12 +37,6 @@ exports.public_operators = function () { } }; -var allow_collapse; - -exports.allow_collapse = function () { - return (!filter_function) || allow_collapse; -}; - /* Convert a list of operators to a string. Each operator is a key-value pair like @@ -259,7 +253,6 @@ function build_filter(operators_mixed_case) { exports.activate = function (operators, opts) { opts = $.extend({}, { - allow_collapse: true, then_select_id: home_msg_list.selected_id() }, opts); @@ -272,8 +265,6 @@ exports.activate = function (operators, opts) { filter_function = build_filter(operators); current_operators = operators; - allow_collapse = opts.allow_collapse; - narrowed_msg_list = new MessageList('zfilt'); current_msg_list = narrowed_msg_list; diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index a5ef806e87..bfede640a5 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -318,7 +318,7 @@ function add_message_metadata(message, dummy) { return message; } -function add_messages_helper(messages, msg_list, predicate, allow_collapse) { +function add_messages_helper(messages, msg_list, predicate) { var top_messages = []; var bottom_messages = []; @@ -345,8 +345,8 @@ function add_messages_helper(messages, msg_list, predicate, allow_collapse) { }); } - msg_list.prepend(top_messages, allow_collapse); - msg_list.append(bottom_messages, allow_collapse); + msg_list.prepend(top_messages); + msg_list.append(bottom_messages); return top_messages.length > 0; } @@ -361,21 +361,18 @@ function add_messages(messages, msg_list, opts) { util.destroy_first_run_message(); messages = $.map(messages, add_message_metadata); - var predicate, allow_collapse; + var predicate; if (msg_list === home_msg_list) { predicate = narrow.message_in_home; - allow_collapse = true; } else if (msg_list === narrowed_msg_list) { predicate = narrow.predicate(); - allow_collapse = narrow.allow_collapse(); } else if (msg_list === all_msg_list) { predicate = function () { return true; }; - allow_collapse = true; } else { throw (new Error("Adding message to a list that is not known")); } - if (add_messages_helper(messages, msg_list, predicate, allow_collapse)) { + if (add_messages_helper(messages, msg_list, predicate)) { prepended = true; }