comparison src/google.coffee @ 25:723eaf36902c

google probs
author Mathias Gebbe <mgebbe@intevation.de>
date Mon, 23 Jun 2014 10:56:29 +0200
parents b90e6df48d2d
children cdbc77880565
comparison
equal deleted inserted replaced
24:08d9679da0f7 25:723eaf36902c
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 async.eachLimit friends, 3, ((friend, callb) ->
47 async.eachLimit friends, 10, ((friend, callback) ->
48 async.waterfall [ 47 async.waterfall [
49 (callback) -> 48 (callback) ->
50 getStream(user, friend, callback) 49 getStream(user, friend, callback)
51 (stream, callback) -> 50 (stream, callback) ->
52 return if not stream? or not stream.items? or stream.items.length is 0 51 return if not stream? or not stream.items? or stream.items.length is 0
53 async.eachLimit stream.items, 10, ((post, cb) -> 52 async.eachLimit stream.items, 10, ((post, cb) ->
54 async.waterfall [ 53 async.waterfall [
55 (callback) -> 54 (callback) ->
55 console.log "check googlepost "+ post.id
56 FromESN.search {uid: post.id + "@google_to_" + me}, callback 56 FromESN.search {uid: post.id + "@google_to_" + me}, callback
57 (result, callback) -> 57 (result, callback) ->
58 return if result.length isnt 0 58 return if result.length isnt 0
59 ti = new Date().getTime() - interval 59 ti = new Date().getTime() - interval
60 ts = Date.parse(post.published) 60 ts = Date.parse(post.published)
61 if (ts >= ti) 61 if (ts >= ti)
62 Sync.postParser post, null, 'google', callback 62 Sync.postParser post, null, 'google', callback
63 else 63 else
64 return 64 return
65 (parsed, callback) -> 65 (parsed, callback) ->
66 console.log "post googlepost "+ post.id
66 Pump.postUser bridgeid, me, parsed, callback 67 Pump.postUser bridgeid, me, parsed, callback
67 (pumppost, callback) -> 68 (pumppost, callback) ->
68 pumppost = JSON.parse(pumppost) 69 pumppost = JSON.parse(pumppost)
69 FromESN.create 70 FromESN.create
70 postid: post.id + "@google" 71 postid: post.id + "@google"
74 recipientUser: me 75 recipientUser: me
75 created: Date.now() 76 created: Date.now()
76 , callback 77 , callback
77 ], (err, result) -> 78 ], (err, result) ->
78 #console.log err 79 #console.log err
79 #console.log result 80 console.log "done"
80 cb() 81 cb()
81 return 82 return
82 ), (err) -> 83 ), (err) ->
83 callback null, 'done' 84 callb()
85 return
84 ], (err, result) -> 86 ], (err, result) ->
85 #console.log 'done.'
86 callback null, 'done'
87 ), (err) -> 87 ), (err) ->
88 if err 88 if err
89 console.log 'one post fail to process' 89 console.log 'one post fail to process'
90 else 90 else
91 console.log 'all google friends processed' 91 console.log 'all google friends processed'
92 return 92 return
93 return 93 return
94 94
95 95
96 ####################################### 96 #######################################
97 ###### get user info googleplus ###### 97 ###### get user info googleplus ######
152 users = JSON.parse(decodeURI(data)) 152 users = JSON.parse(decodeURI(data))
153 return if (users.error?) 153 return if (users.error?)
154 callback null,users 154 callback null,users
155 (users, callback) -> 155 (users, callback) ->
156 #EdgeControl.removeEdges(me,'@google') 156 #EdgeControl.removeEdges(me,'@google')
157 async.eachLimit 10, users.items, ((user,cb) -> 157 async.each users.items, ((user,cb) ->
158 if user.id? 158 if user.id?
159 friends.push(user.id) 159 friends.push(user.id)
160 #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)
161 #EdgeControl.addEdge(me,user.id+'@google') 161 #EdgeControl.addEdge(me,user.id+'@google')
162 cb() 162 cb()
199 data = JSON.parse(data) 199 data = JSON.parse(data)
200 callback null, data 200 callback null, data
201 201
202 ).on "error", (e) -> 202 ).on "error", (e) ->
203 console.log "Got error: " + e.message 203 console.log "Got error: " + e.message
204 return
204 205
205 return 206 return
206 207
207 getRefreshToken = (user, callback) -> 208 getRefreshToken = (user, callback) ->
208 if user.oauth_token.indexOf(';') isnt -1 209 if user.oauth_token.indexOf(';') isnt -1
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)