]> git.openstreetmap.org Git - rails.git/blobdiff - app/mailers/user_mailer.rb
Use correct extension and type for avatar images attached to mails
[rails.git] / app / mailers / user_mailer.rb
index 33fcc7465a6fb8a056448032556dbf7c577b0b7c..a9c6b70f91eeb29d8538aa1c18859e199a38b8ad 100644 (file)
@@ -123,7 +123,7 @@ class UserMailer < ApplicationMailer
 
   def note_comment_notification(comment, recipient)
     with_recipient_locale recipient do
 
   def note_comment_notification(comment, recipient)
     with_recipient_locale recipient do
-      @noteurl = browse_note_url(comment.note)
+      @noteurl = note_url(comment.note)
       @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
       @comment = comment.body
       @owner = recipient == comment.note.author
       @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
       @comment = comment.body
       @owner = recipient == comment.note.author
@@ -187,7 +187,25 @@ class UserMailer < ApplicationMailer
   end
 
   def attach_user_avatar(user)
   end
 
   def attach_user_avatar(user)
-    attachments.inline["avatar.png"] = user_avatar_file(user)
+    @avatar = user_avatar_filename(user)
+    attachments.inline[@avatar] = user_avatar_file(user)
+  end
+
+  def user_avatar_filename(user)
+    avatar = user&.avatar
+    if avatar&.attached?
+      case avatar.content_type
+      when "image/png" then "avatar.png"
+      when "image/jpeg" then "avatar.jpg"
+      when "image/gif" then "avatar.gif"
+      when "image/bmp" then "avatar.bmp"
+      when "image/tiff" then "avatar.tif"
+      when "image/svg+xml" then "avatar.svg"
+      else "avatar"
+      end
+    else
+      "avatar.png"
+    end
   end
 
   def user_avatar_file(user)
   end
 
   def user_avatar_file(user)