Use payload transport to dispatch voip notifications to android#162
Use payload transport to dispatch voip notifications to android#162enahum wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR refactors Android notification transport handling by extracting a new ChangesAndroid notification transport-aware refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
server/android_notification_test.go (1)
86-119: ⚡ Quick winAdd one regression case for unsupported transport coercion.
Please add a case with
Transport: "unexpected"and assert resolved transport isPushTransportStandard, novoipflag, and no TTL override. That locks in bounded-label behavior.Suggested test addition
func TestBuildAndroidMessageTransportRouting(t *testing.T) { @@ t.Run("standard transport has no voip flag and no TTL override", func(t *testing.T) { @@ require.Nil(t, fcmMsg.Android.TTL) }) + + t.Run("unsupported transport is coerced to standard", func(t *testing.T) { + msg := &PushNotification{ + DeviceID: "tok", + Type: PushTypeMessage, + Transport: "unexpected", + } + fcmMsg, transport := buildAndroidMessage(msg) + + require.Equal(t, PushTransportStandard, transport) + _, hasVoIP := fcmMsg.Data["voip"] + require.False(t, hasVoIP) + require.Nil(t, fcmMsg.Android.TTL) + }) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/android_notification_test.go` around lines 86 - 119, Add a regression subtest in TestBuildAndroidMessageTransportRouting that constructs a PushNotification with Transport set to the unexpected string "unexpected", call buildAndroidMessage(msg) and assert the returned transport equals PushTransportStandard, that fcmMsg.Data does not contain the "voip" key, and that fcmMsg.Android.TTL is nil; reference symbols: TestBuildAndroidMessageTransportRouting, PushNotification, buildAndroidMessage, PushTransportStandard, and fcmMsg.Android.TTL to locate where to add the case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@server/android_notification_server.go`:
- Around line 120-123: The current code assigns transport := msg.Transport and
only defaults empty strings, which lets arbitrary values flow downstream; update
the normalization so that after reading msg.Transport you explicitly map allowed
values to the bounded set (e.g., if msg.Transport == PushTransportVoIP then
transport = PushTransportVoIP else transport = PushTransportStandard), treating
any other non-empty/unrecognized string as PushTransportStandard; ensure this
normalized transport variable (used later for Prometheus labels) is what is
returned/used by the relevant handler functions.
---
Nitpick comments:
In `@server/android_notification_test.go`:
- Around line 86-119: Add a regression subtest in
TestBuildAndroidMessageTransportRouting that constructs a PushNotification with
Transport set to the unexpected string "unexpected", call
buildAndroidMessage(msg) and assert the returned transport equals
PushTransportStandard, that fcmMsg.Data does not contain the "voip" key, and
that fcmMsg.Android.TTL is nil; reference symbols:
TestBuildAndroidMessageTransportRouting, PushNotification, buildAndroidMessage,
PushTransportStandard, and fcmMsg.Android.TTL to locate where to add the case.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 85a7f796-19df-438f-9400-ee6bc0997871
📒 Files selected for processing (2)
server/android_notification_server.goserver/android_notification_test.go
| transport := msg.Transport | ||
| if transport == "" { | ||
| transport = PushTransportStandard | ||
| } |
There was a problem hiding this comment.
Normalize unsupported transport values before returning transport.
Line [120] through Line [123] currently forwards any non-empty msg.Transport downstream. That value is later used as a Prometheus transport label (Line [195], Line [226], Line [248], Line [256], Line [258]), which can explode metric cardinality if unexpected values arrive. Coerce to a bounded set (PushTransportStandard / PushTransportVoIP) before returning.
Suggested fix
- transport := msg.Transport
- if transport == "" {
- transport = PushTransportStandard
- }
+ transport := PushTransportStandard
+ if msg.Transport == PushTransportVoIP {
+ transport = PushTransportVoIP
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| transport := msg.Transport | |
| if transport == "" { | |
| transport = PushTransportStandard | |
| } | |
| transport := PushTransportStandard | |
| if msg.Transport == PushTransportVoIP { | |
| transport = PushTransportVoIP | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@server/android_notification_server.go` around lines 120 - 123, The current
code assigns transport := msg.Transport and only defaults empty strings, which
lets arbitrary values flow downstream; update the normalization so that after
reading msg.Transport you explicitly map allowed values to the bounded set
(e.g., if msg.Transport == PushTransportVoIP then transport = PushTransportVoIP
else transport = PushTransportStandard), treating any other
non-empty/unrecognized string as PushTransportStandard; ensure this normalized
transport variable (used later for Prometheus labels) is what is returned/used
by the relevant handler functions.
lieut-data
left a comment
There was a problem hiding this comment.
Looks good, but agree with CodeRabbit's feedback that we should guard against arbitrary transport values when logging the metric (map these to "unknown" instead).
Summary
this PR adds feature parity in order to receive calls on Android as we implemented for iOS
Ticket Link
TDB.