From ecbe040e3e6227b72c6c0752f83da53d326695dd Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 21 May 2025 16:30:18 -0400 Subject: [PATCH] Implement Notification#card Models now know how to find their cards, rather than trying to implement this logic in a view helper. --- app/helpers/notifications_helper.rb | 9 ++------- app/models/card.rb | 4 ++++ app/models/event.rb | 2 ++ app/models/mention.rb | 2 ++ app/models/notification.rb | 1 + 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index a748f2fdd..a0bc7b3b3 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -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 diff --git a/app/models/card.rb b/app/models/card.rb index 4b8f96db7..8707b2bf2 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -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? diff --git a/app/models/event.rb b/app/models/event.rb index 443e9170b..7e027849d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -9,6 +9,8 @@ class Event < ApplicationRecord after_create -> { eventable.event_was_created(self) } + delegate :card, to: :eventable + def action super.inquiry end diff --git a/app/models/mention.rb b/app/models/mention.rb index ac5cb336c..54a20e0ce 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -7,6 +7,8 @@ class Mention < ApplicationRecord after_create_commit :watch_source_by_mentionee + delegate :card, to: :source + def self_mention? mentioner == mentionee end diff --git a/app/models/notification.rb b/app/models/notification.rb index c6bc43a2e..6ae1b91bf 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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)