Only broadcast creations

This commit is contained in:
David Heinemeier Hansson
2025-04-16 16:21:54 +02:00
parent 8ff71b2650
commit 397fc1d2bd
+8 -6
View File
@@ -9,16 +9,18 @@ class Notification < ApplicationRecord
scope :ordered, -> { order(read_at: :desc, created_at: :desc) }
delegate :creator, to: :event
after_create_commit :broadcast
broadcasts_to ->(notification) { [ notification.user, :notifications ] }, inserts_by: :prepend
class << self
def read_all
update!(read_at: Time.current)
end
def self.read_all
update!(read_at: Time.current)
end
def read?
read_at.present?
end
private
def broadcast
broadcast_prepend_to user, :notifications, target: "notifications"
end
end