Module: ActivityNotification::Target

Extended by:
ActiveSupport::Concern
Includes:
Common
Defined in:
lib/activity_notification/models/concerns/target.rb

Overview

Target implementation included in target model to notify, like users or administrators.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#printable_name, #printable_type, #resolve_value, #to_class_name, #to_resource_name, #to_resources_name

Class Method Details

.all_notifications(options = {}) ⇒ Array<Notificaion>

Gets all notifications for this target type.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    All notifications for this target type



55
56
57
58
59
60
61
62
# File 'lib/activity_notification/models/concerns/target.rb', line 55

def all_notifications(options = {})
  reverse            = options[:reverse] || false
  with_group_members = options[:with_group_members] || false
  target_notifications = Notification.filtered_by_target_type(self.name)
                                     .all_index!(reverse, with_group_members)
                                     .filtered_by_options(options)
  options[:limit].present? ? target_notifications.limit(options[:limit]) : target_notifications
end

.available_as_target?Boolean

Checks if the model includes target and target methods are available.

Returns:

  • (Boolean)

    Always true



27
28
29
# File 'lib/activity_notification/models/concerns/target.rb', line 27

def available_as_target?
  true
end

.notification_index_map(options = {}) ⇒ Array<Notificaion>

Gets all notifications for this target type grouped by targets.

Examples:

Get all notifications for for users grouped by user

@notification_index_map = User.notification_index_map
@notification_index_map.each do |user, notifications|
  # Do something for user and notifications
end

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    All notifications for this target type grouped by targets



83
84
85
# File 'lib/activity_notification/models/concerns/target.rb', line 83

def notification_index_map(options = {})
  all_notifications(options).group_by(&:target)
end

.send_batch_unopened_notification_email(options = {}) ⇒ Hash<Object, Mail::Message|ActionMailer::DeliveryJob>

Send batch notification email to this type targets with unopened notifications.

Examples:

Send batch notification email to the users with unopened notifications of specified key

User.send_batch_unopened_notification_email(filtered_by_key: 'this.key')

Send batch notification email to the users with unopened notifications of specified key in 1 hour

User.send_batch_unopened_notification_email(filtered_by_key: 'this.key', custom_filter: ["created_at >= ?", time.hour.ago])

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Hash<Object, Mail::Message|ActionMailer::DeliveryJob>)

    Hash of target and sent email message or its delivery job



128
129
130
131
132
133
# File 'lib/activity_notification/models/concerns/target.rb', line 128

def send_batch_unopened_notification_email(options = {})
  unopened_notification_index_map = unopened_notification_index_map(options)
  unopened_notification_index_map.map { |target, notifications|
    [target, Notification.send_batch_notification_email(target, notifications, options)]
  }.to_h
end

.set_target_class_defaultsNilClass

Sets default values to target class fields.

Returns:

  • (NilClass)

    nil



33
34
35
36
37
38
39
40
# File 'lib/activity_notification/models/concerns/target.rb', line 33

def set_target_class_defaults
  self._notification_email                 = nil
  self._notification_email_allowed         = ActivityNotification.config.email_enabled
  self._batch_notification_email_allowed   = ActivityNotification.config.email_enabled
  self._notification_devise_resource       = ->(model) { model }
  self._printable_notification_target_name = :printable_name
  nil
end

.unopened_notification_index_map(options = {}) ⇒ Array<Notificaion>

Gets all unopened notifications for this target type grouped by targets.

Examples:

Get all unopened notifications for users grouped by user

@unopened_notification_index_map = User.unopened_notification_index_map
@unopened_notification_index_map.each do |user, notifications|
  # Do something for user and notifications
end

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    All unopened notifications for this target type grouped by targets



106
107
108
# File 'lib/activity_notification/models/concerns/target.rb', line 106

def unopened_notification_index_map(options = {})
  all_notifications(options).unopened_only.group_by(&:target)
end

Instance Method Details

