Class: Integrations::ChatMessage::GroupMentionMessage

Inherits:
BaseMessage
  • Object
show all
Defined in:
app/models/integrations/chat_message/group_mention_message.rb

Constant Summary collapse

ISSUE_KIND =
'issue'
MR_KIND =
'merge_request'
NOTE_KIND =
'note'
KNOWN_KINDS =
[ISSUE_KIND, MR_KIND, NOTE_KIND].freeze

Constants inherited from BaseMessage

BaseMessage::RELATIVE_LINK_REGEX

Instance Attribute Summary

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) ⇒ GroupMentionMessage

Returns a new instance of GroupMentionMessage.

Raises:

  • (NotImplementedError)


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
39
40
41
42
43
44
45
# File 'app/models/integrations/chat_message/group_mention_message.rb', line 12

def initialize(params)
  super
  params = HashWithIndifferentAccess.new(params)

  @group_name, @group_url = params[:mentioned].values_at(:name, :url)
  @detail = nil

  obj_attr = params[:object_attributes]
  obj_kind = obj_attr[:object_kind]
  raise NotImplementedError unless KNOWN_KINDS.include?(obj_kind)

  case obj_kind
  when 'issue'
    @source_name, @title = get_source_for_issue(obj_attr)
    @detail = obj_attr[:description]
  when 'merge_request'
    @source_name, @title = get_source_for_merge_request(obj_attr)
    @detail = obj_attr[:description]
  when 'note'
    if params[:commit]
      @source_name, @title = get_source_for_commit(params[:commit])
    elsif params[:issue]
      @source_name, @title = get_source_for_issue(params[:issue])
    elsif params[:merge_request]
      @source_name, @title = get_source_for_merge_request(params[:merge_request])
    else
      raise NotImplementedError
    end

    @detail = obj_attr[:note]
  end

  @source_url = obj_attr[:url]
end

Instance Method Details

#activityObject



55
56
57
58
59
60
61
62
# File 'app/models/integrations/chat_message/group_mention_message.rb', line 55

def activity
  {
    title: "Group #{group_link} was mentioned in #{source_link}",
    subtitle: "of #{project_link}",
    text: strip_markup(formatted_title),
    image: user_avatar
  }
end

#attachmentsObject



47
48
49
50
51
52
53
# File 'app/models/integrations/chat_message/group_mention_message.rb', line 47

def attachments
  if markdown
    detail
  else
    [{ text: format(detail), color: attachment_color }]
  end
end