Sha256: 5e5cb32858919516eee605a20a3dde88554db927c9b566daec2f35dc319c456b

Contents?: true

Size: 865 Bytes

Versions: 3

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true
module Thredded
  class EmailNotifier
    def human_name
      I18n.t('thredded.email_notifier.by_email')
    end

    def key
      'email'
    end

    def new_post(post, users)
      PostMailer.post_notification(post.id, users.map(&:email)).deliver_now
      MembersMarkedNotified.new(post, users).run
    end

    def new_private_post(post, users)
      users = exclude_previously_notified(post, users)
      return unless users.present?
      PrivateTopicMailer
        .message_notification(post.postable.id, post.id, users.map(&:email))
        .deliver_now
      MembersMarkedNotified.new(post, users).run
    end

    def exclude_previously_notified(post, users)
      emails_notified = post.post_notifications.map(&:email)

      users.reject do |user|
        emails_notified.include? user.email
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thredded-0.10.1 app/notifiers/thredded/email_notifier.rb
thredded-0.10.0 app/notifiers/thredded/email_notifier.rb
thredded-0.9.4 app/notifiers/thredded/email_notifier.rb