diff src/facebook.coffee @ 7:2123f355ab68

go back interval or 15 min, delete credentials, layout
author Mathias Gebbe <mgebbe@intevation.de>
date Wed, 11 Jun 2014 02:32:53 +0200
parents f352c74a6a5b
children 6fd0a307850f
line wrap: on
line diff
--- a/src/facebook.coffee	Sat Jun 07 10:22:12 2014 +0200
+++ b/src/facebook.coffee	Wed Jun 11 02:32:53 2014 +0200
@@ -46,7 +46,7 @@
       getUser(user)
       getStream user,callback
   ], (err, posts) ->
-    return if not (posts?)
+    return if not (posts?) or posts.length is 0
     #console.log JSON.stringify(posts) # all posts from network (100)
     async.eachSeries posts, ((post, callback) ->
 
@@ -54,7 +54,7 @@
         (callback) ->
           FromESN.search {uid: post.id + "@facebook_to_" + me, recipientUser: me}, callback
         (result, callback) ->
-          return if result.length isnt 0 or post.from.id == id
+          return if result.length isnt 0 or post.from.id is id
           #console.log "postid: " + post.from.id + "id:" + id
           # if this is your own post return!!!
           getPublicUserInfo(post.from.id , callback)
@@ -67,10 +67,14 @@
           Pump.postUser bridgeid, me, parsed, callback
         (pumppost, callback) ->
           pumppost = JSON.parse(pumppost)
+          if (post.actions[1].link?)
+            postlink = post.actions[1].link
+          else
+            postlink = post.actions[0].link
           FromESN.create
             postid: post.id + "@facebook"
             sourceUser: post.from.id
-            sourcePost: post.actions[0].link
+            sourcePost: postlink
             pumpPost: pumppost.object.id
             recipientUser: me
             created: Date.now()
@@ -133,9 +137,14 @@
     (user, callback) ->
       Pump.getUserFeed(user[0],callback)
     (feed, callback) ->
+      interval = config.interval
+      if not (interval?)
+        interval =  15 * 60 * 1000 # 900 000 ms (15min)
+      ti = new Date().getTime() - interval
       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 not (post.object.deleted?)
+        ts = Date.parse(post.updated)
+        if (ts >= ti and 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) ->
@@ -236,10 +245,14 @@
 #######################################
 getStream = (user,callback) ->
   token = user.oauth_token
-
+  interval = config.interval
+  if not (interval?)
+    interval =  15 * 60 * 1000 # 900 000 ms (15min)
+  ts = Math.round(((new Date()).getTime() - interval)/1000)
+  
   FB.setAccessToken token
 
-  FB.api "me/home?limit=25&",
+  FB.api "me/home?limit=25&?since="+ts,
     fields: [
       "id"
       "type"
@@ -271,6 +284,7 @@
 #######################################
 postStream = (user, post) ->
   token = user.oauth_token
+  text = ""
 
   FB.setAccessToken token
 
@@ -278,9 +292,10 @@
   ToESN.search {uid: post.object.id + "@facebook"}, (err, result) ->
     if result.length is 0
       body = post.object.content.replace(/<(?:.|\n)*?>/gm, '') + " " + post.object.url
-
+      if post.verb is "share"
+        text = post.object.author.url + " wrotes:"
       FB.api "me/feed", "post",
-        message: body
+        message: text + body
       , (res) ->
         if not res or res.error
           console.log (if not res then "error occurred" else res.error)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)