3 var _ = require('lodash');
4 var BackendMuxer = require('gitter-web-backend-muxer');
6 function UserProfileStrategy(/* options */) {
10 this.preload = function(users) {
11 var length = users.size();
12 if (length === 0) return;
14 throw new Error('User profile serializer can only load a single profile at a time');
18 var backendMuxer = new BackendMuxer(user);
19 return backendMuxer.findProfiles(profileResults).then(function(profiles) {
20 profileResults = profiles;
21 // cache the profiles so we can get them out later.
22 // (is this the best variable name?)
24 // A hash would probably we better for this
25 user.profiles = profiles;
29 this.map = function(_user) {
30 if (user !== _user) return;
34 username: user.username,
35 displayName: user.displayName,
36 removed: user.state === 'REMOVED' || undefined, // isRemoved?
37 has_gitter_login: true // by definition
40 // Provider is just the one that matched and we prefer the avatar in the
41 // database over what's coming from the API so that it is easier to reuse
42 // gravatarVersion for github users.
43 _.extend(profile, _.omit(user.profiles[0], ['provider', 'gravatarImageUrl']));
45 if (user.gravatarVersion) {
47 profile.gv = user.gravatarVersion;
50 profile.gravatarImageUrl = user.gravatarImageUrl;
57 UserProfileStrategy.prototype = {
58 name: 'UserProfileStrategy'
61 module.exports = UserProfileStrategy;