Repository navigation
fix(push): post no notification for data-only pushes - #2013
Conversation
A data-only push, or one whose notification block is empty or carries only an image or a badge, fell back to the subscription title or the topic (users/<id>) and showed the raw JSON envelope as the body on native, React Native and Flutter Android, which share these Kotlin templates. Appwrite always sends a JSON object, so an envelope is now shown only when it has a title or body; the message still reaches live callbacks and PushReceiver. A payload that is not a JSON object keeps the previous fallback of the subscription title and the raw payload as body. The Robolectric service test posts each of these envelopes and checks that none shows a notification, then delivers a data-only envelope through PushBackground.deliverMessage, now internal so the test can reach it, and checks that it reaches a live PushListener callback and, with none, the PushReceiver, with no notification posted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A push sent without a title or body reached the foreground service and the web client as a JSON envelope with no notification fields. PushNotificationContent only knew whether a notification block existed, so a data-only envelope fell back to the topic as the title and the raw envelope as the body, while an empty, badge-only or image-only block posted a notification titled with the subscription fallback and no text. The content now records whether the payload is raw (not a JSON object) and is visible only when raw or when the server sent a title or body. Envelopes with neither post nothing and still reach the subscription callback; payloads that are not a JSON object keep the title fallback with the raw payload as the body. A unit test covers each envelope shape and the raw case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and web A push sent without a notification title or body still posted a local notification: the React Native and Web SDKs treated any envelope without a `notification` block as a raw payload, so the user saw the topic (`users/<id>`) as the title and the JSON envelope as the body. An empty `notification` block posted a notification with the subscription title and no body. The content model now separates a raw payload (not a JSON object, such as a plain string sent straight to the broker) from an Appwrite envelope. A raw payload keeps its fallback to the subscription title and the payload as the body. An envelope is never shown raw, and one with neither a title nor a body (data-only, an empty block, badge or contentAvailable only, image only) posts nothing while still reaching subscription callbacks. The React Native push script now calls notify directly with a raw payload, a server title and body, a data-only envelope, an empty block, an image-only block and a contentAvailable and badge block, and checks through a scheduleNotificationAsync recorder in the expo-notifications shim that only the first two post. Its expected lines now live in REACT_NATIVE_PUSH_JS_RESPONSES, renamed from REACT_NATIVE_PUSH_OPENED_RESPONSES since it holds more than the opened checks. Web has no harness for this path; it shares the same model. Co-Authored-By: Claude Opus 5.5 <[email protected]>
🟢 Tier S · Ready to merge
This change suppresses visible notifications for JSON-object push envelopes without a notification title or body, while preserving raw-payload fallbacks and message delivery. It applies the same content rules across Android, Flutter, React Native, and Web, and adds notification-content tests and documentation updates.
📂 Walkthrough · 16
Reviewed |
…ext only Matches #2013 on the other SDKs: a payload that is not a JSON object is shown with itself as the body, and an envelope is shown only when its notification has a title or body. An empty or image-only notification block no longer posts a title-only banner, and a raw MQTT payload gets one again.
ArnabChatterjee20k
left a comment
There was a problem hiding this comment.
Reviewed: one notification rule across Android, Flutter, React Native and Web. A non-object payload is raw, and an envelope shows only with a title or body. Arrays, quoted strings, null and a non-object notification behave the same on every platform, and callbacks still run first. The Apple half is in #2000 (275a593) with the same rule.
Summary
A push sent without a notification title or body (a data-only push) posted a visible notification on Android (native, React Native and Flutter, which share the Kotlin templates), Flutter (Dart foreground/web) and React Native/Web JS. Its title was the topic (
users/<id>) and its body was the raw JSON envelope. Now a JSON-object envelope with no title and no body posts nothing but still reaches live callbacks and AndroidPushReceiver. Payloads that aren't a JSON object keep today's fallback.@ArnabChatterjee20k could you review?
Root cause
notificationContent()only tracked whether anotificationblock existed (present). When the block was missing,notify()fell back to the subscription title or topic for the title and the raw payload for the body. When the block existed but was empty or image-only, it posted the fallback title with no text. Every SDK copied the same logic:PushBackground.kt.twig,mqtt_notification.dart.twig, and React Native and Webpush.ts.twig.Repro (device testing)
Found while running the Android device scenarios, plus new edge cases, on Android emulators (native Android and React Native SDKs) against a real Appwrite
maininstance:users/e2e-native-a.messaging.createPushwith no title or body, data{saleId: "dataonly"}.users/e2e-native-awith body{"messageId":"edge-dataonly-…","data":{"saleId":"dataonly"},"priority":"high"}.Fix
One model on every platform:
raw: the payload is not a JSON object.visible = raw || title || body.raw.Each
notifypath returns early when the content isn't visible. Callbacks andPushReceiverrun before that check, so delivery is unchanged. A data-only, empty,contentAvailable/badge-only or image-only envelope posts nothing, matching FCM/APNs data-message semantics. The mock broker's plainpush-payloadstill shows<subscription title>/push-payload. React Native now computes the content once per message; Web and React Native define the rule in one place.Tests
Tests.kt, "Push notification content":contentAvailable/badge envelopes post nothing; the server title/body case still posts;PushBackground.deliverMessage(nowinternal; the object is already internal) reaches a livePushListenerandE2EPushReceiverwith no notification.push.node.js, newPush notification content JSline: callsnotifywith six payloads; ascheduleNotificationAsyncrecorder in the expo-notifications shim checks that only the raw and server cases post.REACT_NATIVE_PUSH_OPENED_RESPONSESis renamedREACT_NATIVE_PUSH_JS_RESPONSES.test/src/mqtt_notification_test.dartcovering every envelope shape and the raw cases.Notes
{"notification":{}}used to post an "E2E title" notification with no text and now posts nothing.Tests.ktblock ran on host Robolectric (debug and R8), red on main and green on the branch. ReactNativeAndroid passed locally on an identical tree. CI is the gate.Push.swift.twighas the same bug; it's left out because feat(apple): background push through APNs #2000 is changing that file. Follow-up after feat(apple): background push through APNs #2000 merges.🤖 Generated with Claude Code