Permalink
Browse files

Try not to return anonymous photos in /profile

We were getting anonymous avatars even if you had authed profiles with a real
photo. Now if we can tell there's a real one, we'll use it.
  • Loading branch information...
1 parent a376b7b commit 85c2a49438105fb0d1fba79f97de5107155a5849 @kristjan kristjan committed Sep 1, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/webservice.js
View
16 lib/webservice.js
@@ -198,6 +198,13 @@ hallway.get('/services', function(req, res) {
});
});
+var DEFAULT_AVATARS = [
+ /images.instagram.com\/profiles\/anonymousUser.jpg/, // Instagram
+ /static-ak\/rsrc.php\/v2\/yL\/r\/HsTZSDw4avx.gif/, // FB Male
+ /static-ak\/rsrc.php\/v2\/yp\/r\/yDnr5YfbJCH.gif/, // FB Female
+ /4sqi\.net\/img\/blank_(boy|girl)/, // Foursquare
+ /twimg.com\/sticky\/default_profile_images/ // Twitter
+];
// Simple way to get just a single merged profile view
hallway.get('/profile', function(req, res) {
instruments.increment([
@@ -216,6 +223,7 @@ hallway.get('/profile', function(req, res) {
var ret = {};
ret.id = req._authsome.account;
ret.services = {};
+ var thumbnails = [];
entries.runBases(bases, {}, function(item) {
if(item && item.data && item.data.email) ret.email = item.data.email;
var oembed = dMap.get('oembed',item.data, item.idr);
@@ -229,8 +237,16 @@ hallway.get('/profile', function(req, res) {
Object.keys(oembed).forEach(function(key){
if(!ret[key]) ret[key] = oembed[key]; // copy up unique values
});
+ if (oembed.thumbnail_url) thumbnails.push(oembed.thumbnail_url);
}, function(err) {
if (err) logger.error('error sending results for services',err);
+ thumbnails.forEach(function(thumbnail) {
+ var defaultAvatar = false;
+ DEFAULT_AVATARS.forEach(function(avatar) {
+ if (thumbnail.match(avatar)) defaultAvatar = true;
+ });
+ if (!defaultAvatar) ret.thumbnail_url = thumbnail;
+ });
logger.anubis(req, {count:1});
return res.json(ret);
});

0 comments on commit 85c2a49

Please sign in to comment.