Permalink
Browse files

facebook synclet doing photos now

  • Loading branch information...
quartzjer committed Aug 10, 2011
1 parent 7290b8f commit d9e7c247ac863090f3b31a63141281f9539b0c5b
Showing with 14 additions and 9 deletions.
  1. +0 −2 synclets/facebook/friends.js
  2. +14 −7 synclets/facebook/photos.js
@@ -17,14 +17,12 @@ exports.sync = function(processInfo, cb) {
if (err) console.error(err);
var responseObj = {data : {}};
responseObj.data.contact = contacts;
- console.error("sending "+contacts.length);
cb(err, responseObj);
});
};
exports.syncFriends = function(callback) {
fb.getFriends({id:"me"},function(friend){
contacts.push({'obj' : friend, timestamp: new Date(), type : 'new'});
- console.error("friend: "+friend.id);
},callback);
}
@@ -8,21 +8,28 @@
*/
var fb = require('../../Connectors/Facebook/lib.js')
- , contacts = []
+ , async = require('async')
+ , photos = []
;
exports.sync = function(processInfo, cb) {
fb.init(processInfo.auth);
- exports.syncFriends(function(err) {
+ exports.syncPhotos(function(err) {
if (err) console.error(err);
var responseObj = {data : {}};
- responseObj.data.contact = contacts;
+ responseObj.data.photo = photos;
cb(err, responseObj);
});
};
-exports.syncFriends = function(callback) {
- fb.getFriends({id:"me"},function(friend){
- contacts.push({'obj' : friend, timestamp: new Date(), type : 'new'});
- },callback);
+exports.syncPhotos = function(callback) {
+ // use a queue so we know when all the albums are done individually async'ly processing
+ var albums = [];
+ fb.getAlbums({id:"me"},function(album){albums.push(album);},function(){
+ async.forEach(albums,function(album,cbDone){
+ fb.getAlbum({id:album.id},function(photo){
+ photos.push({'obj' : photo, timestamp: new Date(), type : 'new'});
+ },cbDone);
+ },callback);
+ });
}

0 comments on commit d9e7c24

Please sign in to comment.