Class: Decidim::NotificationsDigestMailer

Inherits:
ApplicationMailer show all
Defined in:
app/mailers/decidim/notifications_digest_mailer.rb

Overview

A custom mailer for sending notifications to users when a events are received.

Constant Summary collapse

SIZE_LIMIT =
10

Instance Method Summary collapse

Methods included from OrganizationHelper

#current_organization_name, #organization_colors, #organization_description_label, #organization_name

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from SanitizeHelper

#decidim_escape_translated, #decidim_html_escape, #decidim_rich_text, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included

Instance Method Details

#digest_mail(user, notification_ids) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/mailers/decidim/notifications_digest_mailer.rb', line 10

def digest_mail(user, notification_ids)
  with_user(user) do
    notifications = Decidim::Notification.where(id: notification_ids)
    @user = user
    @organization = user.organization
    @notifications_digest = Decidim::NotificationsDigestPresenter.new(user)
    @display_see_more_message = notifications.size > SIZE_LIMIT
    # Note that this could be improved by adding a "type" column to the notifications table
    # This fix can generate lists of notifications that are below the SIZE_LIMIT
    @notifications = notifications[0...SIZE_LIMIT].filter_map do |notification|
      # Check if is a notification that can be sent on email
      next unless notification.event_class_instance.respond_to?(:email_intro)
      # checks if the resource exists, as we have implemented the possibility of soft deleting resources
      next unless resource_is_present?(notification)
      # checks if the resource is visible
      next unless notification.can_participate?(@user)
      # It usually checks if the resource is reportable and is not hidden, however, there are some exceptions
      # like in the comments, where we check if the resource and intended comment is visible.
      next if notification.hidden_resource?
      # It usually checks if the resource is deletable and is not deleted, however, there are some exceptions
      # like in the comments, where we check if the resource and intended comment is visible.
      next if notification.deleted_resource?

      Decidim::NotificationToMailerPresenter.new(notification)
    end

    mail(to: user.email, subject: @notifications_digest.subject) if @notifications.any?
  end
end