changeset 4:f352c74a6a5b

remove typeof, corrected facebooks toESN entrys
author Mathias Gebbe <mgebbe@intevation.de>
date Fri, 06 Jun 2014 10:18:14 +0200
parents 98a070c98982
children af9f5b94c019
files src/facebook.coffee src/google.coffee src/sync.coffee src/twitter.coffee
diffstat 4 files changed, 31 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/src/facebook.coffee	Thu Jun 05 18:02:25 2014 +0200
+++ b/src/facebook.coffee	Fri Jun 06 10:18:14 2014 +0200
@@ -104,7 +104,7 @@
           (pumpuser, cb) ->
             Pump.getNote(pumpuser[0], fromesn.pumpPost, cb)
           (note, cb) ->
-            if note.liked is not undefined and note.liked is true
+            if note.liked is true
               obj = fromesn.postid.substr(0,fromesn.postid.indexOf('@'))
               postLike(user,obj)
             if (note.replies?)
@@ -135,7 +135,7 @@
     (feed, callback) ->
       async.eachSeries feed.items, ((post, callback) ->
         # do for each post
-        if (post.verb is "post" or post.verb is "share") and (post.object.objectType is "note" or post.object.objectType is "image") and (Pump.isPublicActivity(post)) and (typeof post.object.deleted is "undefined")
+        if (post.verb is "post" or post.verb is "share") and (post.object.objectType is "note" or post.object.objectType is "image") and (Pump.isPublicActivity(post)) and not (post.object.deleted?)
           postStream(user,post)
         callback null, 'done'
       ), (err) ->
@@ -169,9 +169,9 @@
     res.on "end", () ->
       user = JSON.parse(data)
       ### with app id ###
-      Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined"
+      Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) if user?
       ### with link ###
-      Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined"
+      Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) if user?
       return
 
   ).on "error", (e) ->
@@ -199,7 +199,7 @@
       return
 
     _.each res.data, (user) ->
-      getUserById(me,user.uid2,token) unless typeof user.id is "undefined"
+      getUserById(me,user.uid2,token) if user.id?
       return
 
     return
@@ -224,7 +224,7 @@
       console.log (if not res then "error occurred" else res.error)
 
     _.each res.data, (page) ->
-      getUserById(me,page.id,token) unless typeof user.id is "undefined"
+      getUserById(me,page.id,token) if user.id?
       return
 
 
@@ -274,8 +274,8 @@
 
   FB.setAccessToken token
 
-  return if typeof post.object.content  is "undefined" or post.object.content is ""
-  ToESN.search {uid: post.object.id + "@twitter"}, (err, result) ->
+  return if not post.object.content? or post.object.content is ""
+  ToESN.search {uid: post.object.id + "@facebook"}, (err, result) ->
     if result.length is 0
       body = post.object.content.replace(/<(?:.|\n)*?>/gm, '') + " " + post.object.url
 
@@ -289,7 +289,7 @@
         async.waterfall [
           (callback) ->
             savePost = new ToESN()
-            savePost.uid = post.object.id + "@twitter"
+            savePost.uid = post.object.id + "@facebook"
             savePost.sourceUser = post.actor.id
             savePost.sourcePost = post.object.id
             savePost.targetUser = user.user_ESN
@@ -372,16 +372,15 @@
       return
 
     res.on "end", () ->
-      user = JSON.parse(data) unless data isnt "undefined"
+      user = JSON.parse(data) if data?
 
       #### with app user id ###
-      Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined"
-      EdgeControl.addEdge(me,user.id+'@facebook') unless typeof user is "undefined"
-
-      #### with profile url ###
-      Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined"
-      EdgeControl.addEdge(me,user.link) unless typeof user is "undefined"
-
+      if user?
+        Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url)
+        EdgeControl.addEdge(me,user.id+'@facebook')
+        #### with profile url ###
+        Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url)
+        EdgeControl.addEdge(me,user.link)
 
       return
 
--- a/src/google.coffee	Thu Jun 05 18:02:25 2014 +0200
+++ b/src/google.coffee	Fri Jun 06 10:18:14 2014 +0200
@@ -103,7 +103,7 @@
 
     res.on "end", () ->
       user = JSON.parse(data)
-      Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url) unless typeof user.id is "undefined"
+      Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url) if user.id?
 
   ).on "error", (e) ->
     console.log "Got error: " + e.message
@@ -115,7 +115,7 @@
 ###### get google friends        ######
 #######################################
 getFriends = (user, callback) ->
-  return if typeof user is "undefined"
+  return if not user?
   data = ""
   friends = new Array()
   me = user.user_pumpio
@@ -145,9 +145,10 @@
         (users, callback) ->
           EdgeControl.removeEdges(me,'@google')
           _.each users.items, (user) ->
