且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

向使用FCM Firebase登录的主题的所有用户推送通知(登录用户除外)

更新时间:2023-12-05 22:02:34

当前没有任何类型的参数可以排除特定用户从他们订阅的主题中接收消息.但是,作为解决方法,您可以在构建有效负载并处理接收消息的过程中简单地使用自定义实现.

There is currently no parameter of any sort to exclude a specific user from receiving a message from a topic they are subscribed to. However, as a workaround, you could simply have a custom implementation on building the payload and handling the message to receive it.

根据构建有效负载的方式,您可以添加一个自定义键值对,其中包括发布数据的用户ID(类似于posterId或简单地userId).

Depending on how you build your payload, you could just add a custom key-value pair that includes the user id of the one who posted the data (something like posterId or simply userId).

然后在您的客户端上,在处理推送通知时,只需检查ID是否为用户的ID.如果是同一用户,则不显示通知,否则显示它.例如:

Then on your client side, when handling the push notification, just check if the id is the user's or not. If it is the same user, don't show the notification, else show it. e.g.:

if (userId == currentUserId) {
    // if user is the one that sent the message, don't show the notification
    return;
}