Class: NotificationRecipients::Builder::NewNote

Inherits:
Base
  • Object
show all
Defined in:
app/services/notification_recipients/builder/new_note.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_recipients, #filter!, #make_recipient, #notification_recipients, #recipients, #user_scope

Constructor Details

#initialize(note) ⇒ NewNote

Returns a new instance of NewNote.


7
8
9
# File 'app/services/notification_recipients/builder/new_note.rb', line 7

def initialize(note)
  @note = note
end

Instance Attribute Details

#noteObject (readonly)

Returns the value of attribute note


6
7
8
# File 'app/services/notification_recipients/builder/new_note.rb', line 6

def note
  @note
end

Instance Method Details

#acting_userObject


55
56
57
# File 'app/services/notification_recipients/builder/new_note.rb', line 55

def acting_user
  note.author
end

#build!Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/services/notification_recipients/builder/new_note.rb', line 35

def build!
  # Add all users participating in the thread (author, assignee, comment authors)
  add_participants(note.author)
  add_mentions(note.author, target: note)

  if note.for_project_noteable?
    # Merge project watchers
    add_project_watchers
  else
    add_group_watchers
  end

  add_custom_notifications
  add_subscribed_users
end

#custom_actionObject


51
52
53
# File 'app/services/notification_recipients/builder/new_note.rb', line 51

def custom_action
  :new_note
end

#groupObject


27
28
29
30
31
32
33
# File 'app/services/notification_recipients/builder/new_note.rb', line 27

def group
  if note.for_project_noteable?
    project.group
  else
    target.try(:group)
  end
end

#projectObject

NOTE: may be nil, in the case of a PersonalSnippet

(this is okay because NotificationRecipient is written to handle nil projects)


23
24
25
# File 'app/services/notification_recipients/builder/new_note.rb', line 23

def project
  note.project
end

#recipients_targetObject


15
16
17
# File 'app/services/notification_recipients/builder/new_note.rb', line 15

def recipients_target
  note
end

#targetObject


11
12
13
# File 'app/services/notification_recipients/builder/new_note.rb', line 11

def target
  note.noteable
end