From 397fc1d2bd012e8100fe3e1c0f6ceadda752c8b3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 16 Apr 2025 16:21:54 +0200 Subject: [PATCH] Only broadcast creations --- app/models/notification.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 3980c3d8d..d4ea87a95 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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