2021-05-17 11:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Integrations
|
|
|
|
module ChatMessage
|
|
|
|
class WikiPageMessage < BaseMessage
|
|
|
|
attr_reader :title
|
|
|
|
attr_reader :wiki_page_url
|
|
|
|
attr_reader :action
|
|
|
|
attr_reader :description
|
2021-06-03 08:10:18 -04:00
|
|
|
attr_reader :diff_url
|
2021-05-17 11:10:15 -04:00
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
super
|
|
|
|
|
|
|
|
obj_attr = params[:object_attributes]
|
|
|
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
|
|
|
@title = obj_attr[:title]
|
|
|
|
@wiki_page_url = obj_attr[:url]
|
|
|
|
@description = obj_attr[:message]
|
2021-06-03 08:10:18 -04:00
|
|
|
@diff_url = obj_attr[:diff_url]
|
2021-05-17 11:10:15 -04:00
|
|
|
|
|
|
|
@action =
|
|
|
|
case obj_attr[:action]
|
|
|
|
when "create"
|
|
|
|
"created"
|
|
|
|
when "update"
|
|
|
|
"edited"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
return description if markdown
|
|
|
|
|
|
|
|
description_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def activity
|
|
|
|
{
|
|
|
|
title: "#{user_combined_name} #{action} #{wiki_page_link}",
|
|
|
|
subtitle: "in #{project_link}",
|
|
|
|
text: title,
|
|
|
|
image: user_avatar
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def message
|
2021-06-03 08:10:18 -04:00
|
|
|
"#{user_combined_name} #{action} #{wiki_page_link} (#{diff_link}) in #{project_link}: *#{title}*"
|
2021-05-17 11:10:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def description_message
|
|
|
|
[{ text: format(@description), color: attachment_color }]
|
|
|
|
end
|
|
|
|
|
2021-06-03 08:10:18 -04:00
|
|
|
def diff_link
|
|
|
|
link('Compare changes', diff_url)
|
|
|
|
end
|
|
|
|
|
2021-05-17 11:10:15 -04:00
|
|
|
def project_link
|
2021-06-03 08:10:18 -04:00
|
|
|
link(project_name, project_url)
|
2021-05-17 11:10:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def wiki_page_link
|
2021-06-03 08:10:18 -04:00
|
|
|
link('wiki page', wiki_page_url)
|
2021-05-17 11:10:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|