Permalink
Browse files

Finished elementary broken Facebook account and Publish Stream action…

… support
  • Loading branch information...
1 parent e43d954 commit 58019430ae3d3cf15584ca4940f46956880dd5be Harry Brundage committed Nov 11, 2010
Showing with 486 additions and 100 deletions.
  1. +13 −8 Resources/app/controllers/accounts_controller.coffee
  2. +17 −10 Resources/app/controllers/accounts_controller.js
  3. +2 −2 Resources/app/controllers/facebook_authorization_controller.coffee
  4. +2 −2 Resources/app/controllers/facebook_authorization_controller.js
  5. +3 −6 Resources/app/controllers/main.coffee
  6. +3 −3 Resources/app/controllers/main.js
  7. +7 −4 Resources/app/models/accounts/account.coffee
  8. +7 −7 Resources/app/models/accounts/account.js
  9. +49 −15 Resources/app/models/accounts/facebook/facebook_account.coffee
  10. +66 −19 Resources/app/models/accounts/facebook/facebook_account.js
  11. +1 −0 Resources/app/models/actions/action.coffee
  12. +1 −0 Resources/app/models/actions/action.js
  13. +10 −0 Resources/app/models/actions/facebook/facebook_action.coffee
  14. +20 −1 Resources/app/models/actions/facebook/facebook_action.js
  15. +15 −0 Resources/app/models/actions/facebook/publish_stream_action.coffee
  16. +26 −0 Resources/app/models/actions/facebook/publish_stream_action.js
  17. +3 −0 Resources/app/models/actions/facebook/stream_update_action.js
  18. +2 −1 Resources/app/views/accounts/account_table_view_row.coffee
  19. +1 −0 Resources/app/views/accounts/account_table_view_row.js
  20. +9 −4 Resources/app/views/accounts/accounts_table_view_window.coffee
  21. +11 −5 Resources/app/views/accounts/accounts_table_view_window.js
  22. +46 −0 Resources/app/views/accounts/facebook_account_table_row.js
  23. +30 −0 Resources/app/views/accounts/facebook_account_table_view_row.coffee
  24. +44 −0 Resources/app/views/accounts/facebook_account_table_view_row.js
  25. +46 −0 Resources/app/views/accounts/facebook_account_table_viw_row.js
  26. +1 −1 Resources/app/views/accounts/facebook_authorization_window.coffee
  27. +3 −1 Resources/app/views/accounts/facebook_authorization_window.js
  28. +4 −4 Resources/app/views/accounts/twitter_account_table_view_row.coffee
  29. +9 −0 Resources/app/views/splash/actions/facebook_action_table_view_row.coffee
  30. +23 −0 Resources/app/views/splash/actions/facebook_action_table_view_row.js
  31. +4 −3 Resources/app/views/splash/splash_window.coffee
  32. +7 −3 Resources/app/views/splash/splash_window.js
  33. BIN Resources/images/clock.png
  34. BIN Resources/images/id-card.png
  35. BIN Resources/images/radar.png
  36. +1 −1 Resources/vendor/spazcore/helpers/string.js
