debian-mirror-gitlab/app/models/project_services/chat_message/wiki_page_message.rb

62 lines
1.2 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module ChatMessage
2016-06-02 11:05:42 +05:30
class WikiPageMessage < BaseMessage
attr_reader :title
attr_reader :wiki_page_url
attr_reader :action
attr_reader :description
def initialize(params)
2017-08-17 22:00:37 +05:30
super
2016-06-02 11:05:42 +05:30
obj_attr = params[:object_attributes]
obj_attr = HashWithIndifferentAccess.new(obj_attr)
@title = obj_attr[:title]
@wiki_page_url = obj_attr[:url]
2020-03-13 15:44:24 +05:30
@description = obj_attr[:message]
2016-06-02 11:05:42 +05:30
@action =
case obj_attr[:action]
when "create"
"created"
when "update"
"edited"
end
end
def attachments
2017-08-17 22:00:37 +05:30
return description if markdown
2016-06-02 11:05:42 +05:30
description_message
end
2017-08-17 22:00:37 +05:30
def activity
{
2018-03-17 18:26:18 +05:30
title: "#{user_combined_name} #{action} #{wiki_page_link}",
2017-08-17 22:00:37 +05:30
subtitle: "in #{project_link}",
text: title,
image: user_avatar
}
end
2016-06-02 11:05:42 +05:30
private
def message
2018-03-17 18:26:18 +05:30
"#{user_combined_name} #{action} #{wiki_page_link} in #{project_link}: *#{title}*"
2016-06-02 11:05:42 +05:30
end
def description_message
[{ text: format(@description), color: attachment_color }]
end
def project_link
"[#{project_name}](#{project_url})"
end
def wiki_page_link
"[wiki page](#{wiki_page_url})"
end
end
end