Got the gplus friends loading now.

This commit is contained in:
Scott Erickson 2014-03-26 13:50:01 -07:00
parent 544070e578
commit 132b22f14a
3 changed files with 26 additions and 22 deletions

View file

@ -74,7 +74,7 @@
<script>
// Additional JS functions here
window.fbAsyncInit = function() {
Backbone.Mediator.publish('fbapi-loaded')
Backbone.Mediator.publish('fbapi-loaded');
FB.init({
appId : document.location.origin === 'http://localhost:3000' ? '607435142676437' : '148832601965463', // App ID
channelUrl : document.location.origin +'/channel.html', // Channel File

View file

@ -59,8 +59,8 @@ div#columns.row
if friends.length
for friend in friends
p.friend-entry
img(src="http://graph.facebook.com/#{friend.facebookID}/picture").img-thumbnail
span= friend.creatorName + ' (' + friend.facebookName + ')'
img(src=friend.imageSource).img-thumbnail
span= friend.creatorName + ' (' + friend.name + ')'
br
span= Math.round(friend.totalScore * 100)
span :

View file

@ -24,8 +24,8 @@ module.exports = class LadderTabView extends CocoView
'click .connect-facebook': 'onConnectFacebook'
subscriptions:
'fbapi-loaded': 'onFacebookAPILoaded'
'gapi-loaded': 'onGPlusAPILoaded'
'fbapi-loaded': 'checkFriends'
'gapi-loaded': 'checkFriends'
'facebook-logged-in': 'onConnectedWithFacebook'
constructor: (options, @level, @sessions) ->
@ -33,8 +33,12 @@ module.exports = class LadderTabView extends CocoView
@teams = teamDataFromLevel @level
@leaderboards = {}
@refreshLadder()
@checkFriends() if window.FB and window.gapi
checkFriends: ->
return if @checked
@checked = true
@loadingFacebookFriends = true
FB.getLoginStatus (response) =>
@facebookStatus = response.status
@ -46,16 +50,8 @@ module.exports = class LadderTabView extends CocoView
else
@gplusSessionStateLoaded()
apiLoaded: ->
return unless @fbAPILoaded and @gplusAPILoaded
@checkFriends()
# FACEBOOK
onFacebookAPILoaded: ->
@fbAPILoaded = true
@apiLoaded()
# Connect button pressed
onConnectFacebook: ->
@connecting = true
FB.login()
@ -79,18 +75,15 @@ module.exports = class LadderTabView extends CocoView
friendsMap = {}
friendsMap[friend.id] = friend.name for friend in @facebookData
for friend in result
friend.facebookName = friendsMap[friend.facebookID]
friend.name = friendsMap[friend.facebookID]
friend.otherTeam = if friend.team is 'humans' then 'ogres' else 'humans'
@facebookFriends = result
friend.imageSource = "http://graph.facebook.com/#{friend.facebookID}/picture"
@facebookFriendSessions = result
@loadingFacebookFriends = false
@renderMaybe()
# GOOGLE PLUS
onGPlusAPILoaded: ->
@gplusAPILoaded = true
@apiLoaded()
gplusSessionStateLoaded: ->
if application.gplusHandler.loggedIn
@loadingGPlusFriends = true
@ -110,9 +103,16 @@ module.exports = class LadderTabView extends CocoView
}
onGPlusFriendSessionsLoaded: (result) =>
friendsMap = {}
friendsMap[friend.id] = friend for friend in @gplusData
for friend in result
friend.name = friendsMap[friend.gplusID].displayName
friend.otherTeam = if friend.team is 'humans' then 'ogres' else 'humans'
friend.imageSource = friendsMap[friend.gplusID].image.url
@gplusFriendSessions = result
@loadingGPlusFriends = false
@renderMaybe()
# LADDER LOADING
refreshLadder: ->
@ -130,7 +130,7 @@ module.exports = class LadderTabView extends CocoView
@renderMaybe()
renderMaybe: ->
return if @loadingFacebookFriends or @loadingLeaderboards
return if @loadingFacebookFriends or @loadingLeaderboards or @loadingGPlusFriends
@startsLoading = false
@render()
@ -141,11 +141,15 @@ module.exports = class LadderTabView extends CocoView
ctx.teams = @teams
team.leaderboard = @leaderboards[team.id] for team in @teams
ctx.levelID = @levelID
ctx.friends = @facebookFriends
ctx.friends = @consolidateFriends()
ctx.onFacebook = @facebookStatus is 'connected'
ctx.onGPlus = application.gplusHandler.loggedIn
ctx
consolidateFriends: ->
allFriendSessions = (@facebookFriendSessions or []).concat(@gplusFriendSessions or [])
_.uniq allFriendSessions, false, (session) -> session._id
class LeaderboardData
constructor: (@level, @team, @session) ->
_.extend @, Backbone.Events