changeset 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 d2208a4ed5c8
children c552faae9c1c
files public/stylesheets/style.css src/coffeelint.json src/edgecontrol.coffee src/facebook.coffee src/google.coffee src/pumpio.coffee src/routes.coffee src/sync.coffee src/twitter.coffee src/twitterroutes.coffee
diffstat 10 files changed, 167 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/public/stylesheets/style.css	Thu Jun 12 20:58:06 2014 +0200
+++ b/public/stylesheets/style.css	Fri Jun 13 15:18:36 2014 +0200
@@ -67,6 +67,6 @@
 
 .ribbon {
  position: absolute;
- top: 6px;
- left: -25px;
+ top: 0px;
+ left: -40px;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/coffeelint.json	Fri Jun 13 15:18:36 2014 +0200
@@ -0,0 +1,103 @@
+{
+    "arrow_spacing": {
+        "level": "ignore"
+    },
+    "camel_case_classes": {
+        "level": "error"
+    },
+    "coffeescript_error": {
+        "level": "error"
+    },
+    "colon_assignment_spacing": {
+        "level": "ignore",
+        "spacing": {
+            "left": 0,
+            "right": 0
+        }
+    },
+    "cyclomatic_complexity": {
+        "value": 10,
+        "level": "ignore"
+    },
+    "duplicate_key": {
+        "level": "error"
+    },
+    "empty_constructor_needs_parens": {
+        "level": "ignore"
+    },
+    "indentation": {
+        "value": 2,
+        "level": "error"
+    },
+    "line_endings": {
+        "level": "ignore",
+        "value": "unix"
+    },
+    "max_line_length": {
+        "value": 80,
+        "level": "ignore",
+        "limitComments": true
+    },
+    "missing_fat_arrows": {
+        "level": "ignore"
+    },
+    "newlines_after_classes": {
+        "value": 3,
+        "level": "ignore"
+    },
+    "no_backticks": {
+        "level": "error"
+    },
+    "no_debugger": {
+        "level": "warn"
+    },
+    "no_empty_functions": {
+        "level": "ignore"
+    },
+    "no_empty_param_list": {
+        "level": "ignore"
+    },
+    "no_implicit_braces": {
+        "level": "ignore",
+        "strict": true
+    },
+    "no_implicit_parens": {
+        "strict": true,
+        "level": "ignore"
+    },
+    "no_interpolation_in_single_quotes": {
+        "level": "ignore"
+    },
+    "no_plusplus": {
+        "level": "ignore"
+    },
+    "no_stand_alone_at": {
+        "level": "ignore"
+    },
+    "no_tabs": {
+        "level": "error"
+    },
+    "no_throwing_strings": {
+        "level": "error"
+    },
+    "no_trailing_semicolons": {
+        "level": "error"
+    },
+    "no_trailing_whitespace": {
+        "level": "error",
+        "allowed_in_comments": false,
+        "allowed_in_empty_lines": true
+    },
+    "no_unnecessary_double_quotes": {
+        "level": "ignore"
+    },
+    "no_unnecessary_fat_arrows": {
+        "level": "warn"
+    },
+    "non_empty_constructor_needs_parens": {
+        "level": "ignore"
+    },
+    "space_operators": {
+        "level": "ignore"
+    }
+}
--- a/src/edgecontrol.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/edgecontrol.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -47,10 +47,10 @@
      to: to
     , callback
     return
- 
+
   ], (err, result) ->
     return
- 
+
 deleteEdge = (from, to) ->
   async.waterfall [(callback) ->
    bank = Edge.bank()
--- 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      ######
--- a/src/google.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/google.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -49,7 +49,7 @@
         (callback) ->
           getStream(user, friend, callback)
         (stream, callback) ->
-          _.each stream.items, (post) ->
+          async.each stream.items, ((post, cb) ->
             async.waterfall [
               (callback) ->
                 FromESN.search {uid: post.id + "@google_to_" + me, recipientUser: me}, callback
@@ -76,8 +76,9 @@
             ], (err, result) ->
                  #console.log err
                  #console.log result
-          return
-          callback null, null
+                 cb()
+          ), (err) ->
+            callback null, 'done'
       ], (err,  result) ->
         #console.log 'done.'
       callback null, 'done'
@@ -86,7 +87,6 @@
         console.log 'one post fail to process'
       else
         console.log 'all google friends processed'
-      return
   return
 
 
@@ -146,17 +146,22 @@
     res.on "end", () ->
       async.waterfall [
         (callback) ->
-          users = JSON.parse(decodeURI(data))
-          return if (users.error?)
-          callback null,users
+          try
+            users = JSON.parse(decodeURI(data))
+            return if (users.error?)
+            callback null,users
+          catch err
+            console.log 'getFriends error'
+            return
         (users, callback) ->
           EdgeControl.removeEdges(me,'@google')
-          _.each users.items, (user) ->
+          async.each users.items, ((user, cb) ->
             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) ->
+            callback null, friends
       ], (err, friends) ->
         callback null, friends
        return
