How to make a chat application in react native? - javascript

I have build chat UI for my application using react-native-gifted-chat. I have connected the sent messages and received messages with the services. Can anyone help me with the issue of messages not getting updated instantly as the message is received?
Do I need to hit services again and again to refresh the chat message? if yes then how?
Or do I need to implement some kind of push notification? if yes then how?
I just want to make my chat screen update the message instantly when current user receives a message from another user.

Well, for update the message instantly when current user receives a message from another user you need to use firebase realtime database. it provides you to live data instantly..(for more info refer this tutorial https://medium.com/#platypus/react-native-chat-application-679dbff3ccd3)
and for other option Socket.io also provides live data and it is better than firebase realtime database.

Related

How do I send a push notification to my android app whenever a new data is pushed into my firebase realtime database in javascript?

I have both my web app and my android app included into my firebase project. Using the web app, the user can insert data into the realtime database. Using the android app, the user can view his record, which is read from the realtime database.
My javascript:
firebase.database().ref("db/0/").push(
{
"name":"XXXX",
"age":YY,
"address":"ABCDEF"
}
)
//I want to send a notification to the app, whenever a new data is pushed
I want to send a notification to the app, whenever a new data is pushed into the realtime database. How do I proceed?
Calls to the FCM REST API to send a message to a device require that you specify the FCM server* key in your code. As its name implies, this key should only be used in server-side code, or in an otherwise trusted environment.
The reason for this is that anyone who has the FCM server key can send whatever message they want to all of your users. By including this key in your Android or web app, a malicious user can find it and you're putting your users at risk.
See How to send one to one message using Firebase Messaging for a better solution, which also links to the Firebase documentation of using Cloud Functions to notify a usr when something relevant to them happens in the Realtime Database.

How to handle offline messages in React-Native using NodeJS and SocketIO

I am currently using SocketIO and NodeJS to handle messages. However the problem is that when the user becomes offline there's no way that the other user will receive the message.
The solution I came up with was to store the message in the database.
But a new problem arise, when fetching the message and push notification.
If I do fetch for "n" minutes in the server when the app is in background/inactive. There will be a lot of request in the server, and I personally think that it is inefficient. and also it drains the battery.
What is the proper way how to handle fetching the messages from database or pushing notification in app without making too much request in "n" minutes and draining too much power?
You need to save the last sync time in the App. And whenever app comes from background/Inactive state. You need to call an API with this time. This API will give you all the messages and the Push notification which has comes after the last sync time. In this way, With one API call, you will be able to get all the messages and push notifications. I had used this approach to syncing my data in one of my app.
My suggestion is to implement a system of background jobs in the API, checking when there is a new notification to be launched, or with the notification already ready waiting to be launched in the queue. You can search for queue manager like Bull, Bee-Queue.
To launch push notification in the closed/inactive app, you can use a service like OneSignal or Firebase.
I implemented this a few weeks ago and did it this way.
API = Node.js, Bull Queue
App = React Native, OneSignal
Going back to this question if somebody stumbled upon this question.
The best way to handle offline messages regardless if you are using NodeJS/MongoDB, etc. is to store it on server's database. Then call an API that fetches the the messages which is equal to user's ID whenever the mobile app comes to foreground.
If your problem is that you needed notification and you are using
react-native-push-notifications / react-native-push-notification-ios
Then you should use the data notification to include the message on notification parameter on the server's side(Assuming that you are using Firebase Cloud Messaging). With this way you can directly save the message on the mobile's database.

How to push notification by a device to another device in react native

Can anyone tell me how to push notification by a device to another device ? Maybe that’s good if it in One Signal , but no problem if also by firebase ?
For android
My approach is to use firebase.
Use need a server and a database.
You initialize firebase in your app.
When user open your application you get token from firebase and send it to your server and in your server you store token for each user.
And then when a user wants to send message to another user, it call an api from your server to send notification to specific user.
And in your server you have firebase token for each user and by using that you can send push notification to that user with apis that firebase prepared.

Web Push API- Service worker notification [duplicate]

I am wondering if I can use web push notifications to update a web page without displaying a notification for the user to interact with. Essentially I want to refresh data after an event on the server.
If this is possible, is it still necessary to receive permission from the user to send these push updates?
Yes, you can send push messages without showing a notification, but there are limitations on both Firefox and Chrome on the raw number of "invisible" push messages and the rate at which you send them.
You can experiment a bit with the quotas in different browers using the Push Quota ServiceWorker Cookbook example.

Notification in web application when a database is updated

i am trying to develop a web application, which should show a notification ( similar to facebook notifications) whenever there is an update in a database.
Could someone please help me with the notifications part? are there any third party tools/plugins which can achieve this?
Thanks
First of all what kind of technologies are you using? (Backend and FrontEnd)
In a general way you need 2 things:
Backend after a DB update sends notifications through Websockets to notify all clients.
Clients subscribes the notifications and when receives a notification, then updates the UI.

Categories

Resources