Sha256: f4a3ef4e7103ba4d1626e98a60378c566be984346a361edd56630a1bb76089d0

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true
module Decidim
  module Comments
    # A custom mailer for sending notifications to users when
    # a comment is created.
    class CommentNotificationMailer < Decidim::ApplicationMailer
      helper Decidim::ResourceHelper

      helper_method :commentable_title

      def comment_created(user, comment, commentable)
        with_user(user) do
          @comment = comment
          @commentable = commentable
          @organization = commentable.organization
          subject = I18n.t("comment_created.subject", scope: "decidim.comments.mailer.comment_notification")
          mail(to: commentable.author.email, subject: subject)
        end
      end

      def reply_created(user, reply, comment, commentable)
        with_user(user) do
          @reply = reply
          @comment = comment
          @commentable = commentable
          @organization = commentable.organization
          subject = I18n.t("reply_created.subject", scope: "decidim.comments.mailer.comment_notification")
          mail(to: comment.author.email, subject: subject)
        end
      end

      private

      def commentable_title
        @commentable.title.is_a?(Hash) ? @commentable.title[I18n.locale.to_s] : @commentable.title
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
decidim-comments-0.1.0 app/mailers/decidim/comments/comment_notification_mailer.rb
decidim-0.1.0 decidim-comments/app/mailers/decidim/comments/comment_notification_mailer.rb