diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index 85c9243b00bf33..e95fecfd507f4d 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -18,6 +18,7 @@ set_global('$', function () { }); set_global('feature_flags', {}); +set_global('Filter', function() {}); var MessageList = require('js/message_list').MessageList; diff --git a/static/js/echo.js b/static/js/echo.js index 2bc66e6ba92e60..312f12891a1a98 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -118,8 +118,8 @@ exports._add_message_flags = add_message_flags; function get_next_local_id() { var local_id_increment = 0.01; var latest = page_params.max_message_id; - if (typeof all_msg_list !== 'undefined' && all_msg_list.last() !== undefined) { - latest = all_msg_list.last().id; + if (typeof message_list.all !== 'undefined' && message_list.all.last() !== undefined) { + latest = message_list.all.last().id; } latest = Math.max(0, latest); return truncate_precision(latest + local_id_increment); @@ -281,7 +281,7 @@ exports.message_send_error = function message_send_error(local_id, error_respons function abort_message(message) { // Remove in all lists in which it exists - _.each([all_msg_list, home_msg_list, current_msg_list], function (msg_list) { + _.each([message_list.all, home_msg_list, current_msg_list], function (msg_list) { msg_list.remove_and_rerender([message]); }); } diff --git a/static/js/message_list.js b/static/js/message_list.js index afe20acfc41151..0e56b105a825b1 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -622,6 +622,11 @@ exports.MessageList.prototype = { } }; +exports.all = new exports.MessageList( + undefined, undefined, + {muting_enabled: false} +); + // We stop autoscrolling when the user is clearly in the middle of // doing something. Be careful, though, if you try to capture // mousemove, then you will have to contend with the autoscroll diff --git a/static/js/message_store.js b/static/js/message_store.js index 9842810505a3fa..0c79754bd20e68 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -363,7 +363,7 @@ exports.insert_new_messages = function insert_new_messages(messages) { // You must add add messages to home_msg_list BEFORE // calling unread.process_loaded_messages. exports.add_messages(messages, home_msg_list, {messages_are_new: true}); - exports.add_messages(messages, all_msg_list, {messages_are_new: true}); + exports.add_messages(messages, message_list.all, {messages_are_new: true}); if (narrow.active()) { if (narrow.filter().can_apply_locally()) { @@ -421,11 +421,11 @@ function process_result(messages, opts) { messages = _.map(messages, add_message_metadata); // If we're loading more messages into the home view, save them to - // the all_msg_list as well, as the home_msg_list is reconstructed - // from all_msg_list. + // the message_list.all as well, as the home_msg_list is reconstructed + // from message_list.all. if (opts.msg_list === home_msg_list) { process_loaded_for_unread(messages); - exports.add_messages(messages, all_msg_list, {messages_are_new: false}); + exports.add_messages(messages, message_list.all, {messages_are_new: false}); } if (messages.length !== 0 && !opts.cont_will_add_messages) { @@ -594,7 +594,7 @@ util.execute_early(function () { var backfill_batch_size = 1000; $(document).idle({'idle': 1000*10, 'onIdle': function () { - var first_id = all_msg_list.first().id; + var first_id = message_list.all.first().id; exports.load_old_messages({ anchor: first_id, num_before: backfill_batch_size, @@ -632,7 +632,7 @@ util.execute_early(function () { // created, but due to the closure, the old list is not garbage collected. This also leads // to the old list receiving the change id events, and throwing errors as it does not // have the messages that you would expect in its internal data structures. - _.each([all_msg_list, home_msg_list, narrowed_msg_list], function (msg_list) { + _.each([message_list.all, home_msg_list, narrowed_msg_list], function (msg_list) { if (msg_list !== undefined) { msg_list.change_message_id(old_id, new_id); diff --git a/static/js/narrow.js b/static/js/narrow.js index 9f7428dcb22b3b..17b25fb314ec44 100644 --- a/static/js/narrow.js +++ b/static/js/narrow.js @@ -294,8 +294,8 @@ exports.activate = function (raw_operators, opts) { // Don't bother populating a message list when it won't contain // the message we want anyway or if the filter can't be applied // locally. - if (all_msg_list.get(then_select_id) !== undefined && current_filter.can_apply_locally()) { - message_store.add_messages(all_msg_list.all(), narrowed_msg_list, {delay_render: true}); + if (message_list.all.get(then_select_id) !== undefined && current_filter.can_apply_locally()) { + message_store.add_messages(message_list.all.all(), narrowed_msg_list, {delay_render: true}); } var defer_selecting_closest = narrowed_msg_list.empty(); diff --git a/static/js/reload.js b/static/js/reload.js index 0493224032431b..027af0bd650ad1 100644 --- a/static/js/reload.js +++ b/static/js/reload.js @@ -155,7 +155,7 @@ function cleanup_before_reload() { server_events.cleanup_event_queue(); // Empty the large collections - clear_message_list(all_msg_list); + clear_message_list(message_list.all); clear_message_list(home_msg_list); clear_message_list(narrowed_msg_list); message_store.clear(); diff --git a/static/js/subs.js b/static/js/subs.js index ef429282cf333a..8164934ec9a04b 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -105,8 +105,8 @@ function update_in_home_view(sub, value) { home_msg_list.clear({clear_selected_id: false}); - // Recreate the home_msg_list with the newly filtered all_msg_list - message_store.add_messages(all_msg_list.all(), home_msg_list); + // Recreate the home_msg_list with the newly filtered message_list.all + message_store.add_messages(message_list.all.all(), home_msg_list); // Ensure we're still at the same scroll position if (ui.home_tab_obscured()) { @@ -168,7 +168,7 @@ function update_stream_name(sub, new_name) { stream_list.rename_stream(sub); // Update the message feed. - _.each([home_msg_list, current_msg_list, all_msg_list], function (list) { + _.each([home_msg_list, current_msg_list, message_list.all], function (list) { list.change_display_recipient(old_name, new_name); }); } @@ -343,7 +343,7 @@ exports.mark_subscribed = function (stream_name, attrs) { // Update unread counts as the new stream in sidebar might // need its unread counts re-calculated - process_loaded_for_unread(all_msg_list.all()); + process_loaded_for_unread(message_list.all.all()); $(document).trigger($.Event('subscription_add_done.zulip', {sub: sub})); }; diff --git a/static/js/ui.js b/static/js/ui.js index b7f2faf4b71a42..62ce51c4ddfe83 100644 --- a/static/js/ui.js +++ b/static/js/ui.js @@ -176,7 +176,7 @@ function need_skinny_mode() { } function update_message_in_all_views(message_id, callback) { - _.each([all_msg_list, home_msg_list, narrowed_msg_list], function (list) { + _.each([message_list.all, home_msg_list, narrowed_msg_list], function (list) { if (list === undefined) { return; } @@ -192,10 +192,10 @@ function update_message_in_all_views(message_id, callback) { exports.find_message = function (message_id) { // Try to find the message object. It might be in the narrow list - // (if it was loaded when narrowed), or only in the all_msg_list + // (if it was loaded when narrowed), or only in the message_list.all // (if received from the server while in a different narrow) var message; - _.each([all_msg_list, home_msg_list, narrowed_msg_list], function (msg_list) { + _.each([message_list.all, home_msg_list, narrowed_msg_list], function (msg_list) { if (msg_list !== undefined && message === undefined) { message = msg_list.get(message_id); } diff --git a/static/js/unread.js b/static/js/unread.js index d495651c8d6097..df438a1c483bdd 100644 --- a/static/js/unread.js +++ b/static/js/unread.js @@ -195,7 +195,7 @@ exports.enable = function enable() { }; exports.mark_all_as_read = function mark_all_as_read(cont) { - _.each(all_msg_list.all(), function (msg) { + _.each(message_list.all.all(), function (msg) { msg.flags = msg.flags || []; msg.flags.push('read'); }); @@ -235,7 +235,7 @@ exports.mark_messages_as_read = function mark_messages_as_read (messages, option message.unread = false; unread.process_read_message(message, options); home_msg_list.show_message_as_read(message, options); - all_msg_list.show_message_as_read(message, options); + message_list.all.show_message_as_read(message, options); if (narrowed_msg_list) { narrowed_msg_list.show_message_as_read(message, options); } diff --git a/static/js/zulip.js b/static/js/zulip.js index b3c7bdfc0936ea..3681876966b232 100644 --- a/static/js/zulip.js +++ b/static/js/zulip.js @@ -1,7 +1,3 @@ -var all_msg_list = new message_list.MessageList( - undefined, undefined, - {muting_enabled: false} -); var home_msg_list = new message_list.MessageList('zhome', new Filter([{operator: "in", operand: "home"}]), {muting_enabled: true} ); diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index aa2e3eb49bea9c..2320335f14ee15 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -53,7 +53,7 @@ var globals = + ' localstorage' // zulip.js - + ' all_msg_list home_msg_list narrowed_msg_list current_msg_list' + + ' home_msg_list narrowed_msg_list current_msg_list' + ' respond_to_message recenter_view last_viewport_movement_direction' + ' scroll_to_selected get_private_message_recipient' + ' process_loaded_for_unread'