Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/models/event/description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def to_html
end

def to_plain_text
to_sentence(creator_name, h(card.title))
to_sentence(creator_name, quoted(card.title))
end

private
Expand All @@ -41,6 +41,10 @@ def creator_name
h(event.creator.name)
end

def quoted(text)
%("#{h text}")
end

def card
@card ||= event.action.comment_created? ? event.eventable.card : event.eventable
end
Expand Down
17 changes: 15 additions & 2 deletions app/models/webhook/delivery.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Webhook::Delivery < ApplicationRecord
include Rails.application.routes.url_helpers

class ResponseTooLarge < StandardError; end

STALE_TRESHOLD = 7.days
Expand Down Expand Up @@ -130,8 +132,7 @@ def payload
elsif webhook.for_campfire?
render_payload(formats: :html)
elsif webhook.for_slack?
html = render_payload(formats: :html)
{ text: convert_html_to_mrkdwn(html) }.to_json
slack_payload
else
render_payload(formats: :json)
end
Expand All @@ -158,4 +159,16 @@ def convert_html_to_mrkdwn(html)

document.text
end

def slack_payload
text = event.description_for(nil).to_plain_text
url = polymorphic_url(event.eventable, base_url_options.merge(script_name: account.slug))

{ text: "#{text} <#{url}|Open in Fizzy>" }.to_json
end

def base_url_options
Rails.application.routes.default_url_options.presence ||
Rails.application.config.action_mailer.default_url_options
end
end