diff --git a/app/controllers/notifications/mark_all_reads_controller.rb b/app/controllers/notifications/mark_all_reads_controller.rb new file mode 100644 index 000000000..2aad42028 --- /dev/null +++ b/app/controllers/notifications/mark_all_reads_controller.rb @@ -0,0 +1,5 @@ +class Notifications::MarkAllReadsController < ApplicationController + def create + Current.user.notifications.unread.read_all + end +end diff --git a/app/controllers/readings_controller.rb b/app/controllers/readings_controller.rb index 1bf106efd..fb7112b76 100644 --- a/app/controllers/readings_controller.rb +++ b/app/controllers/readings_controller.rb @@ -8,6 +8,6 @@ class ReadingsController < ApplicationController private def mark_bubble_notifications_read - Current.user.notifications.where(bubble: @bubble).update(read_at: Time.current) + Current.user.notifications.where(bubble: @bubble).read_all end end diff --git a/app/models/notification.rb b/app/models/notification.rb index da1cc9614..05d38c940 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -12,6 +12,12 @@ class Notification < ApplicationRecord broadcasts_to ->(notification) { [ notification.user, :notifications ] }, inserts_by: :prepend + class << self + def read_all + update!(read_at: Time.current) + end + end + def read? read_at.present? end diff --git a/app/views/notifications/_tray.html.erb b/app/views/notifications/_tray.html.erb index fa4c650b4..476f0bc78 100644 --- a/app/views/notifications/_tray.html.erb +++ b/app/views/notifications/_tray.html.erb @@ -4,9 +4,9 @@ data: { controller: "dialog", turbo_permanent: true, dialog_modal_value: false, dialog_target: "dialog", action: "keydown.esc->dialog#close:stop click@document->dialog#closeOnClickOutside" } do %> <%= turbo_frame_tag("notifications", src: notifications_tray_path) -%>