Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / api / private / avatars / user-by-username.js
blob712a72d3279546bb99f4b9e33f6f95de91689af8
1 'use strict';
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(
9 function(doc) {
10 if (!doc || !doc.gravatarImageUrl) {
11 // We don't know who this user is. Just fallback to GitHub for now
12 return {
13 url: 'https://avatars.githubusercontent.com/' + username + '?s=' + size,
14 longTermCachable: true
18 if (isGitHubUsername(username)) {
19 return {
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
27 return {
28 url: doc.gravatarImageUrl,
29 longTermCachable: true