Skip to content

fix(push): post no notification for data-only pushes - #2013

Merged
ArnabChatterjee20k merged 3 commits into
mainfrom
fix/push-data-only-notification
Oct 13, 2026
Merged

ArnabChatterjee20k merged 3 commits into
mainfrom
fix/push-data-only-notification

Conversation

@abnegate

Copy link
Copy Markdown
Member

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 Android PushReceiver. Payloads that aren't a JSON object keep today's fallback.

@ArnabChatterjee20k could you review?

Root cause

notificationContent() only tracked whether a notification block 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 Web push.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 main instance:

  1. Subscribe a device as users/e2e-native-a.
  2. Call messaging.createPush with no title or body, data {saleId: "dataonly"}.
  3. Both SDKs posted a notification titled users/e2e-native-a with 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.
  • The body falls back to the payload only when raw.

Each notify path returns early when the content isn't visible. Callbacks and PushReceiver run 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 plain push-payload still 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

  • Android Tests.kt, "Push notification content":
    • empty, data-only, image-only and contentAvailable/badge envelopes post nothing; the server title/body case still posts;
    • a data-only envelope delivered through PushBackground.deliverMessage (now internal; the object is already internal) reaches a live PushListener and E2EPushReceiver with no notification.
    • Fails on main, passes on the branch.
  • React Native push.node.js, new Push notification content JS line: calls notify with six payloads; a scheduleNotificationAsync recorder in the expo-notifications shim checks that only the raw and server cases post. REACT_NATIVE_PUSH_OPENED_RESPONSES is renamed REACT_NATIVE_PUSH_JS_RESPONSES.
  • Flutter: new test/src/mqtt_notification_test.dart covering every envelope shape and the raw cases.
  • Web has no harness for this path; it shares the same model.

Notes

  • This changes one existing Android E2E expectation: {"notification":{}} used to post an "E2E title" notification with no text and now posts nothing.
  • The Android Docker E2E lanes couldn't run locally (host resources); the changed Tests.kt block 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.
  • Apple Push.swift.twig has 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

abnegate and others added 3 commits October 13, 2026 20:49
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]>
@ghost

ghost commented Oct 13, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The changed notification paths preserve callback delivery and correctly gate posting on visible content.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 16
File Change
src/SDK/Language/Flutter.php Registers the Flutter notification-content unit test template.
templates/android/README.md.twig Documents notification behavior for data-only and non-object payloads.
templates/android/library/src/main/java/io/package/services/PushBackground.kt.twig Adds raw/visible notification content and skips posting invisible envelopes.
templates/flutter/README.md.twig Documents Flutter notification behavior for data-only and raw payloads.
templates/flutter/lib/src/mqtt_browser.dart.twig Skips browser notification posting when content is not visible.
templates/flutter/lib/src/mqtt_foreground.dart.twig Skips foreground notification posting while still forwarding messages.
templates/flutter/lib/src/mqtt_notification.dart.twig Defines Flutter raw-payload, visibility, and body-fallback rules.
templates/flutter/test/src/mqtt_notification_test.dart.twig Tests Flutter notification content across envelope and raw payload cases.
templates/react-native/README.md.twig Documents React Native notification behavior for data-only and raw payloads.
templates/react-native/src/services/push.ts.twig Computes notification content once per message and skips invisible notifications.
templates/web/src/services/push.ts.twig Adds shared content parsing and skips browser notifications for invisible envelopes.
tests/e2e/Base.php Adds the React Native JS notification-content response to the expected results.
tests/e2e/ReactNativeAndroidTest.php Uses the renamed React Native JS response group.
tests/e2e/languages/android/Tests.kt Tests invisible envelopes, visible server content, and callback/receiver delivery.
tests/e2e/languages/react-native/push.node.js Tests which payload cases schedule React Native notifications.
tests/e2e/languages/react-native/shims/expo-notifications/index.js Records scheduled notifications for the React Native JS test.

Reviewed 1c62c6f · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

ArnabChatterjee20k added a commit that referenced this pull request Oct 13, 2026
…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 ArnabChatterjee20k left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ArnabChatterjee20k
ArnabChatterjee20k merged commit 512edea into main Oct 13, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants