The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/server/methods/getAvatarSuggestion.coffee

79 lines
2.5 KiB

@getAvatarSuggestionForUser = (user) ->
9 years ago
check user, Object
avatars = []
if user.services.facebook?.id? and RocketChat.settings.get 'Accounts_OAuth_Facebook'
avatars.push
service: 'facebook'
url: "https://graph.facebook.com/#{user.services.facebook.id}/picture?type=large"
if user.services.google?.picture? and user.services.google.picture isnt "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg" and RocketChat.settings.get 'Accounts_OAuth_Google'
avatars.push
service: 'google'
url: user.services.google.picture
if user.services.github?.username? and RocketChat.settings.get 'Accounts_OAuth_Github'
avatars.push
service: 'github'
url: "https://avatars.githubusercontent.com/#{user.services.github.username}?s=200"
if user.services.linkedin?.pictureUrl? and RocketChat.settings.get 'Accounts_OAuth_Linkedin'
avatars.push
service: 'linkedin'
url: user.services.linkedin.pictureUrl
if user.services.twitter?.profile_image_url_https? and RocketChat.settings.get 'Accounts_OAuth_Twitter'
avatars.push
service: 'twitter'
url: user.services.twitter.profile_image_url_https
if user.services.gitlab?.avatar_url? and RocketChat.settings.get 'Accounts_OAuth_Gitlab'
avatars.push
service: 'gitlab'
url: user.services.gitlab.avatar_url
if user.services.sandstorm?.picture? and Meteor.settings.public.sandstorm
avatars.push
service: 'sandstorm'
url: user.services.sandstorm.picture
if user.emails?.length > 0
for email in user.emails when email.verified is true
avatars.push
service: 'gravatar'
url: Gravatar.imageUrl(email.address, {default: '404', size: 200, secure: true})
for email in user.emails when email.verified isnt true
avatars.push
service: 'gravatar'
url: Gravatar.imageUrl(email.address, {default: '404', size: 200, secure: true})
validAvatars = {}
for avatar in avatars
try
result = HTTP.get avatar.url, npmRequestOptions: {encoding: 'binary'}
if result.statusCode is 200
blob = "data:#{result.headers['content-type']};base64,"
blob += Buffer(result.content, 'binary').toString('base64')
avatar.blob = blob
avatar.contentType = result.headers['content-type']
validAvatars[avatar.service] = avatar
catch e
# ...
return validAvatars
Meteor.methods
getAvatarSuggestion: ->
if not Meteor.userId()
Close #2727 Change meteor error (#3040) * Add function to handle errors * Delete message errors * handle error for hideRoom * Allow returning error instead of calling toastr.error * Handle error for leaveRoom * handle error for openRoom * handleError for toggleFavorite * handleError in updateMessage * error for samlLogout * handleError for assets * Add global handleError to eslint * handleError for addOAuthService * handleError: getUserRoles * handleError: insertOrUpdateUsere * handleError: messageDeleting * handleError: removeUserFromRoles * handleError: addPermissionToRole * handleError: addUserToRole * handleError: deleteRole * handleError: removeRoleFromPermission * handleError: removeUserFromRole * handleError: saveRole * Return ready on publish without permission * handleError: channel-settings * handleError: mailMessages * handleError: fileUpload * handleError: rocketchat-importer * handleError: addIncomingIntegration * handleError: deleteIncomingIntegration * handleError: updateIncomingIntegration * handleError: addOutgoingIntegration * handleError: deleteOutgoingIntegration * handleError: updateOutgoingIntegration * Return ready on publish without permission * handleError ldap * remove throw from client code * handleError: setEmail, slashCommand * Sort en.i18n.json * Google translated languages * Use correct error return from publishes * RateLimiter.limitFunction * Fix order of error "500" * handleError validateEmailDomain * handleError channelSettings; settings * handleError livechat * handleError: Mailer.sendMail * handleError pinMessage and unpinMessage * handleError messageStarring * handleError oauth apps * handleError: saveNotificationSettings * handleError getRoomRoles * handleError: createDirectMessage * handleError saveUserPreferences * handleError: saveUserProfile * handleError sendConfirmationEmail * Add ecmascript to root * handleError: avatar * handleError: getStatistics * handleError: roomSetting * handleError: channelSettings * handleError: sendInvitationEmail * handleError: addUserToRoom * handleError: uploadedFilesList * Change error key on user edit * handleError: userInfo * handleError: userRegistration * handleError: createChannel * handleError: createPrivateGroup * handleError: setUserPassword * handleError setUserActiveStatus * handleError: accoutns * A few more errors thrown * Error: livechat publishes * Errors in methods * handleError searchAgent * Add errors handling More errors handling Auto-translation for all languages * Permalink
10 years ago
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'getAvatarSuggestion' }
@unblock()
user = Meteor.user()
getAvatarSuggestionForUser user