按客户端过滤网络通知

Filter web notifications by client-side

当我向某些主题发送通知时,例如...

const message = {
  data: { cost: 49 },
  topic: 'apple'
}
admin.messaging().send(message)

问题是关于 preventing/filtering 通知 如果用户设置类似 >= 50 ? (Firestore/localStorage?)

我该怎么做?

我认为应该使用 messaging-sw.js 进行过滤,但是如何实现?

或者有什么更好的主意,或者我遗漏了什么?

案例 1:When your app is in the foreground

案例 2:When your app is in background

  • 将用户的数据保存在IndexedDB中,因为用户可以在service worker
  • 中访问IndexedDB数据
  • 您必须在 firebase-messaging-sw.js 文件中将函数 setBackgroundMessageHandler 自定义为 this guideline 处理用户的选项
  • 注意:如果您在消息负载中设置通知字段,则不会调用您的 setBackgroundMessageHandler 回调,而是 SDK 根据您的负载显示通知。

无论如何,在客户端使用过滤器不是一个好方法,应该在服务器端使用