使用 FCM Firebase 向除登录用户之外订阅该主题的所有用户推送通知 [英] Push notification to all the users subscribed to the topic except login user using FCM Firebase

查看:40
本文介绍了使用 FCM Firebase 向除登录用户之外订阅该主题的所有用户推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有一个拥有超过一万名成员的群组,我为一个群组创建了一个主题(通知主题),群组中的所有用户都订阅了该主题.现在在组内,任何用户都可以添加图片、文件或视频等帖子.当用户添加帖子时,我需要向订阅该主题的所有用户发送通知,但除了一个,即添加帖子的人.我怎样才能做到这一点??

Now i have a group which have more than ten thousand members and for a group i have created a topic(Notification topic) where all the users in the group subscribed to that topic. Now inside the group any user can add post like image or file or video. When user add the post i need to send notification to all the users subscribed to that topic but except one, that is person who add the post. How can i achieve this??

现在通知将发送给所有用户,包括添加帖子的人.

Now notification is going to all the users including the person who add the post.

推荐答案

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

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 是否是用户的.如果是同一用户,则不显示通知,否则显示.例如:

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;
}

这篇关于使用 FCM Firebase 向除登录用户之外订阅该主题的所有用户推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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