Refactoring socketio so real-time works around username restrictions.

This commit is contained in:
Samuel Clay 2021-01-04 19:01:30 -05:00
parent 06ec0d1099
commit e7e8bd88cd
2 changed files with 75 additions and 68 deletions

View file

@ -4979,17 +4979,7 @@
}, this));
this.socket.removeAllListeners('feed:update');
this.socket.on('feed:update', _.bind(function(feed_id, message) {
NEWSBLUR.log(['Real-time feed update', feed_id, message]);
var feed = this.model.get_feed(feed_id);
if (feed && !feed.get('fetched_once')) {
this.force_feed_refresh(feed_id);
} else {
this.feed_unread_count(feed_id, {
realtime: true
});
}
}, this));
this.socket.on('feed:update', _.bind(this.handle_realtime_update, this));
this.socket.removeAllListeners('feed:story:new');
this.socket.on('feed:story:new', _.bind(function(feed_id, message) {
@ -5001,7 +4991,53 @@
this.socket.removeAllListeners(NEWSBLUR.Globals.username);
this.socket.removeAllListeners("user:update");
this.socket.on('user:update', _.bind(function(username, message) {
this.socket.on('user:update', _.bind(this.handle_realtime_update, this));
this.socket.on('disconnect', _.bind(function() {
NEWSBLUR.log(["Lost connection to real-time pubsub. Falling back to polling."]);
this.flags.feed_refreshing_in_realtime = false;
this.setup_feed_refresh();
// $('.NB-module-content-account-realtime-subtitle').html($.make('b', 'Updating every 60 sec'));
$('.NB-module-content-account-realtime').attr('title', 'Updating sites every ' + this.flags.refresh_interval + ' seconds...').addClass('NB-error').removeClass('NB-active');
this.apply_tipsy_titles();
}, this));
this.socket.on('error', _.bind(function() {
NEWSBLUR.log(["Can't connect to real-time pubsub."]);
this.flags.feed_refreshing_in_realtime = false;
this.setup_feed_refresh();
// $('.NB-module-content-account-realtime-subtitle').html($.make('b', 'Updating every 60 sec'));
$('.NB-module-content-account-realtime').attr('title', 'Updating sites every ' + this.flags.refresh_interval + ' seconds...').addClass('NB-error').removeClass('NB-active');
this.apply_tipsy_titles();
_.delay(_.bind(this.setup_socket_realtime_unread_counts, this), Math.random()*60*1000);
}, this));
this.socket.on('reconnect_failed', _.bind(function() {
console.log(["Socket.io reconnect failed"]);
}, this));
this.socket.on('reconnect', _.bind(function() {
console.log(["Socket.io reconnected successfully!"]);
}, this));
this.socket.on('reconnecting', _.bind(function() {
console.log(["Socket.io reconnecting..."]);
}, this));
}
// this.watch_navigator_online();
},
handle_realtime_update: function (username, message) {
if (_.isNumber(username)) {
var feed_id = username;
NEWSBLUR.log(['Real-time feed update', feed_id, message]);
var feed = this.model.get_feed(feed_id);
if (feed && !feed.get('fetched_once')) {
this.force_feed_refresh(feed_id);
} else {
this.feed_unread_count(feed_id, {
realtime: true
});
}
} else {
NEWSBLUR.log(['Real-time user update', username, message]);
if (this.flags.social_view) return;
if (_.string.startsWith(message, 'feed:')) {
@ -5057,38 +5093,7 @@
NEWSBLUR.assets.load_feeds();
}
}
}, this));
this.socket.on('disconnect', _.bind(function() {
NEWSBLUR.log(["Lost connection to real-time pubsub. Falling back to polling."]);
this.flags.feed_refreshing_in_realtime = false;
this.setup_feed_refresh();
// $('.NB-module-content-account-realtime-subtitle').html($.make('b', 'Updating every 60 sec'));
$('.NB-module-content-account-realtime').attr('title', 'Updating sites every ' + this.flags.refresh_interval + ' seconds...').addClass('NB-error').removeClass('NB-active');
this.apply_tipsy_titles();
}, this));
this.socket.on('error', _.bind(function() {
NEWSBLUR.log(["Can't connect to real-time pubsub."]);
this.flags.feed_refreshing_in_realtime = false;
this.setup_feed_refresh();
// $('.NB-module-content-account-realtime-subtitle').html($.make('b', 'Updating every 60 sec'));
$('.NB-module-content-account-realtime').attr('title', 'Updating sites every ' + this.flags.refresh_interval + ' seconds...').addClass('NB-error').removeClass('NB-active');
this.apply_tipsy_titles();
_.delay(_.bind(this.setup_socket_realtime_unread_counts, this), Math.random()*60*1000);
}, this));
this.socket.on('reconnect_failed', _.bind(function() {
console.log(["Socket.io reconnect failed"]);
}, this));
this.socket.on('reconnect', _.bind(function() {
console.log(["Socket.io reconnected successfully!"]);
}, this));
this.socket.on('reconnecting', _.bind(function() {
console.log(["Socket.io reconnecting..."]);
}, this));
}
// this.watch_navigator_online();
},
watch_navigator_online: function() {

View file

@ -2,6 +2,8 @@
# Use the Google Closure Compiler to minify JavaScript
javascript_compressor: closure
compressor_options:
language_in: "ECMASCRIPT6"
# YUI for CSS (not cssmin)
css_compressor: yui