Sha256: ef59115e296aaf087289062f57ae7ffa5834aabd4096f287d40e552f5be59760

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Decidim
  module Messaging
    # A custom mailer for sending notifications to users when they receive
    # private messages
    class ConversationMailer < Decidim::ApplicationMailer
      def new_conversation(originator, user, conversation)
        notification_mail(
          from: originator,
          to: user,
          conversation: conversation,
          action: "new_conversation"
        )
      end

      def new_message(sender, user, conversation)
        notification_mail(
          from: sender,
          to: user,
          conversation: conversation,
          action: "new_message"
        )
      end

      private

      # rubocop:disable Naming/UncommunicativeMethodParamName
      def notification_mail(from:, to:, conversation:, action:)
        with_user(to) do
          @organization = to.organization
          @conversation = conversation
          @sender = from.name
          @recipient = to.name
          @host = @organization.host

          subject = I18n.t(
            "conversation_mailer.#{action}.subject",
            scope: "decidim.messaging",
            sender: @sender
          )

          mail(to: to.email, subject: subject)
        end
        # rubocop:enable Naming/UncommunicativeMethodParamName
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-core-0.10.1 app/mailers/decidim/messaging/conversation_mailer.rb