Mercurial > pumpbridge
comparison src/facebook.coffee @ 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 | ccf1d9e741bd |
comparison
equal
deleted
inserted
replaced
7:2123f355ab68 | 8:6fd0a307850f |
---|---|
47 getStream user,callback | 47 getStream user,callback |
48 ], (err, posts) -> | 48 ], (err, posts) -> |
49 return if not (posts?) or posts.length is 0 | 49 return if not (posts?) or posts.length is 0 |
50 #console.log JSON.stringify(posts) # all posts from network (100) | 50 #console.log JSON.stringify(posts) # all posts from network (100) |
51 async.eachSeries posts, ((post, callback) -> | 51 async.eachSeries posts, ((post, callback) -> |
52 | |
53 async.waterfall [ | 52 async.waterfall [ |
54 (callback) -> | 53 (callback) -> |
55 FromESN.search {uid: post.id + "@facebook_to_" + me, recipientUser: me}, callback | 54 FromESN.search {uid: post.id + "@facebook_to_" + me, recipientUser: me}, callback |
56 (result, callback) -> | 55 (result, callback) -> |
57 return if result.length isnt 0 or post.from.id is id | 56 return if result.length isnt 0 or post.from.id is id |
60 getPublicUserInfo(post.from.id , callback) | 59 getPublicUserInfo(post.from.id , callback) |
61 (pubuser, callback) -> | 60 (pubuser, callback) -> |
62 pubuser = pubuser | 61 pubuser = pubuser |
63 User.search {id: pubuser.id + "@facebook"}, callback | 62 User.search {id: pubuser.id + "@facebook"}, callback |
64 (dbuser, callback) -> | 63 (dbuser, callback) -> |
65 Sync.postParser post, dbuser[0], 'facebook', callback | 64 if (dbuser[0]?) |
65 Sync.postParser post, dbuser[0], 'facebook', callback | |
66 else | |
67 return | |
66 (parsed, callback) -> | 68 (parsed, callback) -> |
67 Pump.postUser bridgeid, me, parsed, callback | 69 Pump.postUser bridgeid, me, parsed, callback |
68 (pumppost, callback) -> | 70 (pumppost, callback) -> |
69 pumppost = JSON.parse(pumppost) | 71 pumppost = JSON.parse(pumppost) |
70 if (post.actions[1].link?) | 72 if (post.actions[1].link?) |
101 FromESN.search {recipientUser: me}, callback | 103 FromESN.search {recipientUser: me}, callback |
102 (allESN, callback) -> | 104 (allESN, callback) -> |
103 async.each allESN, ((fromesn, callback) -> | 105 async.each allESN, ((fromesn, callback) -> |
104 async.waterfall [ | 106 async.waterfall [ |
105 (cb) -> | 107 (cb) -> |
106 cb (true) if fromesn.sourcePost.indexOf('www.facebook.com') is -1 | 108 if fromesn.sourcePost.indexOf('www.facebook.com') is -1 |
109 return | |
107 Usermap.search {id: me + '_to_' + me}, cb | 110 Usermap.search {id: me + '_to_' + me}, cb |
108 (pumpuser, cb) -> | 111 (pumpuser, cb) -> |
109 Pump.getNote(pumpuser[0], fromesn.pumpPost, cb) | 112 Pump.getNote(pumpuser[0], fromesn.pumpPost, cb) |
110 (note, cb) -> | 113 (note, cb) -> |
114 return if not (note?) | |
111 if note.liked is true | 115 if note.liked is true |
112 obj = fromesn.postid.substr(0,fromesn.postid.indexOf('@')) | 116 obj = fromesn.postid.substr(0,fromesn.postid.indexOf('@')) |
113 postLike(user,obj) | 117 postLike(user,obj) |
114 if (note.replies?) | 118 if (note.replies?) |
115 reply = JSON.stringify(note.replies) | 119 reply = JSON.stringify(note.replies) |
222 me = user.user_pumpio | 226 me = user.user_pumpio |
223 token = user.oauth_token | 227 token = user.oauth_token |
224 | 228 |
225 FB.setAccessToken token | 229 FB.setAccessToken token |
226 | 230 |
227 FB.api "me/likes?limit=1000&", | 231 FB.api "me/likes", |
228 fields: [ | 232 fields: [ |
229 "id" | 233 "id" |
230 ] | 234 ] |
231 , (res) -> | 235 , (res) -> |
232 if not res or res.error | 236 if not res or res.error |
407 | 411 |
408 ###################################################################### | 412 ###################################################################### |
409 ###### get user facebook by id and add him to UserDB and EDGES ##### | 413 ###### get user facebook by id and add him to UserDB and EDGES ##### |
410 ###################################################################### | 414 ###################################################################### |
411 getPublicUserInfo = (id, callback) -> | 415 getPublicUserInfo = (id, callback) -> |
412 | |
413 FB.api ""+id, | 416 FB.api ""+id, |
414 (res) -> | 417 (res) -> |
415 if not res or res.error | 418 if not res or res.error |
416 console.log (if not res then "error occurred" else res.error) | 419 console.log (if not res then "error occurred" else res.error) |
417 callback null,res | 420 callback null,res |