Class: Integrations::ChatMessage::BaseMessage

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

Constant Summary collapse

%r{!\[[^\]]*\]\((/uploads/[^\)]*)\)}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ BaseMessage

Returns a new instance of BaseMessage.



15
16
17
18
19
20
21
22
# File 'app/models/integrations/chat_message/base_message.rb', line 15

def initialize(params)
  @markdown = params[:markdown] || false
  @project_name = params[:project_name] || params.dig(:project, :path_with_namespace)
  @project_url = params.dig(:project, :web_url) || params[:project_url]
  @user_full_name = params.dig(:user, :name) || params[:user_full_name]
  @user_name = params.dig(:user, :username) || params[:user_name]
  @user_avatar = params.dig(:user, :avatar_url) || params[:user_avatar]
end

Instance Attribute Details

#markdownObject (readonly)

Returns the value of attribute markdown.



8
9
10
# File 'app/models/integrations/chat_message/base_message.rb', line 8

def markdown
  @markdown
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



12
13
14
# File 'app/models/integrations/chat_message/base_message.rb', line 12

def project_name
  @project_name
end

#project_urlObject (readonly)

Returns the value of attribute project_url.



13
14
15
# File 'app/models/integrations/chat_message/base_message.rb', line 13

def project_url
  @project_url
end

#user_avatarObject (readonly)

Returns the value of attribute user_avatar.



11
12
13
# File 'app/models/integrations/chat_message/base_message.rb', line 11

def user_avatar
  @user_avatar
end

#user_full_nameObject (readonly)

Returns the value of attribute user_full_name.



9
10
11
# File 'app/models/integrations/chat_message/base_message.rb', line 9

def user_full_name
  @user_full_name
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



10
11
12
# File 'app/models/integrations/chat_message/base_message.rb', line 10

def user_name
  @user_name
end

Instance Method Details

#activityObject

NOTE: Make sure to call ‘#strip_markup` on any untrusted user input that’s added to the ‘title`, `subtitle`, `text`, `fallback`, or `author_name` fields.

Raises:

  • (NotImplementedError)


54
55
56
# File 'app/models/integrations/chat_message/base_message.rb', line 54

def activity
  raise NotImplementedError
end

#attachmentsObject

NOTE: Make sure to call ‘#strip_markup` on any untrusted user input that’s added to the ‘title`, `subtitle`, `text`, `fallback`, or `author_name` fields.

Raises:

  • (NotImplementedError)


48
49
50
# File 'app/models/integrations/chat_message/base_message.rb', line 48

def attachments
  raise NotImplementedError
end

#fallbackObject



42
43
44
# File 'app/models/integrations/chat_message/base_message.rb', line 42

def fallback
  format(message)
end

#pretextObject



38
39
40
# File 'app/models/integrations/chat_message/base_message.rb', line 38

def pretext
  summary
end

#summaryObject



32
33
34
35
36
# File 'app/models/integrations/chat_message/base_message.rb', line 32

def summary
  return message if markdown

  format(message)
end

#user_combined_nameObject



24
25
26
27
28
29
30
# File 'app/models/integrations/chat_message/base_message.rb', line 24

def user_combined_name
  if user_full_name.present?
    "#{user_full_name} (#{user_name})"
  else
    user_name
  end
end