#authenticated_with_devise?(current_resource) ⇒ Boolean

Returns if current resource signed in with Devise is authenticated for the notification. This method is able to be overriden.

Parameters:

  • current_resource (Object)

    Current resource signed in with Devise

Returns:

  • (Boolean)

    If current resource signed in with Devise is authenticated for the notification



169
170
171
172
173
174
175
176
177
178
# File 'lib/activity_notification/models/concerns/target.rb', line 169

def authenticated_with_devise?(current_resource)
  devise_resource = resolve_value(_notification_devise_resource)
  unless current_resource.blank? or current_resource.instance_of? devise_resource.class
    raise TypeError,
      "Defferent type of current resource #{current_resource.class} "\
      "with devise resource #{devise_resource.class} has been passed to #{self.class}##{__method__}. "\
      "You have to override #{self.class}##{__method__} method or set devise_resource in acts_as_target."
  end
  current_resource.present? and current_resource == devise_resource
end

#batch_notification_email_allowed?(notifiable_type, key) ⇒ Boolean

Returns if sending batch notification email is allowed for the target from configured field or overriden method. This method is able to be overriden.

Parameters:

  • notifiable_type (Object)

    Notifiable type of the notifications

  • key (String)

    Key of the notifications

Returns:

  • (Boolean)

    If sending batch notification email is allowed for the target



160
161
162
# File 'lib/activity_notification/models/concerns/target.rb', line 160

def batch_notification_email_allowed?(notifiable_type, key)
  resolve_value(_batch_notification_email_allowed, notifiable_type, key)
end

#has_unopened_notifications?(options = {}) ⇒ Boolean

Returns if the target has unopened notifications.

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Boolean)

    If the target has unopened notifications



214
215
216
# File 'lib/activity_notification/models/concerns/target.rb', line 214

def has_unopened_notifications?(options = {})
  _unopened_notification_index(options).present?
end

#mailer_toString

Returns target email address for email notification. This method is able to be overriden.

Returns:

  • (String)

    Target email address



140
141
142
# File 'lib/activity_notification/models/concerns/target.rb', line 140

def mailer_to
  resolve_value(_notification_email)
end

#notification_email_allowed?(notifiable, key) ⇒ Boolean

Returns if sending notification email is allowed for the target from configured field or overriden method. This method is able to be overriden.

Parameters:

  • notifiable (Object)

    Notifiable instance of the notification

  • key (String)

    Key of the notification

Returns:

  • (Boolean)

    If sending notification email is allowed for the target



150
151
152
# File 'lib/activity_notification/models/concerns/target.rb', line 150

def notification_email_allowed?(notifiable, key)
  resolve_value(_notification_email_allowed, notifiable, key)
end

#notification_index(options = {}) ⇒ Array<Notificaion>

TODO:

Is this switching the best solution?

Gets automatically arranged notification index of the target. This method is the typical way to get notifications index from controller of view. When the target have unopened notifications, it returns unopened notifications first. Additionaly, it returns opened notifications unless unopened index size overs the limit.

Examples:

Get automatically arranged notification index of the @user

@notifications = @user.notification_index

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    Notification index of the target



239
240
241
242
243
# File 'lib/activity_notification/models/concerns/target.rb', line 239

def notification_index(options = {})
  arrange_notification_index(method(:unopened_notification_index),
                             method(:opened_notification_index),
                             options)
end

#notification_index_with_attributes(options = {}) ⇒ Array<Notificaion>

TODO:

Is this switching the best solution?

Gets automatically arranged notification index of the target with included attributes like target, notifiable, group and notifier. This method is the typical way to get notifications index from controller of view. When the target have unopened notifications, it returns unopened notifications first. Additionaly, it returns opened notifications unless unopened index size overs the limit.

Examples:

Get automatically arranged notification index of the @user with included attributes

