Skip to content

Commit

Permalink
Move all_msg_list to message_list.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerkid authored and timabbott committed Apr 22, 2016
1 parent c74483e commit 35b0af2
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions frontend_tests/node_tests/message_list.js
Expand Up @@ -18,6 +18,7 @@ set_global('$', function () {
});

set_global('feature_flags', {});
set_global('Filter', function () {});

var MessageList = require('js/message_list').MessageList;

Expand Down
6 changes: 3 additions & 3 deletions static/js/echo.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
});
}
Expand Down
5 changes: 5 additions & 0 deletions static/js/message_list.js
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions static/js/message_store.js
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions static/js/narrow.js
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion static/js/reload.js
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions static/js/subs.js
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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}));
};
Expand Down
6 changes: 3 additions & 3 deletions static/js/ui.js
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions static/js/unread.js
Expand Up @@ -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');
});
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions 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}
);
Expand Down
2 changes: 1 addition & 1 deletion tools/jslint/check-all.js
Expand Up @@ -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'
Expand Down

0 comments on commit 35b0af2

Please sign in to comment.