Skip to content

Instantly share code, notes, and snippets.

@ciberch
Created September 5, 2012 22:07
Show Gist options
  • Save ciberch/3645934 to your computer and use it in GitHub Desktop.
Save ciberch/3645934 to your computer and use it in GitHub Desktop.
var streamLib = require('activity-streams-mongoose')({
mongoUrl: app.siteConf.mongoUrl,
redis: app.siteConf.redisOptions,
defaultActor: defaultAvatar
});
var authentication = new require('./authentication.js')(streamLib, app.siteConf);
// Moved normalization to only be done on pre save
streamLib.types.UserSchema.pre('save', function (next) {
var user = this;
var svcUrl = null;
if (user.fb && user.fb.id) {
user.displayName = "FB: " + user.fb.name.full;
asmsDB.ActivityObject.findOne().where('url', facebookHash.url).exec(function(err, doc){
if (err) throw err;
user.author = doc._id;
// Need to fetch the users image...
https.get({
'host': 'graph.facebook.com'
, 'path': '/me/picture?access_token='+ user.fb.accessToken
}, function(response) {
user.image = {url: response.headers.location};
next();
}).on('error', function(e) {
next();
});
})
} else {
if (user.github && user.github.id) {
user.displayName = "GitHub: " + user.github.name;
var avatar = 'http://1.gravatar.com/avatar/'+ user.github.gravatarId + '?s=48'
user.image = {url: avatar};
svcUrl = githubHash.url;
} else if (user.twit && user.twit.id) {
user.displayName = "Twitter: " + user.twit.name;
user.image = {url: user.twit.profileImageUrl};
svcUrl = twitterHash.url;
}
if(!user.actor) {
asmsDB.ActivityObject.findOne().where('url', svcUrl).exec(function(err, doc){
user.author = doc;
next();
});
} else {
next();
}
}
});
var asmsDB = new streamLib.DB(streamLib.db, streamLib.types);
streamLib.asmsDB = asmsDB;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment