3 var User
= require('gitter-web-persistence').User
;
4 var isGitHubUsername
= require('gitter-web-identity/lib/is-github-username');
5 var utils
= require('./utils');
7 module
.exports = function(username
, size
) {
8 return User
.findOne({ username
: username
}, { _id
: 0, gravatarImageUrl
: 1 }, { lean
: true }).then(
10 if (!doc
|| !doc
.gravatarImageUrl
) {
11 // We don't know who this user is. Just fallback to GitHub for now
13 url
: 'https://avatars.githubusercontent.com/' + username
+ '?s=' + size
,
14 longTermCachable
: true
18 if (isGitHubUsername(username
)) {
20 url
: utils
.addSizeParam(doc
.gravatarImageUrl
, 's', size
),
21 longTermCachable
: true
25 // TODO: Deal with twitter users better (for example sizes etc)
26 // Currently, twitter users will 404 if you add a ?s= to the url
28 url
: doc
.gravatarImageUrl
,
29 longTermCachable
: true