--- a/src/pumpio.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/pumpio.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -37,9 +37,12 @@
      oauth.get "https://" + server + "/api/user/"+id, token, secret, callback
   ], (err,result) ->
     #console.log 'PUMP BODY:' + result
-    result = JSON.parse(result)
-    id = result.profile.id.substr(result.profile.id.indexOf(':')+1,result.profile.id.length)
-    Routes.updateUserDB(id,result.profile.preferredUsername,result.profile.displayName,result.profile.url,result.profile.image.url)
+    try
+      result = JSON.parse(result)
+      id = result.profile.id.substr(result.profile.id.indexOf(':')+1,result.profile.id.length)
+      Routes.updateUserDB(id,result.profile.preferredUsername,result.profile.displayName,result.profile.url,result.profile.image.url)
+    catch err
+      console.log 'pumpio getUser error' + err
   return
 
 postUser = (bridgeid, to, text, callback) ->
@@ -101,8 +104,12 @@
      oauth.get "https://" + server + "/api/user/"+id+"/feed", token, secret, callback
   ], (err,result) ->
     #console.log 'PUMP BODY:' + result
-    result = JSON.parse(result)
-    callback null, result
+    try
+      result = JSON.parse(result)
+      callback null, result
+    catch err
+      console.log "pump.io Error"
+      callback null, null
   return
 
 #######################################
--- a/src/routes.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/routes.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -47,7 +47,7 @@
     fbid = req.body.fbid
     fbtoken = req.body.fbtoken
     fbdelete = req.body.fbdelete
-  
+
     twdelete = req.body.twdelete
 
     # create/update userdb entrys
@@ -90,7 +90,7 @@
               deleteUsermap(um.id,callback)
             return
        ], (err, result) ->
- 
+
 
     #### FACEBOOK STUFF ####
     if not (fbid?) or not (fbtoken?) or fbid is "" or fbtoken is ""
@@ -128,7 +128,6 @@
             return
        ], (err, result) ->
 
- 
     # go back to main page
     #res.send JSON.stringify(req.body.pumpobj)
     #res.send 'bridge update for:'+ pumpid + '<br>--> ' + gpid + ' ' + gptoken + '<br>--> ' + fbid + ' ' + fbtoken
--- a/src/sync.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/sync.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -32,12 +32,9 @@
       if user.id.indexOf('@facebook') isnt -1
         console.log "start sync for facebook user"
         Facebook.sync(user)
-      return
     ), (err) ->
-      return
   catch err
     console.log 'Error!'
-    return
 
   # Twitter
   try
@@ -45,12 +42,9 @@
       if user.id.indexOf('@twitter') isnt -1
         console.log "start sync for twitter user"
         Twitter.sync(user)
-      return
     ), (err) ->
-      return
   catch err
     console.log 'Error!'
-    return
 
 
   # Google
@@ -59,12 +53,9 @@
       if user.id.indexOf('@google') isnt -1
         console.log "start sync for google user"
         Google.sync(user)
-      return
     ), (err) ->
-      return
   catch err
     console.log 'Error!'
-    return
   ####
   return
 
--- a/src/twitter.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/twitter.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -113,6 +113,7 @@
           else
             return
         (feed, callback) ->
+          return if not feed?
           ti = new Date().getTime() - interval
           async.eachSeries feed.items, ((post, callback) ->
             # do for each post
@@ -123,6 +124,8 @@
                   # post to twitter
                   status = ""
                   text = post.object.content.replace(/<(?:.|\n)*?>/gm, '')
+                  re = new RegExp(String.fromCharCode(160), "g")
+                  text = text.replace(re, " ")
                   if post.verb is "share"
                     status = post.object.author.url + " wrotes: "
                   if text.length <= 140
@@ -151,7 +154,7 @@
           ), (err) ->
             callback null, 'done'
       ],(err, result) ->
-    
+
       ######################################
       # get tweets and post them to pump.io#
       ######################################
@@ -161,7 +164,7 @@
       ).getHomeTimeline {include_rts: true, count: 20 }, (data) ->
         #console.log util.inspect(data)
         ti = (new Date().getTime() - interval)
-        _.each data, (tweet) ->
+        async.each data, ((tweet,cb) ->
           async.waterfall [
             (callback) ->
               FromESN.search {uid: tweet.id + "@twitter_to_" + me, recipientUser: me}, callback
@@ -185,13 +188,11 @@
                 created: Date.now()
               , callback
           ], (err, result) ->
-              #console.log result
-        # end
-        return
+            cb()
+        ), (err) ->
+          return
       return
 
-      return
- 
     parseTwitterDate : (text) ->
 
     getOAuth: (site) ->
--- a/src/twitterroutes.coffee	Thu Jun 12 20:58:06 2014 +0200
+++ b/src/twitterroutes.coffee	Fri Jun 13 15:18:36 2014 +0200
@@ -89,7 +89,7 @@
       return
 
     return
-  
+
   # Routes
   console.log "Initializing Twitter routes"
   app.get "/add-account", userAuth, userRequired, addAccount
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)