Change priority notification level for mentions and assignments

This commit is contained in:
Fernando Olivares
2026-01-21 21:38:07 -06:00
committed by Rosa Gutierrez
parent 2f9e41d356
commit c7d0559191
4 changed files with 72 additions and 22 deletions
+4
View File
@@ -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)
+4
View File
@@ -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)
@@ -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
@@ -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")