Mercurial > pumpbridge
diff src/facebook.coffee @ 17:a52b5b244e51
removed unnecessary underscore and replaced it with async
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Fri, 13 Jun 2014 15:18:36 +0200 |
parents | c1b736a859c9 |
children | b90e6df48d2d |
line wrap: on
line diff
--- a/src/facebook.coffee Thu Jun 12 20:58:06 2014 +0200 +++ b/src/facebook.coffee Fri Jun 13 15:18:36 2014 +0200 @@ -46,7 +46,7 @@ getUser(user) getStream user,callback ], (err, posts) -> - return if not (posts?) or posts.length is 0 + 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 [ @@ -68,11 +68,9 @@ (parsed, callback) -> Pump.postUser bridgeid, me, parsed, callback (pumppost, callback) -> + return if not pumppost? or not post.actions[0]? pumppost = JSON.parse(pumppost) - if (post.actions[1].link?) - postlink = post.actions[1].link - else - postlink = post.actions[0].link + postlink = post.actions[0].link FromESN.create postid: post.id + "@facebook" sourceUser: post.from.id @@ -82,8 +80,6 @@ created: Date.now() , callback ], (err, result) -> - #console.log result - #console.log 'done.' callback null, 'done' ), (err) -> if err @@ -213,10 +209,12 @@ if not res or res.error console.log (if not res then "error occurred" else res.error) - _.each res.data, (person) -> + async.each res.data, ((person, cb) -> getUserById(me,person.id,token) + cb() return - + ), (err) -> + return return ####################################### @@ -267,10 +265,12 @@ console.log (if not res then "error occurred" else res.error) return - _.each res.data, (user) -> + async.each res.data, ((user, cb) -> getUserById(me,user.uid2,token) + cb() return - + ), (err) -> + return return return @@ -293,10 +293,12 @@ if not res or res.error console.log (if not res then "error occurred" else res.error) - _.each res.data, (page) -> + async.each res.data, ((page,cb) -> getUserById(me,page.id,token) + cb() return - + ), (err) -> + return return @@ -312,7 +314,7 @@ FB.setAccessToken token - FB.api "me/home?limit=35&?since="+ts, + FB.api "me/home?limit=10&?since="+ts, fields: [ "id" "type" @@ -334,10 +336,14 @@ callback null, null newposts = new Array() - _.each res.data, (post) -> + async.each res.data, ((post,cb) -> newposts.push(post) if (post.type is 'status' or post.type is 'photo' or post.type is 'link' or post.type is 'video') and (post.status_type is 'mobile_status_update' or post.status_type is 'added_photos' or post.status_type is 'shared_story') - - callback null, newposts.reverse() + cb() + return + ), (err) -> + callback null, newposts.reverse() + return + return ####################################### ###### post facebook stream ######