@notifications = @user.notification_index_with_attributes

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :send_later (Boolean) — default: false

    If it sends notification email asynchronously

  • :fallback (String, Symbol) — default: :batch_default

    Fallback template to use when MissingTemplate is raised

  • :batch_key (String) — default: nil

    Key of the batch notification email, a key of the first notification will be used if not specified

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    Notification index of the target with attributes



345
346
347
348
349
# File 'lib/activity_notification/models/concerns/target.rb', line 345

def notification_index_with_attributes(options = {})
  arrange_notification_index(method(:unopened_notification_index_with_attributes),
                             method(:opened_notification_index_with_attributes),
                             options)
end

#notificationsArray<Notificaion>

Has many notification instances of this target.

Returns:

  • (Array<Notificaion>)

    Array or database query of notifications of this target



11
12
13
14
# File 'lib/activity_notification/models/concerns/target.rb', line 11

has_many :notifications,
class_name: "::ActivityNotification::Notification",
as: :target,
dependent: :delete_all

#notify_to(notifiable, options = {}) ⇒ Notification

Generates notifications to this target. This method calls NotificationApi#notify_to internally with self target instance.

Parameters:

  • notifiable (Object)

    Notifiable instance to notify

  • options (Hash) (defaults to: {})

    Options for notifications

Options Hash (options):

  • :key (String) — default: notifiable.default_notification_key

    Key of the notification

  • :group (Object) — default: nil

    Group unit of the notifications

  • :notifier (Object) — default: nil

    Notifier of the notifications

  • :parameters (Hash) — default: {}

    Additional parameters of the notifications

  • :send_email (Boolean) — default: true

    Whether it sends notification email

  • :send_later (Boolean) — default: true

    Whether it sends notification email asynchronously

Returns:

See Also:



300
301
302
# File 'lib/activity_notification/models/concerns/target.rb', line 300

def notify_to(notifiable, options = {})
  Notification.notify_to(self, notifiable, options)
end

#open_all_notifications(options = {}) ⇒ Integer

Opens all notifications of this target. This method calls NotificationApi#open_all_of internally with self target instance.

Parameters:

  • options (Hash) (defaults to: {})

    Options for opening notifications

Options Hash (options):

  • :opened_at (DateTime) — default: DateTime.now

    Time to set to opened_at of the notification record

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

Returns:

  • (Integer)

    Number of opened notification records

See Also:



316
317
318
# File 'lib/activity_notification/models/concerns/target.rb', line 316

def open_all_notifications(options = {})
  Notification.open_all_of(self, options)
end

#opened_notification_index(options = {}) ⇒ Array<Notificaion>

Gets opened notification index of the target.

Examples:

Get opened notification index of the @user

@notifications = @user.opened_notification_index(10)

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    Opened notification index of the target



283
284
285
# File 'lib/activity_notification/models/concerns/target.rb', line 283

def opened_notification_index(options = {})
  arrange_single_notification_index(method(:_opened_notification_index), options)
end

#opened_notification_index_with_attributes(options = {}) ⇒ Array<Notificaion>

Gets opened notification index of the target with including attributes like target, notifiable, group and notifier.

Examples:

Get opened notification index of the @user with included attributes

@notifications = @user.opened_notification_index_with_attributes(10)

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    Opened notification index of the target with attributes



389
390
391
# File 'lib/activity_notification/models/concerns/target.rb', line 389

def opened_notification_index_with_attributes(options = {})
  include_attributes _opened_notification_index(options)
end

#printable_target_nameString

Returns printable target model name to show in view or email.

Returns:

  • (String)

    Printable target model name



182
183
184
# File 'lib/activity_notification/models/concerns/target.rb', line 182

def printable_target_name
  resolve_value(_printable_notification_target_name)
end

#send_batch_notification_email(notifications, options = {}) ⇒ Mail::Message|ActionMailer::DeliveryJob|NilClass

Sends batch notification email to the target.

Parameters:

  • notifications (Array<Notification>)

    Target notifications to send batch notification email

  • options (Hash) (defaults to: {})

    Options for notification email

