pointer.js: Add setter for furthest_read.

After migration to an ES6 module, `furthest_read` would no longer be
mutable from outside the module.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2018-08-04 02:37:23 -04:00 committed by Tim Abbott
parent 6e4ae95994
commit 055ebe76aa
5 changed files with 9 additions and 2 deletions

View File

@ -203,6 +203,7 @@ run_test('message_id_change', () => {
set_global('pointer', { set_global('pointer', {
furthest_read: 401, furthest_read: 401,
set_furthest_read: function (value) { this.furthest_read = value; },
}); });
set_global('message_list', {}); set_global('message_list', {});

View File

@ -67,6 +67,9 @@ run_test('pointer_event', () => {
}; };
global.pointer.furthest_read = 0; global.pointer.furthest_read = 0;
global.pointer.set_furthest_read = function (value) {
this.furthest_read = value;
};
global.pointer.server_furthest_read = 0; global.pointer.server_furthest_read = 0;
server_events._get_events_success([event]); server_events._get_events_success([event]);
assert.equal(global.pointer.furthest_read, event.pointer); assert.equal(global.pointer.furthest_read, event.pointer);

View File

@ -176,7 +176,7 @@ exports.reify_message_id = function (opts) {
var old_id = opts.old_id; var old_id = opts.old_id;
var new_id = opts.new_id; var new_id = opts.new_id;
if (pointer.furthest_read === old_id) { if (pointer.furthest_read === old_id) {
pointer.furthest_read = new_id; pointer.set_furthest_read(new_id);
} }
if (stored_messages[old_id]) { if (stored_messages[old_id]) {
stored_messages[new_id] = stored_messages[old_id]; stored_messages[new_id] = stored_messages[old_id];

View File

@ -11,6 +11,9 @@ exports.recenter_pointer_on_display = false;
// when All Messages is next clicked by the user // when All Messages is next clicked by the user
exports.suppress_scroll_pointer_update = false; exports.suppress_scroll_pointer_update = false;
exports.furthest_read = -1; exports.furthest_read = -1;
exports.set_furthest_read = function (value) {
exports.furthest_read = value;
};
exports.server_furthest_read = -1; exports.server_furthest_read = -1;
var pointer_update_in_flight = false; var pointer_update_in_flight = false;

View File

@ -133,7 +133,7 @@ function get_events_success(events) {
if (new_pointer !== undefined if (new_pointer !== undefined
&& new_pointer > pointer.furthest_read) { && new_pointer > pointer.furthest_read) {
pointer.furthest_read = new_pointer; pointer.set_furthest_read(new_pointer);
pointer.server_furthest_read = new_pointer; pointer.server_furthest_read = new_pointer;
home_msg_list.select_id(new_pointer, {then_scroll: true, use_closest: true}); home_msg_list.select_id(new_pointer, {then_scroll: true, use_closest: true});
} }