From c7d0559191e68609678a73f899b769c47747a5b6 Mon Sep 17 00:00:00 2001 From: Fernando Olivares Date: Wed, 21 Jan 2026 21:38:07 -0600 Subject: [PATCH] Change priority notification level for mentions and assignments --- app/models/event.rb | 4 + app/models/mention.rb | 4 + .../models/notification/push_target/native.rb | 8 +- .../notification/push_target/native_test.rb | 78 ++++++++++++++----- 4 files changed, 72 insertions(+), 22 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index bbbf2a60c..6ba11a28d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -37,6 +37,10 @@ class Event < ApplicationRecord Event::Description.new(self, user) end + def high_priority_push? + action.card_assigned? + end + private def dispatch_webhooks Event::WebhookDispatchJob.perform_later(self) diff --git a/app/models/mention.rb b/app/models/mention.rb index 5491bfd9f..66a02428a 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -18,6 +18,10 @@ class Mention < ApplicationRecord source end + def high_priority_push? + true + end + private def watch_source_by_mentionee source.watch_by(mentionee) diff --git a/saas/app/models/notification/push_target/native.rb b/saas/app/models/notification/push_target/native.rb index 2eb4e5ef2..d2e86ead4 100644 --- a/saas/app/models/notification/push_target/native.rb +++ b/saas/app/models/notification/push_target/native.rb @@ -49,7 +49,7 @@ class Notification::PushTarget::Native < Notification::PushTarget badge: notification.user.notifications.unread.count, sound: "default", thread_id: card&.id, - high_priority: assignment_notification? + high_priority: high_priority_notification? ) end @@ -69,11 +69,11 @@ class Notification::PushTarget::Native < Notification::PushTarget end def interruption_level - assignment_notification? ? "time-sensitive" : "active" + high_priority_notification? ? "time-sensitive" : "active" end - def assignment_notification? - notification.source.is_a?(Event) && notification.source.action == "card_assigned" + def high_priority_notification? + notification.source.high_priority_push? end def creator_avatar_url diff --git a/saas/test/models/notification/push_target/native_test.rb b/saas/test/models/notification/push_target/native_test.rb index b684ec11a..93fe546c5 100644 --- a/saas/test/models/notification/push_target/native_test.rb +++ b/saas/test/models/notification/push_target/native_test.rb @@ -45,22 +45,6 @@ class Notification::PushTarget::NativeTest < ActiveSupport::TestCase assert_equal "card", push.send(:notification_category) end - test "interruption_level is time-sensitive for assignments" do - notification = notifications(:logo_assignment_kevin) - @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - - push = Notification::PushTarget::Native.new(notification) - - assert_equal "time-sensitive", push.send(:interruption_level) - end - - test "interruption_level is active for non-assignments" do - @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") - - push = Notification::PushTarget::Native.new(@notification) - - assert_equal "active", push.send(:interruption_level) - end test "pushes to native devices when user has devices" do stub_push_services @@ -130,7 +114,27 @@ class Notification::PushTarget::NativeTest < ActiveSupport::TestCase assert native.high_priority end - test "native notification sets normal priority for non-assignments" do + test "native notification sets high_priority for mentions" do + notification = notifications(:logo_card_david_mention_by_jz) + notification.user.identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") + + push = Notification::PushTarget::Native.new(notification) + native = push.send(:native_notification) + + assert native.high_priority + end + + test "native notification sets normal priority for comments" do + notification = notifications(:layout_commented_kevin) + @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") + + push = Notification::PushTarget::Native.new(notification) + native = push.send(:native_notification) + + assert_not native.high_priority + end + + test "native notification sets normal priority for other card events" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") push = Notification::PushTarget::Native.new(@notification) @@ -146,10 +150,48 @@ class Notification::PushTarget::NativeTest < ActiveSupport::TestCase native = push.send(:native_notification) assert_equal 1, native.apple_data.dig(:aps, :"mutable-content") - assert_includes %w[active time-sensitive], native.apple_data.dig(:aps, :"interruption-level") assert_not_nil native.apple_data.dig(:aps, :category) end + test "native notification sets time-sensitive interruption level for assignments" do + notification = notifications(:logo_assignment_kevin) + notification.user.identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") + + push = Notification::PushTarget::Native.new(notification) + native = push.send(:native_notification) + + assert_equal "time-sensitive", native.apple_data.dig(:aps, :"interruption-level") + end + + test "native notification sets time-sensitive interruption level for mentions" do + notification = notifications(:logo_card_david_mention_by_jz) + notification.user.identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") + + push = Notification::PushTarget::Native.new(notification) + native = push.send(:native_notification) + + assert_equal "time-sensitive", native.apple_data.dig(:aps, :"interruption-level") + end + + test "native notification sets active interruption level for comments" do + notification = notifications(:layout_commented_kevin) + @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") + + push = Notification::PushTarget::Native.new(notification) + native = push.send(:native_notification) + + assert_equal "active", native.apple_data.dig(:aps, :"interruption-level") + end + + test "native notification sets active interruption level for other card events" do + @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone") + + push = Notification::PushTarget::Native.new(@notification) + native = push.send(:native_notification) + + assert_equal "active", native.apple_data.dig(:aps, :"interruption-level") + end + test "native notification sets android notification to nil for data-only" do @identity.devices.create!(token: "test123", platform: "apple", name: "Test iPhone")