Merge pull request #6808 from artoscinote/ma_SCI_9863

Always save notifications to database, but filter them [SCI-9869]
This commit is contained in:
Martin Artnik 2023-12-12 14:09:23 +01:00 committed by GitHub
commit 543ac1a404
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -22,6 +22,7 @@ class UserNotificationsController < ApplicationController
def load_notifications
current_user.notifications
.in_app
.order(created_at: :desc)
end

View file

@ -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)

View file

@ -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?