question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Appending message using FCM event

See original GitHub issue

Issue Description

An error occurred when appending a message

Steps to Reproduce / Code Snippets

  • Below codes works find when I use with local method, but when I put the code inside FCM event method ( FCM.on(FCMEvent.Notification, async (notif) => () ), it throws an error.
FCM.on(FCMEvent.Notification, async (notif) => {
      if (this._mounted && notif.action === FCM.BACKEND_ACTION_MESSAGE) {
        const { state } = this.props.navigation;
        if (notif.chat_room_id === state.params.chatRoomId) {
          let arrMsg = [];
          let objMsg = {};
          objMsg._id = notif.message_id;
          objMsg.createdAt = new Date(notif.date);
          objMsg.text = notif.message;
          let objUsr = {};
          objUsr._id = parseInt(notif.sender_contact_id);
          objUsr.avatar = 'https://avatars0.githubusercontent.com/u/9919?v=4&s=40';
          objMsg.user = objUsr;
          
          arrMsg.push(objMsg);
          this.stateMessages = GiftedChat.append(this.stateMessages, arrMsg);  //### THIS THROWS AN ERROR
        }
      }
    });

Error Msg

Invalid Date <unknown> .\node_modules\react-native-gifted-chat\src\MessageContainer.js: 44:38

PrepareMessages .\node_modules\react-native-gifted-chat\src\MessageContainer.js: 40:28

componentWillRecediveProps .\node_modules\react-native-gifted-chat\src\MessageContainer.js: 70:46

Additional Information

  • React Native version: “react-native”: “^0.48.4”
  • react-native-gifted-chat version: “react-native-gifted-chat”: “^0.2.7”
  • FCM: “react-native-fcm”: “^9.6.2”
  • Platform(s) (iOS, Android, or both?): BOTH

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
andreluisjunqueiracommented, Apr 4, 2018

latest version. when a try in debug mode works, but when a disable debug mode, i get this error “invalid date”

0reactions
prasannaballalcommented, Jul 3, 2019

The gifted chat expects the Date object. So if you are not sending date object it will not work in debug mode. When debugging with chrome, chrome does some magic and makes it work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase Cloud Messaging
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.
Read more >
Append messages to push notification - Firebase
Use a messages array to store all the incoming messages. If the user have clicked on the notification, you can use "Notification Click...
Read more >
Web Push Notification with Firebase Cloud Messaging
Send and receive web push notifications with Firebase Cloud Messaging (FCM). This is a broad and shallow overview of the whole picture surrounding...
Read more >
How to Push Notification in Android using Firebase Cloud ...
Since receiving FCM notifications require the use of the internet, add the following permission to the AndroidManifest.xml file anywhere between ...
Read more >
Android Push Notifications (FCM) - IBM Cloud Docs
Create an Event Notifications service, add a push destination for Firebase Cloud Messaging (FCM), and send messages to Android devices. What is Event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found