-            friends.push(user.id)
-            Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url) unless typeof user.id is "undefined"
-            EdgeControl.addEdge(me,user.id+'@google') unless typeof user.id is "undefined"
+            if user.id?
+              friends.push(user.id)
+              Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url)
+              EdgeControl.addEdge(me,user.id+'@google')
           callback null, friends
       ], (err, friends) ->
         callback null, friends
--- a/src/sync.coffee	Thu Jun 05 18:02:25 2014 +0200
+++ b/src/sync.coffee	Fri Jun 06 10:18:14 2014 +0200
@@ -86,22 +86,21 @@
 
     if post.type is 'photo'
       parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='"+ post.link + "'> schreibt</a> via " + network + " am " + post.updated_time + ":<br>"
-      parsed += "<br>" + post.message if typeof post.message isnt "undefined"
+      parsed += "<br>" + post.message if post.message? and post.message isnt ""
       parsed += "<br><img src='" + post.picture + "'></img>"
 
     if post.type is 'link' or post.type is 'video'
       parsed = "<img src='" + profilePicLink + "'></img> <a href='" + user.profileLink + "'>" + user.displayName + "</a> <a href='https://www.facebook.com/" + post.id + "'> schreibt</a> via " + network + " am " + post.updated_time + ":<br>"
-      parsed += "<br>" + post.message if typeof post.message isnt "undefined"
-      parsed += "<br>" + post.description if typeof post.description isnt "undefined"
-      parsed +=  "<br><a href='" + post.link + "'>"+ post.link + "</a>" if typeof post.link isnt "undefined"
-      parsed += "<br><img src='" + post.picture + "'></img>" if typeof post.picture isnt "undefined"
-
+      parsed += "<br>" + post.message if post.message? and post.message isnt ""
+      parsed += "<br>" + post.description if post.description?
+      parsed +=  "<br><a href='" + post.link + "'>"+ post.link + "</a>" if post.link?
+      parsed += "<br><img src='" + post.picture + "'></img>" if post.picture?
 
     callback null, parsed
 
   if network is 'google'
     parsed = "<img src='" + post.actor.image.url + "'></img> <a href='" + post.actor.url + "'>" + post.actor.displayName + "</a> <a href='"+ post.object.url + "'> schreibt</a> via " + network + " am " + post.updated + ":<br><br>" + post.object.content
-    if typeof post.object.attachments isnt "undefined"
+    if not post.object.attachments?
       _.each post.object.attachments, (attachment) ->
 
         if attachment.objectType == "photo"
@@ -109,12 +108,12 @@
 
         if attachment.objectType == "article"
           parsed +=  "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>"
-          if typeof attachment.image isnt "undefined"
+          if not attachment.image?
             parsed += "<br><img src='" + attachment.image.url + "'></img>"
 
         if attachment.objectType == "video"
           parsed +=  "<br><a href='" + attachment.url + "'>"+ attachment.displayName + "</a>"
-          if typeof attachment.image isnt "undefined"
+          if not attachment.image?
             parsed += "<br><img src='" + attachment.image.url + "'></img>"
 
     callback null, parsed
--- a/src/twitter.coffee	Thu Jun 05 18:02:25 2014 +0200
+++ b/src/twitter.coffee	Fri Jun 06 10:18:14 2014 +0200
@@ -86,7 +86,6 @@
 
     sync: (user) ->
       me = user.user_pumpio
-      id = user.user_ESN.substr(0,user.user_ESN.indexOf('@'))
       token = user.oauth_token
       secret = user.extra_token
       util = require("util")
@@ -98,13 +97,6 @@
         access_token_secret: secret
       )
 
-      #twit.verifyCredentials((data) ->
-      #  console.log util.inspect(data)
-      #  return
-      #).updateStatus "Test tweet from pumpbridge using " + twitter.VERSION, (data) ->
-      #  console.log util.inspect(data)
-      #  return
-
       # GET PUBLIC PUMP POSTS AND POST THEM
       async.waterfall [
         (callback) ->
@@ -117,6 +109,7 @@
             if (post.verb is "post" or post.verb is "share") and (post.object.objectType is "note" or post.object.objectType is "image") and (Pump.isPublicActivity(post)) and (typeof post.object.deleted is "undefined")
               ToESN.search {uid: post.object.id + "@twitter"}, (err, result) ->
                 if result.length is 0
+                  # post to twitter
                   text = post.object.content.replace(/<(?:.|\n)*?>/gm, '')
                   status = ""
                   if text.length <= 140
@@ -145,7 +138,6 @@
           ), (err) ->
             callback null, 'done'
       ],(err, result) ->
-            #console.log 'done.'
     
       return
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)