如何使用FCM主题在聊天应用程序中进行通知? [英] How to use FCM topics for notification in chat app?

查看:79
本文介绍了如何使用FCM主题在聊天应用程序中进行通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有Flutter和Firestore后端的聊天功能.

I am make chat feature with Flutter and Firestore backend.

每条消息都是Firestore集合中具有UID和文本字段的新文档.聊天是1:1且随机的,因此在进入聊天之前不知道用户会与谁交谈.聊天集合中的DocID都是自动ID.

Every message is new document in Firestore collection with UID and text field. Chat is 1:1 and random so no know who user will talk to before enter chat. DocID in chat collection are all auto-id.

我已阅读可以使用主题来管理发送通知.这比使用单个设备的fcm令牌要容易.

I have read can use topics to manage send notification. This should be easier than use individual device fcm token.

任何人都知道如何为这个随机的1:1聊天应用程序实现使用主题吗?

Anyone know how to implement use topic for this random 1:1 chat app?

推荐答案

您绝对可以为每个1:1会话使用一个单独的主题,例如,使用我在此处描述的命名方案:

You can definitely use a separate topic for each 1:1 conversation, for example with the naming scheme I described here: Best way to manage Chat channels in Firebase. But there are some things to consider which, as Doug already pointed out in his comment, leads most developers to not solely use FCM for their chat apps.

例如:FCM主题不安全.这意味着找到主题ID的任何人都可以订阅它,从而偷听1:1对话.而且,尽管您可以生成难以猜测的主题,但也不应依赖于不知道主题ID作为一种安全机制.

For example: FCM topics are not secured. This means that anyone who finds out the topic ID can subscribe to it, and thus overhear the 1:1 conversation. And while you can generate topics that are hard to guess, you should not rely on not knowing the topic ID as a security mechanism.

考虑替代方案的另一个原因是FCM消息是瞬态的:一旦传递了它们,便不再有任何痕迹.使用当前的Firestore实现,您可以查询数据库以显示所有消息,而使用纯FCM实现,则必须构建自己的数据库(如果您的应用程序需要这样做).

Another reason to consider alternatives is that FCM messages are transient: once they are delivered there is no longer any trace of them. With your current Firestore implementation you can query the database to get all messages to show, while with a pure FCM implementation you will have to build your own database (if that is required for your app).

由于这些原因,我所知道的大多数聊天应用程序都将FCM(用于推送通知)和在线数据库(用于持久性)结合起来用作后端服务.

For these reasons most chat apps I know of use a combination of FCM (for push notifications) and an online database (for persistence) as their backend services.

这篇关于如何使用FCM主题在聊天应用程序中进行通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