Files
fizzy/app/models/notifier.rb
T
Stanko K.R. 36ee253a1a Stack notifications everywhere
We had client-side notification stacking in the tray since launch, but now we want to stack notifications in the notifications page, in API responses and in email bundles.
2026-02-12 10:29:50 +01:00

39 lines
923 B
Ruby

class Notifier
attr_reader :source
class << self
def for(source)
case source
when Event
"Notifier::#{source.eventable.class}EventNotifier".safe_constantize&.new(source)
when Mention
MentionNotifier.new(source)
end
end
end
def notify
if should_notify?
# Processing recipients in order avoids deadlocks if notifications overlap.
recipients.sort_by(&:id).map do |recipient|
notification = Notification.find_or_initialize_by(user: recipient, card: source.card)
notification.source = source
notification.creator = creator
notification.read_at = nil
notification.unread_count = (notification.unread_count || 0) + 1
notification.save!
notification
end
end
end
private
def initialize(source)
@source = source
end
def should_notify?
!creator.system?
end
end