@@ -31,8 +31,6 @@ class AccountsController extends Citrus.Controller
@selectWindow ?= new Citrus.NewAccountSelectWindow this, (type) =>
this.addNewAccountOfType(type)
- Ti.API.debug(@selectWindow.win)
-
root.tabGroup.activeTab.open @selectWindow.win, {animated:true}
# Calledback from the NewAccountSelectWindow
@@ -44,16 +42,22 @@ class AccountsController extends Citrus.Controller
else
account = new Citrus[type]()
- if account?
+ if account? && account.valid
this.watchAccount(account)
- account.authorize (account) =>
- @selectWindow.win.close()
+ # Callback to trigger initial sync
+ success = () =>
+ @selectWindow.win.close({animated: false})
account.synch()
+ account.removeEventListener "authorization:success", success
+ account.addEventListener "authorization:success", success
+ account.authorize() # This adds a new window to the heirarchy
+ d("Created account and added authorization success listener")
return account
else
- Ti.API.error("Couldn't create a new account of type "+type)
- return null
+ er("Couldn't create a new account of type "+type)
+ er(account)
+ return false
# Called on each account to set up event listeners
watchAccount: (account) ->
@@ -71,6 +75,7 @@ class AccountsController extends Citrus.Controller
# Called when row is first ready to show and when it updates.
account.addEventListener "state:ready", (e) =>
+ d("Account state is ready")
if account.displayed? && account.displayed
@window.updateAccountDisplay(account)
else
@@ -82,7 +87,7 @@ class AccountsController extends Citrus.Controller
# Called if row has error loading
account.addEventListener "state:error", (e) =>
@window.hideLoading()
- alert("There was an error retrieving your details from Twitter. Please try again.")
+ alert("There was an error retrieving your details. Please try again.")
account.addEventListener "state:deleted", (e) =>
@store.removeAccount(account)
Oops, something went wrong.
@@ -3,8 +3,8 @@ Ti.include("/app/views/accounts/facebook_authorization_window.js")
class FacebookAuthorizationController extends Citrus.Controller
constructor: (onLoad, onError) ->
super
- d(Titanium.Facebook.loggedIn)
- if Titanium.Facebook.loggedIn
+ d(Titanium.Facebook.isLoggedIn())
+ if Titanium.Facebook.isLoggedIn()
onLoad(Titanium.Facebook.session)
return
else
Oops, something went wrong.
@@ -9,7 +9,7 @@ Titanium.UI.setBackgroundColor('#000')
# Code Reader tab group
root.CodeReaderController = new Citrus.CodeReaderController()
codeReaderTab = Titanium.UI.createTab({
- icon:'KS_nav_views.png',
+ icon:'images/radar.png',
title:'Scanner',
window: root.CodeReaderController.window.win
})
@@ -20,24 +20,21 @@ root.accountStore = new Citrus.AccountSet()
root.AccountsController = new Citrus.AccountsController(root.accountStore)
accountsTab = Titanium.UI.createTab({
- icon:'KS_nav_views.png',
+ icon:'images/id-card.png',
title:'Accounts',
window: root.AccountsController.window.win
})
# Scanned Codes list tab group
root.CodesWindow = new Citrus.CodesWindow('Codes','No Codes scanned yet.')
codesTab = Titanium.UI.createTab({
- icon:'KS_nav_views.png',
+ icon:'images/clock.png',
title:'Scanned Codes',
window: root.CodesWindow.win
})
-
-
root.tabGroup.addTab(tab) for tab in [codeReaderTab, accountsTab, codesTab]
root.tabGroup.setActiveTab(accountsTab)
root.tabGroup.open({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT})
-
Ti.include('test.js')
Oops, something went wrong.
@@ -4,16 +4,19 @@ class Account extends Citrus.PersistedObject
type: "GenericAccount"
lastSynched: false
refreshInterval: 1000*60*3 # 3 hours
+ constructor: ->
+ super
+ @valid = true
+
isAuthorized: ->
false
- authorize: (callback) ->
- @_authCallback = callback
+ authorize: () ->
+ return true if this.isAuthorized()
this.fireEvent("authorization:start")
true
completeAuthorization: () ->
- @_authCallback(this) if @_authCallback?
this.fireEvent("authorization:success")
this.fireEvent("authorization:complete")
true
@@ -28,4 +31,4 @@ Ti.include("/app/models/accounts/twitter/twitter_account.js")
Ti.include("/app/models/accounts/facebook/facebook_account.js")
Ti.include("/app/models/accounts/google/google_account.js")
#Ti.include("/app/models/accounts/foursquare/foursquare_account.js")
-Ti.include("/app/models/accounts/linkedin/linkedin_account.js")
+Ti.include("/app/models/accounts/linkedin/linkedin_account.js")
Oops, something went wrong.
@@ -2,32 +2,66 @@ Ti.include("/app/controllers/facebook_authorization_controller.js")
class FacebookAccount extends Citrus.Account
type: "FacebookAccount"
+ persistableAttributes: ["name", "affiliations"]
constructor: () ->
+ super
# Hack for only one facebook account while the titanium module is in use.
- if _.any(root.accountStore, (a) -> a.type == "FacebookAccount")
+ if root.accountStore? && _.any(root.accountStore.accounts, (a) -> return a.type == "FacebookAccount")
d("Trying to create a second Facebook account. No can do at the moment.")
alert("Multiple Facebook accounts aren't supported right now, sorry!")
- return null
- else
- return super
+ @valid = false
isAuthorized: () ->
Ti.Facebook.isLoggedIn()
- authorize: (success) ->
+ synch: () =>
+ d("Synching facebook account")
+ this.fireEvent("state:updating")
+ unless this.isAuthorized()
+ d("Trying to synch Facebook account but account is not authorized!")
+ this.fireEvent("state:error")
+ return false
+ else
+ fql = "SELECT name, affiliations FROM user WHERE uid = me()"
+ Titanium.Facebook.query fql, (e) =>
+ if e.success && e.data?
+ d("Success getting facebook data!")
+ @name = e.data[0].name
+ @affiliations = _.map(e.data[0].affiliations, (a) -> a.name).join(", ") if e.data[0]?.affiliations?
+ this.fireEvent("state:ready")
+ else
+ er("Error fqling Facebook information.")
+ er(e)
+ this.fireEvent("state:error")
+
+ authorize: () ->
d("Starting facebook authorization")
- loggedIn = (session) ->
+ super
+ d(Titanium.Facebook.isLoggedIn())
+ d(Titanium.Facebook.loggedIn)
+ d(Titanium.Facebook.session)
+ d(Titanium.Facebook.permissions)
+ controller = {}
+
+ loggedIn = (session) =>
d("Successfully logged in to facebook")
d(session)
- errorLoggingIn = (e) ->
- er("Error logging in with facebook account!")
- er(e)
- er(Titanium.Facebook.session)
- er(Titanium.Facebook.isLoggedIn())
- Titanium.Facebook.publishStream("Test status! Woooohooo", null, null, (e) ->
- d("Trying to publish stream")
- d(e)
- )
+ controller.destroy()
+ this.completeAuthorization()
+
+ errorLoggingIn = (e) =>
+ d("Suspected login error. Verifying")
+ unless Titanium.Facebook.isLoggedIn()
+ er("Error logging in with facebook account!")
+ er(e)
+ d("Session:")
+ d(Titanium.Facebook.session)
+ d("Is logged in:")
+ d(Titanium.Facebook.isLoggedIn())
+ this.fireEvent("authorization:error", e)
+ else
+ er("False negative on facebook login! Loggin in.")
+ loggedIn(Titanium.Facebook.session)
controller = new Citrus.FacebookAuthorizationController(loggedIn, errorLoggingIn)
Oops, something went wrong.

0 comments on commit 5801943

Please sign in to comment.