Permalink
Browse files

Fixing repeating friend finding check in both intro and friends dialog.

  • Loading branch information...
1 parent 9410e3f commit 833edd1e2781bf83d6ef7d7aedd49779f34f3384 @samuelclay committed Dec 20, 2012
Showing with 29 additions and 20 deletions.
  1. +21 −16 media/js/newsblur/reader/reader_friends.js
  2. +8 −4 media/js/newsblur/reader/reader_intro.js
@@ -4,7 +4,7 @@ NEWSBLUR.ReaderFriends = function(options) {
};
this.options = $.extend({}, defaults, options);
-
+ this.sync_checks = 0;
this.runner();
};
@@ -89,10 +89,10 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, {
console.log(["Find friends", data]);
this.profile = NEWSBLUR.assets.user_profile;
this.services = data.services;
- if (!this.services['twitter'].syncing && !this.services['facebook'].syncing) {
- clearInterval(this.sync_interval);
+ // if (!this.services['twitter'].syncing && !this.services['facebook'].syncing) {
+ clearTimeout(this.sync_interval);
this.make_find_friends_and_services();
- }
+ // }
}, this));
},
@@ -155,10 +155,11 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, {
}
if (service_syncing) {
- clearInterval(this.sync_interval);
- this.sync_interval = setInterval(_.bind(function() {
+ clearTimeout(this.sync_interval);
+ this.sync_checks += 1;
+ this.sync_interval = _.delay(_.bind(function() {
this.check_services_sync_status();
- }, this), 3000);
+ }, this), this.sync_checks * 1000);
}
},
@@ -249,7 +250,7 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, {
}
},
'onClose': _.bind(function(dialog, callback) {
- clearInterval(this.sync_interval);
+ clearTimeout(this.sync_interval);
dialog.data.hide().empty().remove();
dialog.container.hide().empty().remove();
dialog.overlay.fadeOut(200, function() {
@@ -279,21 +280,24 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, {
},
connect: function(service) {
+ var self = this;
var options = "location=0,status=0,width=800,height=500";
var url = "/oauth/" + service + "_connect";
this.connect_window = window.open(url, '_blank', options);
- this.connect_window_timer = setInterval(_.bind(function() {
- console.log(["post connect window?", this.connect_window, this.connect_window.closed, this.connect_window.location]);
+ clearInterval(this.connect_window_timer);
+ this.sync_checks = 0;
+ this.connect_window_timer = setInterval(function() {
+ console.log(["post connect window?", self, self.connect_window, self.connect_window.closed]);
try {
- if (!this.connect_window ||
- !this.connect_window.location ||
- this.connect_window.closed) {
- this.post_connect({});
+ if (!self.connect_window ||
+ !self.connect_window.location ||
+ self.connect_window.closed) {
+ self.post_connect({});
}
} catch (err) {
- this.post_connect({});
+ self.post_connect({});
}
- }, this), 1000);
+ }, 1000);
},
disconnect: function(service) {
@@ -307,6 +311,7 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, {
},
post_connect: function(data) {
+ console.log(["post_connect", data, this, this.connect_window_timer]);
clearInterval(this.connect_window_timer);
$('.NB-error', this.$modal).remove();
if (data.error) {
@@ -16,6 +16,7 @@ NEWSBLUR.ReaderIntro = function(options) {
this.page_number = this.options.page_number;
this.slider_value = 0;
this.intervals = {};
+ this.sync_checks = 0;
this.runner();
};
@@ -245,16 +246,18 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, {
}
if (service_syncing) {
- clearInterval(this.sync_interval);
- this.sync_interval = setInterval(_.bind(function() {
+ clearTimeout(this.sync_interval);
+ this.sync_checks += 1;
+ this.sync_interval = _.delay(_.bind(function() {
this.fetch_friends();
- }, this), 3000);
+ }, this), this.sync_checks * 1000);
}
},
connect: function(service) {
var options = "location=0,status=0,width=800,height=500";
var url = "/oauth/" + service + "_connect";
+ this.sync_checks = 0;
this.connect_window = window.open(url, '_blank', options);
this.connect_window_timer = setInterval(_.bind(function() {
console.log(["post connect window?", this.connect_window, this.connect_window.closed, this.connect_window.location]);
@@ -360,7 +363,7 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, {
this.show_twitter_follow_buttons();
}
- clearInterval(this.sync_interval);
+ clearTimeout(this.sync_interval);
NEWSBLUR.assets.preference('intro_page', page_number);
_gaq.push(['_trackEvent', 'reader_intro', 'Page ' + this.page_number]);
},
@@ -449,6 +452,7 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, {
var options = "location=0,status=0,width=800,height=500";
var url = "/import/authorize";
this.connect_window = window.open(url, '_blank', options);
+ clearInterval(this.connect_window_timer);
this.connect_window_timer = setInterval(_.bind(function() {
console.log(["post connect window?", this.connect_window, this.connect_window.closed, this.connect_window.location]);
try {

0 comments on commit 833edd1

Please sign in to comment.