Make comments the event's host
This commit is contained in:
@@ -53,8 +53,8 @@ module EventsHelper
|
||||
end
|
||||
when "card_unassigned"
|
||||
"#{ event.creator == Current.user ? "You" : event.creator.name } unassigned #{ event.assignees.include?(Current.user) ? "yourself" : event.assignees.pluck(:name).to_sentence } from <span style='color: var(--card-color)'>#{ event.eventable.title }</span>".html_safe
|
||||
when "card_commented"
|
||||
"#{ event.creator == Current.user ? "You" : event.creator.name } commented on <span style='color: var(--card-color)'>#{ event.eventable.title }</span>".html_safe
|
||||
when "comment_created"
|
||||
"#{ event.creator == Current.user ? "You" : event.creator.name } commented on <span style='color: var(--card-color)'>#{ event.eventable.card.title }</span>".html_safe
|
||||
when "card_published"
|
||||
"#{ event.creator == Current.user ? "You" : event.creator.name } added <span style='color: var(--card-color)'>#{ event.eventable.title }</span>".html_safe
|
||||
when "card_closed"
|
||||
@@ -82,7 +82,7 @@ module EventsHelper
|
||||
"bolt"
|
||||
when "card_unstaged"
|
||||
"bolt"
|
||||
when "card_commented"
|
||||
when "comment_created"
|
||||
"comment"
|
||||
when "card_title_changed"
|
||||
"rename"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module NotificationsHelper
|
||||
def event_notification_title(event)
|
||||
case event_notification_action(event)
|
||||
when "card_commented" then "RE: " + event.eventable.title
|
||||
when "comment_created" then "RE: " + event.eventable.card.title
|
||||
when "card_assigned" then "Assigned to you: " + event.eventable.title
|
||||
else event.eventable.title
|
||||
end
|
||||
@@ -13,7 +13,7 @@ module NotificationsHelper
|
||||
case event_notification_action(event)
|
||||
when "card_closed" then "Closed by #{name}"
|
||||
when "card_published" then "Added by #{name}"
|
||||
when "card_commented" then comment_notification_body(event)
|
||||
when "comment_created" then comment_notification_body(event)
|
||||
else name
|
||||
end
|
||||
end
|
||||
@@ -56,6 +56,7 @@ module NotificationsHelper
|
||||
end
|
||||
|
||||
def comment_notification_body(event)
|
||||
"#{strip_tags(event.comment.body_html).blank? ? "#{event.creator.name} replied" : "#{event.creator.name}:" } #{strip_tags(event.comment.body_html).truncate(200)}"
|
||||
comment = event.eventable
|
||||
"#{strip_tags(comment.body_html).blank? ? "#{event.creator.name} replied" : "#{event.creator.name}:" } #{strip_tags(comment.body_html).truncate(200)}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Comment < ApplicationRecord
|
||||
include Mentions, Messageable, Searchable
|
||||
include Eventable, Mentions, Messageable, Searchable
|
||||
|
||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||
has_many :reactions, dependent: :delete_all
|
||||
@@ -10,7 +10,7 @@ class Comment < ApplicationRecord
|
||||
# FIXME: Not a fan of this. Think all references to comment should come directly from the message.
|
||||
scope :belonging_to_card, ->(card) { joins(:message).where(messages: { card_id: card.id }) }
|
||||
|
||||
after_create_commit :watch_card_by_creator, :track_commented_card
|
||||
after_create_commit :watch_card_by_creator
|
||||
after_destroy_commit :cleanup_events
|
||||
|
||||
delegate :watch_by, to: :card
|
||||
@@ -24,10 +24,6 @@ class Comment < ApplicationRecord
|
||||
card.watch_by creator
|
||||
end
|
||||
|
||||
def track_commented_card
|
||||
card.track_event :commented, comment_id: id
|
||||
end
|
||||
|
||||
# FIXME: This isn't right. We need to introduce an eventable polymorphic association for this.
|
||||
def cleanup_events
|
||||
# Delete events that reference directly in particulars
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
module Comment::Eventable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
include ::Eventable
|
||||
|
||||
included do
|
||||
after_create_commit :track_creation
|
||||
end
|
||||
|
||||
def event_was_created(event)
|
||||
card.touch(:last_active_at)
|
||||
end
|
||||
|
||||
private
|
||||
def track_creation
|
||||
track_event("created", collection: card.collection)
|
||||
end
|
||||
end
|
||||
+1
-5
@@ -15,11 +15,7 @@ class Event < ApplicationRecord
|
||||
end
|
||||
|
||||
def notifiable_target
|
||||
if action.commented?
|
||||
comment
|
||||
else
|
||||
eventable
|
||||
end
|
||||
eventable
|
||||
end
|
||||
|
||||
# TODO: This doesn't belong here anymore
|
||||
|
||||
@@ -2,14 +2,10 @@ module Event::Particulars
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
store_accessor :particulars, :assignee_ids, :comment_id, :stage_id, :stage_name
|
||||
store_accessor :particulars, :assignee_ids, :stage_id, :stage_name
|
||||
end
|
||||
|
||||
def assignees
|
||||
@assignees ||= User.where id: assignee_ids
|
||||
end
|
||||
|
||||
def comment
|
||||
@comment ||= Comment.find_by id: comment_id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,14 +9,18 @@ class Notifier::EventNotifier < Notifier
|
||||
source.assignees.excluding(source.collection.access_only_users)
|
||||
when "card_published"
|
||||
watchers_and_subscribers(include_only_watching: true).without(creator, *card.mentionees)
|
||||
when "card_commented"
|
||||
watchers_and_subscribers.without(creator, *source.comment.mentionees)
|
||||
when "comment_created"
|
||||
watchers_and_subscribers.without(creator, *source.eventable.mentionees)
|
||||
else
|
||||
watchers_and_subscribers.without(creator)
|
||||
end
|
||||
end
|
||||
|
||||
def card
|
||||
source.eventable
|
||||
if source.eventable.is_a?(Card)
|
||||
source.eventable
|
||||
else
|
||||
source.eventable.card
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<% card = event.eventable.is_a?(Card) ? event.eventable : event.eventable.card %>
|
||||
|
||||
<%= link_to event.eventable,
|
||||
class: "event event--#{ event.action } panel center center-block flex-inline align-start justify-start gap position-relative",
|
||||
style: "--card-color: #{ event.eventable.color }; background-color: color-mix(in srgb, var(--card-color) 10%, var(--color-bg));
|
||||
style: "--card-color: #{ card.color }; background-color: color-mix(in srgb, var(--card-color) 10%, var(--color-bg));
|
||||
color: color-mix(in srgb, var(--card-color) 40%, var(--color-ink));",
|
||||
data: { related_element_target: "related",
|
||||
related_element_group_value: event.eventable.id,
|
||||
related_element_group_value: card.id,
|
||||
action: "mouseover->related-element#highlight mouseout->related-element#unhighlight" } do %>
|
||||
<div class="avatar txt-x-small flex-item-no-shrink">
|
||||
<%= avatar_image_tag(event.creator) %>
|
||||
@@ -22,9 +24,9 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if event.action == "card_commented" && !strip_tags(event&.comment&.body_html).blank? %>
|
||||
<% if event.action == "comment_created" && !strip_tags(event&.eventable&.body_html).blank? %>
|
||||
<span class="txt-break overflow-line-clamp txt-tight-lines">
|
||||
<%= strip_tags(event.comment.body_html).truncate(200) -%>
|
||||
<%= strip_tags(event&.eventable.body_html).truncate(200) -%>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
|
||||
Vendored
+2
-3
@@ -35,10 +35,9 @@ layout_published:
|
||||
layout_commented:
|
||||
creator: david
|
||||
collection: writebook
|
||||
eventable: layout (Card)
|
||||
action: card_commented
|
||||
eventable: layout_overflowing_david (Comment)
|
||||
action: comment_created
|
||||
summary: layout_initial_activity
|
||||
particulars: <%= { comment_id: ActiveRecord::FixtureSet.identify(:layout_overflowing_david) }.to_json %>
|
||||
created_at: <%= 1.week.ago %>
|
||||
|
||||
layout_assignment_jz:
|
||||
|
||||
Reference in New Issue
Block a user