changeset 8:6fd0a307850f

check empty strings and users
author Mathias Gebbe <mgebbe@intevation.de>
date Wed, 11 Jun 2014 21:58:41 +0200
parents 2123f355ab68
children 8363d4970c75
files src/facebook.coffee src/pumpio.coffee src/routes.coffee src/sync.coffee src/twitter.coffee
diffstat 5 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/facebook.coffee	Wed Jun 11 02:32:53 2014 +0200
+++ b/src/facebook.coffee	Wed Jun 11 21:58:41 2014 +0200
@@ -49,7 +49,6 @@
     return if not (posts?) or posts.length is 0
     #console.log JSON.stringify(posts) # all posts from network (100)
     async.eachSeries posts, ((post, callback) ->
-
       async.waterfall [
         (callback) ->
           FromESN.search {uid: post.id + "@facebook_to_" + me, recipientUser: me}, callback
@@ -62,7 +61,10 @@
           pubuser = pubuser
           User.search {id: pubuser.id + "@facebook"}, callback
         (dbuser, callback) ->
-          Sync.postParser post, dbuser[0], 'facebook', callback
+          if (dbuser[0]?)
+            Sync.postParser post, dbuser[0], 'facebook', callback
+          else
+            return
         (parsed, callback) ->
           Pump.postUser bridgeid, me, parsed, callback
         (pumppost, callback) ->
@@ -103,11 +105,13 @@
       async.each allESN, ((fromesn, callback) ->
         async.waterfall [
           (cb) ->
-            cb (true) if fromesn.sourcePost.indexOf('www.facebook.com') is -1
+            if fromesn.sourcePost.indexOf('www.facebook.com') is -1
+              return
             Usermap.search {id: me + '_to_' + me}, cb
           (pumpuser, cb) ->
             Pump.getNote(pumpuser[0], fromesn.pumpPost, cb)
           (note, cb) ->
+            return if not (note?)
             if note.liked is true
               obj = fromesn.postid.substr(0,fromesn.postid.indexOf('@'))
               postLike(user,obj)
@@ -224,7 +228,7 @@
 
   FB.setAccessToken token
 
-  FB.api "me/likes?limit=1000&",
+  FB.api "me/likes",
     fields: [
       "id"
     ]
@@ -409,7 +413,6 @@
 ###### get user facebook by id and add him to UserDB and EDGES   #####
 ######################################################################
 getPublicUserInfo = (id, callback) ->
-
   FB.api ""+id,
    (res) ->
      if not res or res.error
--- a/src/pumpio.coffee	Wed Jun 11 02:32:53 2014 +0200
+++ b/src/pumpio.coffee	Wed Jun 11 21:58:41 2014 +0200
@@ -126,8 +126,11 @@
      oauth.get noteurl, token, secret, callback
   ], (err,result) ->
     #console.log 'PUMP BODY:' + result
-    result = JSON.parse(result)
-    callback null, result
+    if err
+      callback null, null
+    else
+      result = JSON.parse(result)
+      callback null, result
   return
 
 isPublicActivity = (act) ->
--- a/src/routes.coffee	Wed Jun 11 02:32:53 2014 +0200
+++ b/src/routes.coffee	Wed Jun 11 21:58:41 2014 +0200
@@ -66,7 +66,7 @@
      #  Pump.postUser(result, 'mgebbe@io.intevation.de','Hallo Welt')
 
     #### GOOGLE STUFF ####
-    if not (gpid?) or not (gptoken?)
+    if not (gpid?) or not (gptoken?) or gpid is "" or gptoken is ""
       console.log 'no google'
     else
       async.waterfall [
@@ -93,15 +93,17 @@
  
 
     #### FACEBOOK STUFF ####
-    if not (fbid?) or not (fbtoken?)
+    if not (fbid?) or not (fbtoken?) or fbid is "" or fbtoken is ""
       console.log 'no facebook'
     else
       # get long-lived token
       # (token is callback function)
       # get the long lived token from facebook
       Facebook.getLongLivedToken fbtoken,(token) ->
-        saveUsermap(pumpid,fbid,token,fbtoken, (err, result) ->
-          console.log 'fbsave.')
+        if (token?)
+          saveUsermap(pumpid,fbid,token,fbtoken, (err, result) ->
+            console.log 'fbsave.')
+
     if (fbdelete?)
       console.log "delete fb account"
       async.waterfall [
--- a/src/sync.coffee	Wed Jun 11 02:32:53 2014 +0200
+++ b/src/sync.coffee	Wed Jun 11 21:58:41 2014 +0200
@@ -76,7 +76,7 @@
   #text='<img src='$PROFILE_PIC_LINK_80x80'></img> <a href='$PROFILE_LINK'>'$PROFILE_NAME'</a> <a href='$POST_LINK'>wrotes</a> at '$POST_TIME':<br><br>'$CONTENT''
 
   if network is 'facebook'
-    if (user.profilePicLink?)
+    if user? and user.profilePicLink?
       profilePicLink = user.profilePicLink.replace("50x50", "80x80")
     else
       profilePicLink = 'http://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/F_icon.svg/80px-F_icon.svg.png'
--- a/src/twitter.coffee	Wed Jun 11 02:32:53 2014 +0200
+++ b/src/twitter.coffee	Wed Jun 11 21:58:41 2014 +0200
@@ -108,7 +108,10 @@
         (callback) ->
           Usermap.search {id: me + '_to_' + me}, callback
         (user, callback) ->
-          Pump.getUserFeed(user[0],callback)
+          if (user[0]?)
+            Pump.getUserFeed(user[0],callback)
+          else
+            return
         (feed, callback) ->
           ti = new Date().getTime() - interval
           async.eachSeries feed.items, ((post, callback) ->
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)