avatar inline attachment
authorHerve Saint-Amand <git@saintamh.org>
Thu, 29 Dec 2016 23:37:22 +0000 (23:37 +0000)
committerHerve Saint-Amand <git@saintamh.org>
Thu, 29 Dec 2016 23:37:22 +0000 (23:37 +0000)
app/models/notifier.rb

index b53210c30e96df1c017fe1b9f62ba07584984f3b..ea10eeb7bd413166920f649ea86bba7f4d0c8fb1 100644 (file)
@@ -179,12 +179,25 @@ class Notifier < ActionMailer::Base
         content: @@osm_logo_png_bytes,
       }
 
+      File.open(user_avatar_file_path(comment.author), 'rb') do |file|
+        attachments.inline['avatar.png'] = file.read()
+      end
+
       mail :to => recipient.email, :subject => subject
     end
   end
 
   private
 
+  def user_avatar_file_path(user)
+    image = user.image
+    if image.file?
+      return image.path.sub('/original/', '/small/')
+    else
+      return Rails.root.join('app', 'assets', 'images', 'users', 'images', 'small.png')
+    end
+  end
+
   def with_recipient_locale(recipient)
     I18n.with_locale Locale.available.preferred(recipient.preferred_languages) do
       yield