From f5746f490f8151587f054b9d104775f4292184cc Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Wed, 28 Sep 2016 01:38:41 -0300 Subject: [PATCH] Uses higher resolution pictures when importing avatars from Facebook --- lib/auth/facebook_authenticator.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/auth/facebook_authenticator.rb b/lib/auth/facebook_authenticator.rb index 127ec938311..e68aabb3df8 100644 --- a/lib/auth/facebook_authenticator.rb +++ b/lib/auth/facebook_authenticator.rb @@ -1,5 +1,7 @@ class Auth::FacebookAuthenticator < Auth::Authenticator + AVATAR_HEIGHT = 480 + def name "facebook" end @@ -31,7 +33,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator user = result.user if user && (!user.user_avatar || user.user_avatar.custom_upload_id.nil?) 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 @@ -65,7 +68,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator 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 end @@ -130,5 +134,8 @@ class Auth::FacebookAuthenticator < Auth::Authenticator end + def add_avatar_parameters(avatar_url) + "#{avatar_url}?height=#{AVATAR_HEIGHT}" + end end