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:
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -9,6 +9,8 @@ class Event < ApplicationRecord
|
||||
|
||||
after_create -> { eventable.event_was_created(self) }
|
||||
|
||||
delegate :card, to: :eventable
|
||||
|
||||
def action
|
||||
super.inquiry
|
||||
end
|
||||
|
||||
@@ -7,6 +7,8 @@ class Mention < ApplicationRecord
|
||||
|
||||
after_create_commit :watch_source_by_mentionee
|
||||
|
||||
delegate :card, to: :source
|
||||
|
||||
def self_mention?
|
||||
mentioner == mentionee
|
||||
end
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user