Module: NewsmastMastodon::Overrides::NotifyServiceExtension

Defined in:
app/services/newsmast_mastodon/overrides/notify_service_extension.rb

Instance Method Summary collapse

Instance Method Details

#call(recipient, type, activity) ⇒ Object



8
9
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
# File 'app/services/newsmast_mastodon/overrides/notify_service_extension.rb', line 8

def call(recipient, type, activity)
  return if recipient.user.nil?

  @recipient    = recipient
  @activity     = activity
  @notification = Notification.new(account: @recipient, type: type, activity: @activity)

  # For certain conditions we don't need to create a notification at all
  return if drop?

  @notification.filtered = filter?
  @notification.set_group_key!
  @notification.save!

  # It's possible the underlying activity has been deleted
  # between the save call and now
  return if @notification.activity.nil?

  if @notification.filtered?
    update_notification_request!
    NewsmastMastodon::CustomNotificationService.new.call(@recipient, @notification) if @notification.type == :mention
  else
    push_notification!
    push_to_conversation! if direct_message?
    send_email! if email_needed?
    NewsmastMastodon::CustomNotificationService.new.call(@recipient, @notification)
  end
rescue ActiveRecord::RecordInvalid
  nil
end

#send_email!Object



39
40
41
42
43
44
45
46
# File 'app/services/newsmast_mastodon/overrides/notify_service_extension.rb', line 39

def send_email!
  return unless NotificationMailer.respond_to?(@notification.type)

  NotificationMailer
    .with(recipient: @recipient, notification: @notification)
    .public_send(@notification.type)
    .deliver_later
end