Rename get_updates to get_events in the frontend.

We did this rename on the backend ages ago.

(imported from commit 11bdf6aa08d932fe2586de282f6174e3dba7267a)
This commit is contained in:
Tim Abbott
2014-01-30 14:29:00 -05:00
parent e60f148a3e
commit 1eb294ed11
8 changed files with 56 additions and 56 deletions

View File

@@ -490,8 +490,8 @@ exports.send_message_success = function (local_id, message_id, start_time, local
setTimeout(function () { setTimeout(function () {
if (exports.send_times_data[message_id].received === undefined) { if (exports.send_times_data[message_id].received === undefined) {
blueslip.error("Restarting get_updates due to delayed receipt of sent message " + message_id); blueslip.error("Restarting get_events due to delayed receipt of sent message " + message_id);
server_events.restart_get_updates(); server_events.restart_get_events();
} }
}, 5000); }, 5000);
}; };
@@ -544,7 +544,7 @@ function send_message(request) {
} }
exports.transmit_message(request, success, error); exports.transmit_message(request, success, error);
server_events.assert_get_updates_running("Restarting get_updates because it was not running during send"); server_events.assert_get_events_running("Restarting get_events because it was not running during send");
if (feature_flags.local_echo && locally_echoed) { if (feature_flags.local_echo && locally_echoed) {
clear_compose_box(); clear_compose_box();

View File

@@ -48,7 +48,7 @@ function preserve_state(send_after_reload) {
} }
// Check if we're doing a compose-preserving reload. This must be // Check if we're doing a compose-preserving reload. This must be
// done before the first call to get_updates // done before the first call to get_events
$(function () { $(function () {
var location = window.location.toString(); var location = window.location.toString();
var fragment = location.substring(location.indexOf('#') + 1); var fragment = location.substring(location.indexOf('#') + 1);

View File

@@ -6,23 +6,23 @@ var waiting_on_homeview_load = true;
var events_stored_during_tutorial = []; var events_stored_during_tutorial = [];
var get_updates_xhr; var get_events_xhr;
var get_updates_timeout; var get_events_timeout;
var get_updates_failures = 0; var get_events_failures = 0;
exports.get_updates_params = { exports.get_events_params = {
pointer: -1 pointer: -1
}; };
function get_updates_success(events) { function get_events_success(events) {
var messages = []; var messages = [];
var messages_to_update = []; var messages_to_update = [];
var new_pointer; var new_pointer;
_.each(events, function (event) { _.each(events, function (event) {
exports.get_updates_params.last_event_id = Math.max(exports.get_updates_params.last_event_id, exports.get_events_params.last_event_id = Math.max(exports.get_events_params.last_event_id,
event.id); event.id);
}); });
if (tutorial.is_running()) { if (tutorial.is_running()) {
@@ -163,38 +163,38 @@ function get_updates_success(events) {
} }
} }
exports.get_updates = function get_updates(options) { exports.get_events = function get_events(options) {
options = _.extend({dont_block: false}, options); options = _.extend({dont_block: false}, options);
exports.get_updates_params.pointer = furthest_read; exports.get_events_params.pointer = furthest_read;
exports.get_updates_params.dont_block = options.dont_block || get_updates_failures > 0; exports.get_events_params.dont_block = options.dont_block || get_events_failures > 0;
if (exports.get_updates_params.queue_id === undefined) { if (exports.get_events_params.queue_id === undefined) {
exports.get_updates_params.queue_id = page_params.event_queue_id; exports.get_events_params.queue_id = page_params.event_queue_id;
exports.get_updates_params.last_event_id = page_params.last_event_id; exports.get_events_params.last_event_id = page_params.last_event_id;
} }
if (get_updates_xhr !== undefined) { if (get_events_xhr !== undefined) {
get_updates_xhr.abort(); get_events_xhr.abort();
} }
if (get_updates_timeout !== undefined) { if (get_events_timeout !== undefined) {
clearTimeout(get_updates_timeout); clearTimeout(get_events_timeout);
} }
get_updates_timeout = undefined; get_events_timeout = undefined;
get_updates_xhr = channel.post({ get_events_xhr = channel.post({
url: '/json/get_events', url: '/json/get_events',
data: exports.get_updates_params, data: exports.get_events_params,
idempotent: true, idempotent: true,
timeout: page_params.poll_timeout, timeout: page_params.poll_timeout,
success: function (data) { success: function (data) {
get_updates_xhr = undefined; get_events_xhr = undefined;
get_updates_failures = 0; get_events_failures = 0;
$('#connection-error').hide(); $('#connection-error').hide();
get_updates_success(data.events); get_events_success(data.events);
get_updates_timeout = setTimeout(get_updates, 0); get_events_timeout = setTimeout(get_events, 0);
}, },
error: function (xhr, error_type, exn) { error: function (xhr, error_type, exn) {
get_updates_xhr = undefined; get_events_xhr = undefined;
// If we are old enough to have messages outside of the // If we are old enough to have messages outside of the
// Tornado cache or if we're old enough that our message // Tornado cache or if we're old enough that our message
// queue has been garbage collected, immediately reload. // queue has been garbage collected, immediately reload.
@@ -210,37 +210,37 @@ exports.get_updates = function get_updates(options) {
return; return;
} else if (error_type === 'timeout') { } else if (error_type === 'timeout') {
// Retry indefinitely on timeout. // Retry indefinitely on timeout.
get_updates_failures = 0; get_events_failures = 0;
$('#connection-error').hide(); $('#connection-error').hide();
} else { } else {
get_updates_failures += 1; get_events_failures += 1;
} }
if (get_updates_failures >= 5) { if (get_events_failures >= 5) {
$('#connection-error').show(); $('#connection-error').show();
} else { } else {
$('#connection-error').hide(); $('#connection-error').hide();
} }
var retry_sec = Math.min(90, Math.exp(get_updates_failures/2)); var retry_sec = Math.min(90, Math.exp(get_events_failures/2));
get_updates_timeout = setTimeout(get_updates, retry_sec*1000); get_events_timeout = setTimeout(get_events, retry_sec*1000);
} }
}); });
}; };
exports.assert_get_updates_running = function assert_get_updates_running(error_message) { exports.assert_get_events_running = function assert_get_events_running(error_message) {
if (get_updates_xhr === undefined && get_updates_timeout === undefined) { if (get_events_xhr === undefined && get_events_timeout === undefined) {
exports.restart_get_updates({dont_block: true}); exports.restart_get_events({dont_block: true});
blueslip.error(error_message); blueslip.error(error_message);
} }
}; };
exports.restart_get_updates = function restart_get_updates(options) { exports.restart_get_events = function restart_get_events(options) {
exports.get_updates(options); exports.get_events(options);
}; };
exports.force_get_updates = function force_get_updates() { exports.force_get_events = function force_get_events() {
get_updates_timeout = setTimeout(exports.get_updates, 0); get_events_timeout = setTimeout(exports.get_events, 0);
}; };
exports.home_view_loaded = function home_view_loaded() { exports.home_view_loaded = function home_view_loaded() {
@@ -269,10 +269,10 @@ setInterval(function () {
$(function () { $(function () {
$(document).on('unsuspend', function () { $(document).on('unsuspend', function () {
// Immediately poll for new updates on unsuspend // Immediately poll for new events on unsuspend
blueslip.log("Restarting get_updates due to unsuspend"); blueslip.log("Restarting get_events due to unsuspend");
get_updates_failures = 0; get_events_failures = 0;
exports.restart_get_updates({dont_block: true}); exports.restart_get_events({dont_block: true});
}); });
}); });

View File

@@ -3,7 +3,7 @@
var csrf_token; var csrf_token;
$(function () { $(function () {
// Display loading indicator. This disappears after the first // Display loading indicator. This disappears after the first
// get_updates completes. // get_events completes.
if (page_params.have_initial_messages && !page_params.needs_tutorial) { if (page_params.have_initial_messages && !page_params.needs_tutorial) {
util.make_loading_indicator($('#page_loading_indicator'), {text: 'Loading...'}); util.make_loading_indicator($('#page_loading_indicator'), {text: 'Loading...'});
} else if (!page_params.needs_tutorial) { } else if (!page_params.needs_tutorial) {

View File

@@ -193,8 +193,8 @@ Socket.prototype = {
if (that._reconnect_initiation_time !== null) { if (that._reconnect_initiation_time !== null) {
// If this is a reconnect, network was probably // If this is a reconnect, network was probably
// recently interrupted, so we optimistically restart // recently interrupted, so we optimistically restart
// get_updates // get_events
server_events.restart_get_updates(); server_events.restart_get_events();
} }
that._is_open = true; that._is_open = true;

View File

@@ -327,7 +327,7 @@ function finale() {
is_running = false; is_running = false;
current_msg_list.clear(); current_msg_list.clear();
// Force a check on new events before we re-render the message list. // Force a check on new events before we re-render the message list.
server_events.force_get_updates(); server_events.force_get_events();
stream_data.set_stream_info(real_stream_info); stream_data.set_stream_info(real_stream_info);
util.show_first_run_message(); util.show_first_run_message();
current_msg_list.rerender(); current_msg_list.rerender();

View File

@@ -1590,8 +1590,8 @@ $(function () {
$('.logout_button').click(function (e) { $('.logout_button').click(function (e) {
$('#logout_form').submit(); $('#logout_form').submit();
}); });
$('.restart_get_updates_button').click(function (e) { $('.restart_get_events_button').click(function (e) {
server_events.restart_get_updates({dont_block: true}); server_events.restart_get_events({dont_block: true});
}); });
$('#api_key_button').click(function (e) { $('#api_key_button').click(function (e) {

View File

@@ -640,7 +640,7 @@ function add_message_metadata(message) {
} }
return cached_msg; return cached_msg;
} }
server_events.get_updates_params.last = Math.max(server_events.get_updates_params.last || 0, message.id); server_events.get_events_params.last = Math.max(server_events.get_events_params.last || 0, message.id);
var involved_people; var involved_people;
@@ -1183,7 +1183,7 @@ function main() {
} }
} }
// now start subscribing to updates // now start subscribing to updates
server_events.get_updates(); server_events.get_events();
// backfill more messages after the user is idle // backfill more messages after the user is idle
var backfill_batch_size = 1000; var backfill_batch_size = 1000;
@@ -1209,7 +1209,7 @@ function main() {
}); });
} else { } else {
server_events.home_view_loaded(); server_events.home_view_loaded();
server_events.get_updates(); server_events.get_events();
} }
$(document).on('message_id_changed', function (event) { $(document).on('message_id_changed', function (event) {
@@ -1217,8 +1217,8 @@ function main() {
if (furthest_read === old_id) { if (furthest_read === old_id) {
furthest_read = new_id; furthest_read = new_id;
} }
if (server_events.get_updates_params.pointer === old_id) { if (server_events.get_events_params.pointer === old_id) {
server_events.get_updates_params.pointer = new_id; server_events.get_events_params.pointer = new_id;
} }
if (msg_metadata_cache[old_id]) { if (msg_metadata_cache[old_id]) {
msg_metadata_cache[new_id] = msg_metadata_cache[old_id]; msg_metadata_cache[new_id] = msg_metadata_cache[old_id];