diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 1bbd3b508..b5c802ecf 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -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", diff --git a/app/models/comment.rb b/app/models/comment.rb index 8922b30b7..630589e41 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/concerns/messageable.rb b/app/models/concerns/messageable.rb index 219ee1197..d4c4f83fe 100644 --- a/app/models/concerns/messageable.rb +++ b/app/models/concerns/messageable.rb @@ -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 diff --git a/app/models/message.rb b/app/models/message.rb index 2947c99b5..7d950b3b7 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -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