mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 16:01:58 +00:00
pointer: Remove frontend logic tracking furthest_read.
Since we are no longer using the "pointer" value sent in page_params.pointer for anything, there's no value in continuing to send it from the server to the client. The remaining code in pointer.js is logic managing state for the currently selected message.
This commit is contained in:
@@ -56,25 +56,6 @@ run_test('message_event', () => {
|
||||
assert(inserted);
|
||||
});
|
||||
|
||||
run_test('pointer_event', () => {
|
||||
const event = {
|
||||
type: 'pointer',
|
||||
pointer: 999,
|
||||
};
|
||||
|
||||
global.pointer.furthest_read = 0;
|
||||
global.pointer.set_furthest_read = function (value) {
|
||||
this.furthest_read = value;
|
||||
};
|
||||
global.pointer.server_furthest_read = 0;
|
||||
global.pointer.set_server_furthest_read = function (value) {
|
||||
this.server_furthest_read = value;
|
||||
};
|
||||
server_events._get_events_success([event]);
|
||||
assert.equal(global.pointer.furthest_read, event.pointer);
|
||||
assert.equal(global.pointer.server_furthest_read, event.pointer);
|
||||
});
|
||||
|
||||
// Start blueslip tests here
|
||||
|
||||
const setup = function () {
|
||||
|
||||
@@ -208,9 +208,6 @@ exports.add_message_metadata = function (message) {
|
||||
exports.reify_message_id = function (opts) {
|
||||
const old_id = opts.old_id;
|
||||
const new_id = opts.new_id;
|
||||
if (pointer.furthest_read === old_id) {
|
||||
pointer.set_furthest_read(new_id);
|
||||
}
|
||||
if (stored_messages.has(old_id)) {
|
||||
stored_messages.set(new_id, stored_messages.get(old_id));
|
||||
stored_messages.delete(old_id);
|
||||
|
||||
@@ -12,70 +12,12 @@ exports.suppress_scroll_pointer_update = false;
|
||||
exports.set_suppress_scroll_pointer_update = function (value) {
|
||||
exports.suppress_scroll_pointer_update = value;
|
||||
};
|
||||
exports.furthest_read = -1;
|
||||
exports.set_furthest_read = function (value) {
|
||||
exports.furthest_read = value;
|
||||
};
|
||||
exports.server_furthest_read = -1;
|
||||
exports.set_server_furthest_read = function (value) {
|
||||
exports.server_furthest_read = value;
|
||||
};
|
||||
|
||||
let pointer_update_in_flight = false;
|
||||
|
||||
function update_pointer() {
|
||||
if (!pointer_update_in_flight) {
|
||||
pointer_update_in_flight = true;
|
||||
return channel.post({
|
||||
url: '/json/users/me/pointer',
|
||||
idempotent: true,
|
||||
data: {pointer: exports.furthest_read},
|
||||
success: function () {
|
||||
exports.server_furthest_read = exports.furthest_read;
|
||||
pointer_update_in_flight = false;
|
||||
},
|
||||
error: function () {
|
||||
pointer_update_in_flight = false;
|
||||
},
|
||||
});
|
||||
}
|
||||
// Return an empty, resolved Deferred.
|
||||
return $.when();
|
||||
}
|
||||
|
||||
|
||||
exports.send_pointer_update = function () {
|
||||
// Only bother if you've read new messages.
|
||||
if (exports.furthest_read > exports.server_furthest_read) {
|
||||
update_pointer();
|
||||
}
|
||||
};
|
||||
|
||||
exports.initialize = function initialize() {
|
||||
exports.server_furthest_read = page_params.pointer;
|
||||
exports.furthest_read = exports.server_furthest_read;
|
||||
|
||||
// We only send pointer updates when the user has been idle for a
|
||||
// short while to avoid hammering the server
|
||||
$(document).idle({idle: 1000,
|
||||
onIdle: exports.send_pointer_update,
|
||||
keepTracking: true});
|
||||
|
||||
$(document).on('message_selected.zulip', function (event) {
|
||||
// Only advance the pointer when not narrowed
|
||||
if (event.id === -1) {
|
||||
return;
|
||||
}
|
||||
// Additionally, don't advance the pointer server-side
|
||||
// if the selected message is local-only
|
||||
if (event.msg_list === home_msg_list && page_params.narrow_stream === undefined) {
|
||||
if (event.id > exports.furthest_read) {
|
||||
const msg = home_msg_list.get(event.id);
|
||||
if (!msg.locally_echoed) {
|
||||
exports.furthest_read = event.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.mark_read && event.previously_selected !== -1) {
|
||||
// Mark messages between old pointer and new pointer as read
|
||||
|
||||
@@ -19,7 +19,6 @@ function get_events_success(events) {
|
||||
let messages = [];
|
||||
const update_message_events = [];
|
||||
const post_message_events = [];
|
||||
let new_pointer;
|
||||
|
||||
const clean_event = function clean_event(event) {
|
||||
// Only log a whitelist of the event to remove private data
|
||||
@@ -64,10 +63,6 @@ function get_events_success(events) {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'pointer':
|
||||
new_pointer = event.pointer;
|
||||
break;
|
||||
|
||||
case 'update_message':
|
||||
update_message_events.push(event);
|
||||
break;
|
||||
@@ -125,13 +120,6 @@ function get_events_success(events) {
|
||||
}
|
||||
}
|
||||
|
||||
if (new_pointer !== undefined
|
||||
&& new_pointer > pointer.furthest_read) {
|
||||
pointer.set_furthest_read(new_pointer);
|
||||
pointer.set_server_furthest_read(new_pointer);
|
||||
home_msg_list.select_id(new_pointer, {then_scroll: true, use_closest: true});
|
||||
}
|
||||
|
||||
if (home_msg_list.selected_id() === -1 && !home_msg_list.empty()) {
|
||||
home_msg_list.select_id(home_msg_list.first().id, {then_scroll: false});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user