diff --git a/app/controllers/user_notifications_controller.rb b/app/controllers/user_notifications_controller.rb index 8c7404d24..ca05c3bbc 100644 --- a/app/controllers/user_notifications_controller.rb +++ b/app/controllers/user_notifications_controller.rb @@ -22,6 +22,7 @@ class UserNotificationsController < ApplicationController def load_notifications current_user.notifications + .in_app .order(created_at: :desc) end diff --git a/app/models/notification.rb b/app/models/notification.rb index 9bd6bb2da..286789a63 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true class Notification < ApplicationRecord - include Noticed::Model + belongs_to :recipient, polymorphic: true + scope :in_app, -> { where.not("notifications.params->'hide_in_app' = 'true'") } + private def can_send_to_user?(_user) diff --git a/app/notifications/base_notification.rb b/app/notifications/base_notification.rb index ae98891c5..d17d4a245 100644 --- a/app/notifications/base_notification.rb +++ b/app/notifications/base_notification.rb @@ -35,7 +35,12 @@ class BaseNotification < Noticed::Base private def database_notification? - recipient.notifications_settings.dig(notification_subgroup.to_s, 'in_app') + # always save all notifications, + # but flag if they should display in app or not + + params[:hide_in_app] = recipient.notifications_settings.dig(notification_subgroup.to_s, 'in_app') != true + + true end def email_notification?