Options Hash (options):

  • :send_later (Boolean) — default: false

    If it sends notification email asynchronously

  • :fallback (String, Symbol) — default: :batch_default

    Fallback template to use when MissingTemplate is raised

  • :batch_key (String) — default: nil

    Key of the batch notification email, a key of the first notification will be used if not specified

Returns:

  • (Mail::Message|ActionMailer::DeliveryJob|NilClass)

    Email message or its delivery job, return NilClass for wrong target



413
414
415
416
417
418
# File 'lib/activity_notification/models/concerns/target.rb', line 413

def send_batch_notification_email(notifications, options = {})
  return if notifications.blank?
  if notifications.map{ |n| n.target }.uniq == [self]
    Notification.send_batch_notification_email(self, notifications, options)
  end
end

#send_notification_email(notification, options = {}) ⇒ Mail::Message|ActionMailer::DeliveryJob

Sends notification email to the target.

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification email

Options Hash (options):

  • :send_later (Boolean)

    If it sends notification email asynchronously

  • :fallback (String, Symbol) — default: :default

    Fallback template to use when MissingTemplate is raised

Returns:

  • (Mail::Message|ActionMailer::DeliveryJob)

    Email message or its delivery job, return NilClass for wrong target



399
400
401
402
403
# File 'lib/activity_notification/models/concerns/target.rb', line 399

def send_notification_email(notification, options = {})
  if notification.target == self
    notification.send_notification_email(options)
  end
end

#unopened_notification_count(options = {}) ⇒ Integer

Returns count of unopened notifications of the target.

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Integer)

    Count of unopened notifications of the target



198
199
200
201
# File 'lib/activity_notification/models/concerns/target.rb', line 198

def unopened_notification_count(options = {})
  target_notifications = _unopened_notification_index(options)
  target_notifications.present? ? target_notifications.count : 0
end

#unopened_notification_index(options = {}) ⇒ Array<Notificaion>

Gets unopened notification index of the target.

Examples:

Get unopened notification index of the @user

@notifications = @user.unopened_notification_index

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    Unopened notification index of the target



262
263
264
# File 'lib/activity_notification/models/concerns/target.rb', line 262

def unopened_notification_index(options = {})
  arrange_single_notification_index(method(:_unopened_notification_index), options)
end

#unopened_notification_index_with_attributes(options = {}) ⇒ Array<Notificaion>

Gets unopened notification index of the target with included attributes like target, notifiable, group and notifier.

Examples:

Get unopened notification index of the @user with included attributes

@notifications = @user.unopened_notification_index_with_attributes

Parameters:

  • options (Hash) (defaults to: {})

    Options for notification index

Options Hash (options):

  • :limit (Integer) — default: nil

    Limit to query for notifications

  • :reverse (Boolean) — default: false

    If notification index will be ordered as earliest first

  • :with_group_members (Boolean) — default: false

    If notification index will include group members

  • :as_latest_group_member (Boolean) — default: false

    If grouped notification will be shown as the latest group member (default is shown as the earliest member)

  • :filtered_by_type (String) — default: nil

    Notifiable type for filter

  • :filtered_by_group (Object) — default: nil

    Group instance for filter

  • :filtered_by_group_type (String) — default: nil

    Group type for filter, valid with :filtered_by_group_id

  • :filtered_by_group_id (String) — default: nil

    Group instance id for filter, valid with :filtered_by_group_type

  • :filtered_by_key (String) — default: nil

    Key of the notification for filter

  • :custom_filter (Array|Hash) — default: nil

    Custom notification filter (e.g. [“created_at >= ?”, time.hour.ago])

Returns:

  • (Array<Notificaion>)

    Unopened notification index of the target with attributes



368
369
370
# File 'lib/activity_notification/models/concerns/target.rb', line 368

def unopened_notification_index_with_attributes(options = {})
  include_attributes _unopened_notification_index(options)
end