Mercurial > pumpbridge
comparison src/google.coffee @ 18:c552faae9c1c
removed unnecessary parts, fixed getFriends async.each
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Fri, 13 Jun 2014 16:37:20 +0200 |
parents | a52b5b244e51 |
children | 6b3f38af3fa4 |
comparison
equal
deleted
inserted
replaced
17:a52b5b244e51 | 18:c552faae9c1c |
---|---|
38 async.waterfall [ | 38 async.waterfall [ |
39 (callback) -> | 39 (callback) -> |
40 updateToken(user,callback) | 40 updateToken(user,callback) |
41 (updateuser,callback) -> | 41 (updateuser,callback) -> |
42 user = updateuser | 42 user = updateuser |
43 getUser(user) | 43 #getUser(user) |
44 getFriends(user,callback) | 44 getFriends(user,callback) |
45 ], (err, friends) -> | 45 ], (err, friends) -> |
46 # für jeden Freunde tue dies: hier bewusst von async.eachSeries friends, ((friend, callback) -> auf async.each gewechselt | 46 # für jeden Freunde tue dies: hier bewusst von async.eachSeries friends, ((friend, callback) -> auf async.each gewechselt |
47 async.each friends, ((friend, callback) -> | 47 async.each friends, ((friend, callback) -> |
48 async.waterfall [ | 48 async.waterfall [ |
49 (callback) -> | 49 (callback) -> |
50 getStream(user, friend, callback) | 50 getStream(user, friend, callback) |
51 (stream, callback) -> | 51 (stream, callback) -> |
52 return if not stream? | |
52 async.each stream.items, ((post, cb) -> | 53 async.each stream.items, ((post, cb) -> |
53 async.waterfall [ | 54 async.waterfall [ |
54 (callback) -> | 55 (callback) -> |
55 FromESN.search {uid: post.id + "@google_to_" + me, recipientUser: me}, callback | 56 FromESN.search {uid: post.id + "@google_to_" + me, recipientUser: me}, callback |
56 (result, callback) -> | 57 (result, callback) -> |
75 , callback | 76 , callback |
76 ], (err, result) -> | 77 ], (err, result) -> |
77 #console.log err | 78 #console.log err |
78 #console.log result | 79 #console.log result |
79 cb() | 80 cb() |
81 return | |
80 ), (err) -> | 82 ), (err) -> |
81 callback null, 'done' | 83 callback null, 'done' |
82 ], (err, result) -> | 84 ], (err, result) -> |
83 #console.log 'done.' | 85 #console.log 'done.' |
84 callback null, 'done' | 86 callback null, 'done' |
85 ), (err) -> | 87 ), (err) -> |
86 if err | 88 if err |
87 console.log 'one post fail to process' | 89 console.log 'one post fail to process' |
88 else | 90 else |
89 console.log 'all google friends processed' | 91 console.log 'all google friends processed' |
92 return | |
90 return | 93 return |
91 | 94 |
92 | 95 |
93 ####################################### | 96 ####################################### |
94 ###### get user info googleplus ###### | 97 ###### get user info googleplus ###### |
144 data +=chunk | 147 data +=chunk |
145 | 148 |
146 res.on "end", () -> | 149 res.on "end", () -> |
147 async.waterfall [ | 150 async.waterfall [ |
148 (callback) -> | 151 (callback) -> |
149 try | 152 users = JSON.parse(decodeURI(data)) |
150 users = JSON.parse(decodeURI(data)) | 153 return if (users.error?) |
151 return if (users.error?) | 154 callback null,users |
152 callback null,users | |
153 catch err | |
154 console.log 'getFriends error' | |
155 return | |
156 (users, callback) -> | 155 (users, callback) -> |
157 EdgeControl.removeEdges(me,'@google') | 156 #EdgeControl.removeEdges(me,'@google') |
158 async.each users.items, ((user, cb) -> | 157 async.each users.items, ((user,cb) -> |
159 if user.id? | 158 if user.id? |
160 friends.push(user.id) | 159 friends.push(user.id) |
161 Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url) | 160 #Routes.updateUserDB(user.id+'@google',user.displayName,user.displayName,user.url,user.image.url) |
162 EdgeControl.addEdge(me,user.id+'@google') | 161 #EdgeControl.addEdge(me,user.id+'@google') |
163 ), (err) -> | 162 cb() |
164 callback null, friends | 163 ), (err) -> |
164 callback null, friends | |
165 ], (err, friends) -> | 165 ], (err, friends) -> |
166 callback null, friends | 166 callback null, friends |
167 return | 167 return |
168 | 168 |
169 ).on "error", (e) -> | 169 ).on "error", (e) -> |