Move mentions to comments

- It does not make sense to scan "event summaries" for notifications.
- Placing them at the message level prevents us from using the generic approach to extract the mentionable content
This commit is contained in:
Jorge Manrubia
2025-04-22 16:17:37 +02:00
parent 81961a3523
commit 9b4fec936e
4 changed files with 13 additions and 8 deletions
+10 -3
View File
@@ -25,10 +25,8 @@ module NotificationsHelper
def notification_tag(notification, &)
tag.div id: dom_id(notification), class: "notification tray__item border-radius txt-normal" do
# TODO: Temporary, I'll remove this. Right now, we support linking comments, but we should be linking messages.
resource = notification.resource.is_a?(Message) ? notification.resource.comment : notification.resource
concat(
link_to(resource,
link_to(notification_resource_path(notification),
class: "notification__content border-radius shadow fill-white flex align-start txt-align-start gap flex-item-grow max-width border txt-ink",
data: { action: "click->dialog#close", turbo_frame: "_top" },
&)
@@ -37,6 +35,15 @@ module NotificationsHelper
end
end
def notification_resource_path(notification)
if notification.resource.is_a?(Comment)
# TODO: Extract a direct path for these
collection_card_path(notification.resource.card.collection, notification.resource.card, anchor: "comment_#{notification.resource.id}")
else
notification.resource
end
end
def notification_mark_read_button(notification)
button_to read_notification_path(notification),
class: "notification__unread_indicator btn borderless",
+1 -1
View File
@@ -1,5 +1,5 @@
class Comment < ApplicationRecord
include Messageable, Searchable
include Mentions, Messageable, Searchable
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :reactions, dependent: :delete_all
+2
View File
@@ -6,5 +6,7 @@ module Messageable
included do
has_one :message, as: :messageable, touch: true, dependent: :destroy
has_one :card, through: :message
delegate :collection, to: :message
end
end
-4
View File
@@ -1,11 +1,7 @@
class Message < ApplicationRecord
include Mentions
belongs_to :card, touch: true
delegated_type :messageable, types: Messageable::TYPES, inverse_of: :message, dependent: :destroy
scope :chronologically, -> { order created_at: :asc, id: :desc }
delegate :collection, to: :card
end