Make MessageList.selected_id an accessor method

(imported from commit 144d12ba8be2de02900ef06c3413f660144de8bf)
This commit is contained in:
Zev Benjamin
2013-02-20 12:26:50 -05:00
parent 36798c8d67
commit 9e9b4c8541
7 changed files with 21 additions and 17 deletions

View File

@@ -21,7 +21,7 @@ function show(tabname, focus_area) {
$('.message_comp').slideDown(100, function () { $('.message_comp').slideDown(100, function () {
// If the compose box is obscuring the currently selected message, // If the compose box is obscuring the currently selected message,
// scroll up until the message is no longer occluded. // scroll up until the message is no longer occluded.
if (current_msg_list.selected_id === -1) { if (current_msg_list.selected_id() === -1) {
// If there's no selected message, there's no need to // If there's no selected message, there's no need to
// scroll the compose box to avoid it. // scroll the compose box to avoid it.
return; return;

View File

@@ -88,7 +88,7 @@ function process_hotkey(e) {
} }
if (narrow_hotkeys.hasOwnProperty(code)) { if (narrow_hotkeys.hasOwnProperty(code)) {
narrow_hotkeys[code](current_msg_list.selected_id); narrow_hotkeys[code](current_msg_list.selected_id());
return true; return true;
} }

View File

@@ -3,7 +3,7 @@ function MessageList(table_name) {
this._items = []; this._items = [];
this._hash = {}; this._hash = {};
this.table_name = table_name; this.table_name = table_name;
this.selected_id = -1; this._selected_id = -1;
return this; return this;
} }
@@ -28,12 +28,16 @@ MessageList.prototype = {
return this._items[this._items.length - 1]; return this._items[this._items.length - 1];
}, },
selected_id: function MessageList_selected_id() {
return this._selected_id;
},
selected_message: function MessageList_selected_message() { selected_message: function MessageList_selected_message() {
return this.get(this.selected_id); return this.get(this._selected_id);
}, },
selected_row: function MessageList_selected_row() { selected_row: function MessageList_selected_row() {
return rows.get(this.selected_id, this.table_name); return rows.get(this._selected_id, this.table_name);
}, },
closest_id: function MessageList_closest_id(id) { closest_id: function MessageList_closest_id(id) {

View File

@@ -210,7 +210,7 @@ function build_filter(operators_mixed_case) {
exports.activate = function (operators, opts) { exports.activate = function (operators, opts) {
opts = $.extend({}, { opts = $.extend({}, {
allow_collapse: true, allow_collapse: true,
target_id: current_msg_list.selected_id target_id: current_msg_list.selected_id()
}, opts); }, opts);
var was_narrowed = exports.active(); var was_narrowed = exports.active();
@@ -252,7 +252,7 @@ exports.activate = function (operators, opts) {
var msgs = narrowed_msg_list.all(); var msgs = narrowed_msg_list.all();
var i; var i;
var to_process = []; var to_process = [];
for (i = 0; i < msgs.length && msgs[i].id <= narrowed_msg_list.selected_id; ++i) { for (i = 0; i < msgs.length && msgs[i].id <= narrowed_msg_list.selected_id(); ++i) {
to_process.push(msgs[i]); to_process.push(msgs[i]);
} }
@@ -341,7 +341,7 @@ exports.deactivate = function () {
reset_load_more_status(); reset_load_more_status();
current_msg_list = all_msg_list; current_msg_list = all_msg_list;
select_message_by_id(all_msg_list.selected_id, all_msg_list, select_message_by_id(all_msg_list.selected_id(), all_msg_list,
{then_scroll: true}); {then_scroll: true});
search.update_highlight_on_narrow(); search.update_highlight_on_narrow();

View File

@@ -135,7 +135,7 @@ function stream_home_view_clicked(e) {
// If we added any messages that were unread but before the currently selected message pointer // If we added any messages that were unread but before the currently selected message pointer
// we need to re-process them to update the unread count // we need to re-process them to update the unread count
if (! all_msg_list.empty()) { if (! all_msg_list.empty()) {
process_unread_counts(message_range(all_msg_list.first().id, all_msg_list.selected_id), true); process_unread_counts(message_range(all_msg_list.first().id, all_msg_list.selected_id()), true);
} }
}, 0); }, 0);

View File

@@ -254,7 +254,7 @@ function resizehandler(e) {
// This function might run onReady (if we're in a narrow window), // This function might run onReady (if we're in a narrow window),
// but before we've loaded in the messages; in that case, don't // but before we've loaded in the messages; in that case, don't
// try to scroll to one. // try to scroll to one.
if (current_msg_list.selected_id !== -1) { if (current_msg_list.selected_id() !== -1) {
scroll_to_selected(); scroll_to_selected();
} }
// When the screen resizes, it may cause some messages to go off the screen // When the screen resizes, it may cause some messages to go off the screen

View File

@@ -259,7 +259,7 @@ function update_selected_message(message, msg_list, opts) {
furthest_read = new_selected_id; furthest_read = new_selected_id;
} }
msg_list.selected_id = new_selected_id; msg_list._selected_id = new_selected_id;
} }
function select_message(next_message, msg_list, opts) { function select_message(next_message, msg_list, opts) {
@@ -279,7 +279,7 @@ function select_message(next_message, msg_list, opts) {
} }
} }
if (rows.id(next_message) !== msg_list.selected_id) { if (rows.id(next_message) !== msg_list.selected_id()) {
update_selected_message(next_message, msg_list, opts); update_selected_message(next_message, msg_list, opts);
} }
@@ -559,7 +559,7 @@ function add_message_metadata(message, dummy) {
} }
function add_messages_helper(messages, msg_list, predicate, allow_collapse, append_new_messages) { function add_messages_helper(messages, msg_list, predicate, allow_collapse, append_new_messages) {
var center_message_id = msg_list.selected_id; var center_message_id = msg_list.selected_id();
// center_message_id is guaranteed to be between the top and bottom // center_message_id is guaranteed to be between the top and bottom
var top_messages = $.grep(messages, function (elem, idx) { var top_messages = $.grep(messages, function (elem, idx) {
return (elem.id < center_message_id && msg_list.get(elem.id) === undefined return (elem.id < center_message_id && msg_list.get(elem.id) === undefined
@@ -615,8 +615,8 @@ function add_messages(messages, msg_list, opts) {
// //
// We also need to re-select the message by ID, because we might have // We also need to re-select the message by ID, because we might have
// removed and re-added the row as part of prepend collapsing. // removed and re-added the row as part of prepend collapsing.
if (prepended && (msg_list.selected_id >= 0)) { if (prepended && (msg_list.selected_id() >= 0)) {
select_message_by_id(msg_list.selected_id, msg_list, {then_scroll: true}); select_message_by_id(msg_list.selected_id(), msg_list, {then_scroll: true});
} }
if (typeahead_helper.autocomplete_needs_update()) { if (typeahead_helper.autocomplete_needs_update()) {
@@ -692,7 +692,7 @@ function get_updates(options) {
select_message_by_id(data.new_pointer, all_msg_list, {then_scroll: true}); select_message_by_id(data.new_pointer, all_msg_list, {then_scroll: true});
} }
if (all_msg_list.selected_id === -1) { if (all_msg_list.selected_id() === -1) {
select_message_by_id(all_msg_list.first().id, all_msg_list, {then_scroll: false}); select_message_by_id(all_msg_list.first().id, all_msg_list, {then_scroll: false});
} }
@@ -799,7 +799,7 @@ $(function () {
function load_more(messages) { function load_more(messages) {
// If we received the initially selected message, select it on the client side, // If we received the initially selected message, select it on the client side,
// but not if the user has already selected another one during load. // but not if the user has already selected another one during load.
if (all_msg_list.selected_id === -1) { if (all_msg_list.selected_id() === -1) {
select_message_by_id(initial_pointer, all_msg_list, {then_scroll: true}); select_message_by_id(initial_pointer, all_msg_list, {then_scroll: true});
} }