Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [firebase_messaging] All incoming Firebase notifications are handled as notification type #3696

Closed
james-airspace opened this issue Sep 30, 2020 · 1 comment · Fixed by #4012
Labels
plugin: messaging type: bug Something isn't working

Comments

@james-airspace
Copy link

james-airspace commented Sep 30, 2020

Bug report

Describe the bug
Firebase Messaging library appears to not handle data messages. Data messages are converted to notification messages as part of the remote message parsing that the library does after receiving the notification from firebase.

Steps to reproduce

Steps to reproduce the behavior:

  1. Add firebase_messaging library to project and configure
  2. Put the app in the background
  3. Send a data notification to the app. I am using this to send the push:
curl --location --request POST 'https://fcm.googleapis.com/fcm/send' \
--header 'Content-Type: application/json' \
--header 'Authorization: key=<REDACTED> \
--data-raw '{
  "registration_ids": ["<REDACTED>"],
  "data": {
    "foobar": "bazbar"
  }
}'

The above data notification is attempted to be delivered to the system tray as a notification message type, but it fails with this error:

NoSuchMethodError: The method 'call' was called on null.
Receiver: null
Tried calling: call(_LinkedHashMap len:1)

If I foreground the app and send the notification again, this is what I get back in the onMessage callback.
{notification: {title: null, body: null}, data: {foobar: bazbar}}

This payload shouldn't have a notification key within the payload. This is why the logs display an error when the app is backgrounded. The system is trying to create a notification with null body/title. Looks like the Firebase Messaging library is adding the notification key, even when the notification key is null in the message received from Firebase. I found what looks to be the culprit.

https://github.com/FirebaseExtended/flutterfire/blob/master/packages/firebase_messaging/android/src/main/java/io/flutter/plugins/firebasemessaging/FirebaseMessagingPlugin.java#L135

Looks like the parseRemoteMessage function appends a notification object to the map, even when remoteMessage.getNotification() is null.

Expected behavior

Data messages sent to the app with the plugin registered are still handled as data messages.

Branch with fix
https://github.com/james-airspace/flutterfire/tree/fix-3696

@james-airspace james-airspace added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Sep 30, 2020
@james-airspace james-airspace changed the title 🐛 [firebase_messaging] All incoming Firebase notifications are handled as notification type when plugin is registered 🐛 [firebase_messaging] All incoming Firebase notifications are handled as notification type Sep 30, 2020
@dackers86
Copy link
Member

PR created based on the above branch. #3704

@darshankawar darshankawar added plugin: messaging and removed Needs Attention This issue needs maintainer attention. labels Oct 1, 2020
@firebase firebase locked and limited conversation to collaborators Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: messaging type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants