From 1283092c5f3df352105be25f19d55506f2e93e34 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Fri, 10 Aug 2012 19:20:08 -0700 Subject: [PATCH] Fixing intro and friend's twitter/facebook connect once and for all. --- media/js/newsblur/reader/reader_friends.js | 21 ++++++++++++-- media/js/newsblur/reader/reader_intro.js | 33 +++++++++++++++++++++- templates/social/social_connect.xhtml | 26 +++++++++-------- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/media/js/newsblur/reader/reader_friends.js b/media/js/newsblur/reader/reader_friends.js index 98af94c42..4d6242164 100644 --- a/media/js/newsblur/reader/reader_friends.js +++ b/media/js/newsblur/reader/reader_friends.js @@ -89,9 +89,8 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, { this.profile = NEWSBLUR.assets.user_profile; this.services = data.services; if (!this.services['twitter'].syncing && !this.services['facebook'].syncing) { + clearInterval(this.sync_interval); this.make_find_friends_and_services(); - } else { - _.delay(_.bind(this.check_services_sync_status, this), 3000); } }, this)); }, @@ -155,7 +154,10 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, { } if (service_syncing) { - _.delay(_.bind(this.check_services_sync_status, this), 3000); + clearInterval(this.sync_interval); + this.sync_interval = setInterval(_.bind(function() { + this.check_services_sync_status(); + }, this), 3000); } }, @@ -278,6 +280,18 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, { 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]); + try { + if (!this.connect_window || + !this.connect_window.location || + this.connect_window.closed) { + this.post_connect({}); + } + } catch (err) { + this.post_connect({}); + } + }, this), 1000); }, disconnect: function(service) { @@ -291,6 +305,7 @@ _.extend(NEWSBLUR.ReaderFriends.prototype, { }, post_connect: function(data) { + clearInterval(this.connect_window_timer); $('.NB-error', this.$modal).remove(); if (data.error) { var $error = $.make('div', { className: 'NB-error' }, [ diff --git a/media/js/newsblur/reader/reader_intro.js b/media/js/newsblur/reader/reader_intro.js index a76649c8b..f634566b5 100644 --- a/media/js/newsblur/reader/reader_intro.js +++ b/media/js/newsblur/reader/reader_intro.js @@ -243,7 +243,10 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, { } if (service_syncing) { - _.delay(_.bind(this.fetch_friends, this), 3000); + clearInterval(this.sync_interval); + this.sync_interval = setInterval(_.bind(function() { + this.fetch_friends(); + }, this), 3000); } }, @@ -251,6 +254,18 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, { 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]); + try { + if (!this.connect_window || + !this.connect_window.location || + this.connect_window.closed) { + this.post_connect({}); + } + } catch (err) { + this.post_connect({}); + } + }, this), 1000); _gaq.push(['_trackEvent', 'reader_intro', 'Connect to ' + service.name + ' attempt']); }, @@ -268,6 +283,7 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, { post_connect: function(data) { console.log(["Intro post_connect", data]); + clearInterval(this.connect_window_timer); $('.NB-error', this.$modal).remove(); if (data.error) { var $error = $.make('div', { className: 'NB-error' }, [ @@ -342,6 +358,7 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, { this.show_twitter_follow_buttons(); } + clearInterval(this.sync_interval); NEWSBLUR.assets.preference('intro_page', page_number); _gaq.push(['_trackEvent', 'reader_intro', 'Page ' + this.page_number]); }, @@ -425,10 +442,24 @@ _.extend(NEWSBLUR.ReaderIntro.prototype, { var options = "location=0,status=0,width=800,height=500"; var url = "/import/authorize?modal=true"; 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]); + try { + if (!this.connect_window || + !this.connect_window.location || + this.connect_window.closed) { + this.start_import_from_google_reader({}); + } + } catch (err) { + this.start_import_from_google_reader({}); + } + }, this), 1000); + NEWSBLUR.reader.flags.importing_from_google_reader = true; }, start_import_from_google_reader: function(data) { + clearInterval(this.connect_window_timer); var $error = $('.NB-intro-gitgoogle .NB-error', this.$modal); var $loading = $('.NB-intro-imports-progress .NB-loading', this.$modal); if (data && data.error) { diff --git a/templates/social/social_connect.xhtml b/templates/social/social_connect.xhtml index 4c874ec78..04d27d628 100644 --- a/templates/social/social_connect.xhtml +++ b/templates/social/social_connect.xhtml @@ -37,41 +37,42 @@ window.console = {}; window.console.log = function() {}; } + var opener = parent && parent.window.opener || window.opener; var next = "{{ next|safe }}"; if (next) { console.log(["Forwarding to next", next]); setTimeout(function() { window.location.href = next; }, 1000); - } else if (window.opener && window.opener.NEWSBLUR) { - console.log(["Found opener", window.opener.NEWSBLUR]); - if (window.opener.NEWSBLUR.reader.flags.importing_from_google_reader) { + } else if (opener && opener.NEWSBLUR) { + console.log(["Found opener", opener.NEWSBLUR]); + if (opener.NEWSBLUR.reader.flags.importing_from_google_reader) { console.log(['Importing from Reader']); - if (window.opener.NEWSBLUR.intro) { + if (opener.NEWSBLUR.intro) { console.log(['Using Intro dialog']); - window.opener.NEWSBLUR.intro.start_import_from_google_reader({ + opener.NEWSBLUR.intro.start_import_from_google_reader({ {% if error %} 'error': "{{ error }}", {% endif %} }); } else { console.log(['Using some other dialog']); - window.opener.NEWSBLUR.reader.post_google_reader_connect({ + opener.NEWSBLUR.reader.post_google_reader_connect({ {% if error %} 'error': "{{ error }}", {% endif %} }); } - } else if (window.opener.NEWSBLUR.intro) { + } else if (opener.NEWSBLUR.intro) { console.log(['Connecting through intro']); - window.opener.NEWSBLUR.intro.post_connect({ + opener.NEWSBLUR.intro.post_connect({ {% if error %} 'error': "{{ error }}", {% endif %} }); - } else if (window.opener.NEWSBLUR.reader_friends) { + } else if (opener.NEWSBLUR.reader_friends) { console.log(["Connecting through friends dialog"]); - window.opener.NEWSBLUR.reader_friends.post_connect({ + opener.NEWSBLUR.reader_friends.post_connect({ {% if error %} 'error': "{{ error }}", {% endif %} @@ -79,8 +80,9 @@ } window.close(); } else { - console.log(["No opener, directing to /", window.opener]); - window.location.href = "/"; + console.log(["No opener, directing to /", opener]); + window.close(); + // window.location.href = "/"; }