From 53ebb509d8840513fb54220675dcd18fa519ffd1 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 3 Jul 2025 12:05:41 -0400 Subject: [PATCH] Broadcast when all notifications are cleared Then make the turbo response to clearing all notifications a no-op. This has the bonus side effect of properly clearing the notifications try on all open pages. ref: https://fizzy.37signals.com/5986089/collections/2/cards/796 --- app/controllers/notifications/readings_controller.rb | 5 ++++- app/models/notification.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/notifications/readings_controller.rb b/app/controllers/notifications/readings_controller.rb index 5f593fa95..805bb1a67 100644 --- a/app/controllers/notifications/readings_controller.rb +++ b/app/controllers/notifications/readings_controller.rb @@ -6,6 +6,9 @@ class Notifications::ReadingsController < ApplicationController def create_all Current.user.notifications.unread.read_all - redirect_to notifications_path + respond_to do |format| + format.html { redirect_to notifications_path } + format.turbo_stream { } # No action needed, readings will have been broadcast + end end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 6ae1b91bf..73525f4ff 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -13,7 +13,7 @@ class Notification < ApplicationRecord delegate :card, to: :source def self.read_all - update!(read_at: Time.current) + all.each { |notification| notification.read } end def read