Mercurial > pumpbridge
comparison src/facebook.coffee @ 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 | 2123f355ab68 |
comparison
equal
deleted
inserted
replaced
3:98a070c98982 | 4:f352c74a6a5b |
---|---|
102 cb (true) if fromesn.sourcePost.indexOf('www.facebook.com') is -1 | 102 cb (true) if fromesn.sourcePost.indexOf('www.facebook.com') is -1 |
103 Usermap.search {id: me + '_to_' + me}, cb | 103 Usermap.search {id: me + '_to_' + me}, cb |
104 (pumpuser, cb) -> | 104 (pumpuser, cb) -> |
105 Pump.getNote(pumpuser[0], fromesn.pumpPost, cb) | 105 Pump.getNote(pumpuser[0], fromesn.pumpPost, cb) |
106 (note, cb) -> | 106 (note, cb) -> |
107 if note.liked is not undefined and note.liked is true | 107 if note.liked is true |
108 obj = fromesn.postid.substr(0,fromesn.postid.indexOf('@')) | 108 obj = fromesn.postid.substr(0,fromesn.postid.indexOf('@')) |
109 postLike(user,obj) | 109 postLike(user,obj) |
110 if (note.replies?) | 110 if (note.replies?) |
111 reply = JSON.stringify(note.replies) | 111 reply = JSON.stringify(note.replies) |
112 rep = JSON.parse(reply) | 112 rep = JSON.parse(reply) |
133 (user, callback) -> | 133 (user, callback) -> |
134 Pump.getUserFeed(user[0],callback) | 134 Pump.getUserFeed(user[0],callback) |
135 (feed, callback) -> | 135 (feed, callback) -> |
136 async.eachSeries feed.items, ((post, callback) -> | 136 async.eachSeries feed.items, ((post, callback) -> |
137 # do for each post | 137 # do for each post |
138 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") | 138 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?) |
139 postStream(user,post) | 139 postStream(user,post) |
140 callback null, 'done' | 140 callback null, 'done' |
141 ), (err) -> | 141 ), (err) -> |
142 callback null, 'done' | 142 callback null, 'done' |
143 ],(err, result) -> | 143 ],(err, result) -> |
167 return | 167 return |
168 | 168 |
169 res.on "end", () -> | 169 res.on "end", () -> |
170 user = JSON.parse(data) | 170 user = JSON.parse(data) |
171 ### with app id ### | 171 ### with app id ### |
172 Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined" | 172 Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) if user? |
173 ### with link ### | 173 ### with link ### |
174 Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined" | 174 Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) if user? |
175 return | 175 return |
176 | 176 |
177 ).on "error", (e) -> | 177 ).on "error", (e) -> |
178 console.log "Got error: " + e.message | 178 console.log "Got error: " + e.message |
179 | 179 |
197 if not res or res.error | 197 if not res or res.error |
198 console.log (if not res then "error occurred" else res.error) | 198 console.log (if not res then "error occurred" else res.error) |
199 return | 199 return |
200 | 200 |
201 _.each res.data, (user) -> | 201 _.each res.data, (user) -> |
202 getUserById(me,user.uid2,token) unless typeof user.id is "undefined" | 202 getUserById(me,user.uid2,token) if user.id? |
203 return | 203 return |
204 | 204 |
205 return | 205 return |
206 | 206 |
207 return | 207 return |
222 , (res) -> | 222 , (res) -> |
223 if not res or res.error | 223 if not res or res.error |
224 console.log (if not res then "error occurred" else res.error) | 224 console.log (if not res then "error occurred" else res.error) |
225 | 225 |
226 _.each res.data, (page) -> | 226 _.each res.data, (page) -> |
227 getUserById(me,page.id,token) unless typeof user.id is "undefined" | 227 getUserById(me,page.id,token) if user.id? |
228 return | 228 return |
229 | 229 |
230 | 230 |
231 return | 231 return |
232 | 232 |
272 postStream = (user, post) -> | 272 postStream = (user, post) -> |
273 token = user.oauth_token | 273 token = user.oauth_token |
274 | 274 |
275 FB.setAccessToken token | 275 FB.setAccessToken token |
276 | 276 |
277 return if typeof post.object.content is "undefined" or post.object.content is "" | 277 return if not post.object.content? or post.object.content is "" |
278 ToESN.search {uid: post.object.id + "@twitter"}, (err, result) -> | 278 ToESN.search {uid: post.object.id + "@facebook"}, (err, result) -> |
279 if result.length is 0 | 279 if result.length is 0 |
280 body = post.object.content.replace(/<(?:.|\n)*?>/gm, '') + " " + post.object.url | 280 body = post.object.content.replace(/<(?:.|\n)*?>/gm, '') + " " + post.object.url |
281 | 281 |
282 FB.api "me/feed", "post", | 282 FB.api "me/feed", "post", |
283 message: body | 283 message: body |
287 return | 287 return |
288 | 288 |
289 async.waterfall [ | 289 async.waterfall [ |
290 (callback) -> | 290 (callback) -> |
291 savePost = new ToESN() | 291 savePost = new ToESN() |
292 savePost.uid = post.object.id + "@twitter" | 292 savePost.uid = post.object.id + "@facebook" |
293 savePost.sourceUser = post.actor.id | 293 savePost.sourceUser = post.actor.id |
294 savePost.sourcePost = post.object.id | 294 savePost.sourcePost = post.object.id |
295 savePost.targetUser = user.user_ESN | 295 savePost.targetUser = user.user_ESN |
296 savePost.targetPost = res.id | 296 savePost.targetPost = res.id |
297 savePost.recipientUser = 'public' | 297 savePost.recipientUser = 'public' |
370 res.on "data", (chunk) -> | 370 res.on "data", (chunk) -> |
371 data += chunk | 371 data += chunk |
372 return | 372 return |
373 | 373 |
374 res.on "end", () -> | 374 res.on "end", () -> |
375 user = JSON.parse(data) unless data isnt "undefined" | 375 user = JSON.parse(data) if data? |
376 | 376 |
377 #### with app user id ### | 377 #### with app user id ### |
378 Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined" | 378 if user? |
379 EdgeControl.addEdge(me,user.id+'@facebook') unless typeof user is "undefined" | 379 Routes.updateUserDB(user.id+'@facebook',user.name,user.name,user.link,user.picture.data.url) |
380 | 380 EdgeControl.addEdge(me,user.id+'@facebook') |
381 #### with profile url ### | 381 #### with profile url ### |
382 Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) unless typeof user is "undefined" | 382 Routes.updateUserDB(user.link,user.name,user.name,user.link,user.picture.data.url) |
383 EdgeControl.addEdge(me,user.link) unless typeof user is "undefined" | 383 EdgeControl.addEdge(me,user.link) |
384 | |
385 | 384 |
386 return | 385 return |
387 | 386 |
388 ).on "error", (e) -> | 387 ).on "error", (e) -> |
389 console.log "Got error: " + e.message | 388 console.log "Got error: " + e.message |