Class: ChatMessage::NoteMessage

Inherits:
BaseMessage show all
Defined in:
app/models/project_services/chat_message/note_message.rb

Constant Summary

Constants inherited from BaseMessage

BaseMessage::RELATIVE_LINK_REGEX

Instance Attribute Summary collapse

Attributes inherited from BaseMessage

#markdown, #project_name, #project_url, #user_avatar, #user_full_name, #user_name

Instance Method Summary collapse

Methods inherited from BaseMessage

#fallback, #pretext, #summary, #user_combined_name

Constructor Details

#initialize(params) ⇒ NoteMessage

Returns a new instance of NoteMessage.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/project_services/chat_message/note_message.rb', line 10

def initialize(params)
  super

  params = HashWithIndifferentAccess.new(params)
  obj_attr = params[:object_attributes]
  @note = obj_attr[:note]
  @note_url = obj_attr[:url]
  @target, @title = case obj_attr[:noteable_type]
                    when "Commit"
                      create_commit_note(params[:commit])
                    when "Issue"
                      create_issue_note(params[:issue])
                    when "MergeRequest"
                      create_merge_note(params[:merge_request])
                    when "Snippet"
                      create_snippet_note(params[:snippet])
                    end
end

Instance Attribute Details

#noteObject (readonly)

Returns the value of attribute note


5
6
7
# File 'app/models/project_services/chat_message/note_message.rb', line 5

def note
  @note
end

#note_urlObject (readonly)

Returns the value of attribute note_url


6
7
8
# File 'app/models/project_services/chat_message/note_message.rb', line 6

def note_url
  @note_url
end

#targetObject (readonly)

Returns the value of attribute target


8
9
10
# File 'app/models/project_services/chat_message/note_message.rb', line 8

def target
  @target
end

#titleObject (readonly)

Returns the value of attribute title


7
8
9
# File 'app/models/project_services/chat_message/note_message.rb', line 7

def title
  @title
end

Instance Method Details

#activityObject


35
36
37
38
39
40
41
42
# File 'app/models/project_services/chat_message/note_message.rb', line 35

def activity
  {
    title: "#{user_combined_name} #{link('commented on ' + target, note_url)}",
    subtitle: "in #{project_link}",
    text: formatted_title,
    image: user_avatar
  }
end

#attachmentsObject


29
30
31
32
33
# File 'app/models/project_services/chat_message/note_message.rb', line 29

def attachments
  return note if markdown

  description_message
end