Uses higher resolution pictures when importing avatars from Facebook

This commit is contained in:
Rafael dos Santos Silva 2016-09-28 01:38:41 -03:00
parent 214056e782
commit f5746f490f

View File

@ -1,5 +1,7 @@
class Auth::FacebookAuthenticator < Auth::Authenticator class Auth::FacebookAuthenticator < Auth::Authenticator
AVATAR_HEIGHT = 480
def name def name
"facebook" "facebook"
end end
@ -31,7 +33,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
user = result.user user = result.user
if user && (!user.user_avatar || user.user_avatar.custom_upload_id.nil?) if user && (!user.user_avatar || user.user_avatar.custom_upload_id.nil?)
if (avatar_url = facebook_hash[:avatar_url]).present? if (avatar_url = facebook_hash[:avatar_url]).present?
UserAvatar.import_url_for_user(avatar_url, user, override_gravatar: false) avatar_url_with_parameters = add_avatar_parameters(avatar_url)
UserAvatar.import_url_for_user(avatar_url_with_parameters, user, override_gravatar: false)
end end
end end
@ -65,7 +68,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
if (avatar_url = data[:avatar_url]).present? if (avatar_url = data[:avatar_url]).present?
UserAvatar.import_url_for_user(avatar_url, user) avatar_url_with_parameters = add_avatar_parameters(avatar_url)
UserAvatar.import_url_for_user(avatar_url_with_parameters, user)
user.save user.save
end end
@ -130,5 +134,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator
end end
def add_avatar_parameters(avatar_url)
"#{avatar_url}?height=#{AVATAR_HEIGHT}"
end
end end