Implement Notification#card

Models now know how to find their cards, rather than trying to
implement this logic in a view helper.
This commit is contained in:
Mike Dalessio
2025-05-21 16:30:18 -04:00
parent 6ab166b439
commit ecbe040e3e
5 changed files with 11 additions and 7 deletions
+2 -7
View File
@@ -66,15 +66,10 @@ module NotificationsHelper
end
def notification_closed?(notification)
card_for_notification(notification).closed?
notification.card.closed?
end
def notification_color(notification)
card_for_notification(notification).color
end
def card_for_notification(notification)
eventable = notification.source.eventable
eventable.respond_to?(:card) ? eventable.card : eventable
notification.card.color
end
end
+4
View File
@@ -31,6 +31,10 @@ class Card < ApplicationRecord
[ super, collection.name ].compact.join("/")
end
def card
self
end
private
def set_default_title
self.title = "Untitled" if title.blank?
+2
View File
@@ -9,6 +9,8 @@ class Event < ApplicationRecord
after_create -> { eventable.event_was_created(self) }
delegate :card, to: :eventable
def action
super.inquiry
end
+2
View File
@@ -7,6 +7,8 @@ class Mention < ApplicationRecord
after_create_commit :watch_source_by_mentionee
delegate :card, to: :source
def self_mention?
mentioner == mentionee
end
+1
View File
@@ -10,6 +10,7 @@ class Notification < ApplicationRecord
after_create_commit :broadcast_unread
delegate :notifiable_target, to: :source
delegate :card, to: :source
def self.read_all
update!(read_at: Time.current)