From b43eaa4517107326c7e73b949cec759f841b4a30 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 13 Mar 2024 11:35:49 +0100 Subject: [PATCH] Refactor notification filtering behavior definition (#29567) --- app/models/notification.rb | 46 +++++++++++++++++++++++++--------- app/services/notify_service.rb | 2 +- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index e322daea4a..861a154369 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -29,18 +29,40 @@ class Notification < ApplicationRecord 'Poll' => :poll, }.freeze - TYPES = %i( - mention - status - reblog - follow - follow_request - favourite - poll - update - admin.sign_up - admin.report - ).freeze + PROPERTIES = { + mention: { + filterable: true, + }.freeze, + status: { + filterable: false, + }.freeze, + reblog: { + filterable: true, + }.freeze, + follow: { + filterable: true, + }.freeze, + follow_request: { + filterable: true, + }.freeze, + favourite: { + filterable: true, + }.freeze, + poll: { + filterable: false, + }.freeze, + update: { + filterable: false, + }.freeze, + 'admin.sign_up': { + filterable: false, + }.freeze, + 'admin.report': { + filterable: false, + }.freeze, + }.freeze + + TYPES = PROPERTIES.keys.freeze TARGET_STATUS_INCLUDES_BY_TYPE = { status: :status, diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb index 66cbff0ef8..f3d16f1be7 100644 --- a/app/services/notify_service.rb +++ b/app/services/notify_service.rb @@ -83,7 +83,7 @@ class NotifyService < BaseService end def filter? - return false if NON_FILTERABLE_TYPES.include?(@notification.type) + return false unless Notification::PROPERTIES[@notification.type][:filterable] return false if override_for_sender? from_limited? ||