Skip to content

Commit

Permalink
facebook synclet doing photos now
Browse files Browse the repository at this point in the history
  • Loading branch information
quartzjer committed Aug 10, 2011
1 parent 7290b8f commit d9e7c24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 0 additions & 2 deletions synclets/facebook/friends.js
Expand Up @@ -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);
}
21 changes: 14 additions & 7 deletions synclets/facebook/photos.js
Expand Up @@ -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.