How to send direct message via Firebase from user to user?

浪尽此生 提交于 2021-02-04 21:28:50

问题


I am really rookie and need an advice.

I have read documentation, and as far as i understood if you need send direct message, follow next steps:

  1. Make authentification, eventually you get Firebase TokenId and userId
  2. Send them to your server side and store it in DB
  3. When you are going to send a message you need create json and put inside topic text and resipent userId so on...
  4. Send this json via HTTP to your server side
  5. When server retrive this json, it should use Firebase API to create new message bloc child with random name in firebase
  6. Eventually server have to find recipent user in DB by userId that we get from message.
  7. After server will find current recipent user by userId , next we should take firebase tokenId In order to sent notification .
  8. And send recipent user notification with such data - name of new message bloc child
  9. Recipent will connect to this current bloc and retrive data

It is as i understood this consept, fix me please if smth wrong?


回答1:


Your suggested approach sounds good. The most important thing to realize is that you require an app server to send a downstream message to a device. Using the database as the communication mechanism between the app and the app server is a popular approach.

You could also use Cloud Messaging's upstream capabilities. But I've never tried that approach, because the database works fine for me and I had little interest in learning yet another protocol (XMPP).

You can read how I implemented it in this Firebase blog post Sending notifications between Android devices with Firebase Database and Cloud Messaging.



来源:https://stackoverflow.com/questions/39244994/how-to-send-direct-message-via-firebase-from-user-to-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!