From 563da0e05247bc0a8e7fd6f39b7a0b5669839200 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 13 Nov 2020 19:56:30 +0530 Subject: [PATCH] feat: Use gravatar URL for contacts and users if no image available (#1407) --- app/models/concerns/avatarable.rb | 11 +++++++---- app/models/user.rb | 9 --------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/models/concerns/avatarable.rb b/app/models/concerns/avatarable.rb index c65fbe3fe..a44beb28b 100644 --- a/app/models/concerns/avatarable.rb +++ b/app/models/concerns/avatarable.rb @@ -9,10 +9,13 @@ module Avatarable end def avatar_url - if avatar.attached? && avatar.representable? - url_for(avatar.representation(resize: '250x250')) - else - '' + return url_for(avatar.representation(resize: '250x250')) if avatar.attached? && avatar.representable? + + if [User, Contact].include?(self.class) && email.present? + hash = Digest::MD5.hexdigest(email) + return "https://www.gravatar.com/avatar/#{hash}?d=404" end + + '' end end diff --git a/app/models/user.rb b/app/models/user.rb index 6bfcfdbd0..33faa8ee6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -110,15 +110,6 @@ class User < ApplicationRecord inboxes.where(account_id: Current.account.id) end - alias avatar_img_url avatar_url - def avatar_url - if avatar_img_url == '' - hash = Digest::MD5.hexdigest(email) - return "https://www.gravatar.com/avatar/#{hash}?d=404" - end - avatar_img_url - end - def administrator? current_account_user&.administrator? end