【问题标题】:How to modify firebase database so that i can set a read or unread status如何修改firebase数据库以便我可以设置已读或未读状态
【发布时间】:2018-12-15 23:47:15
【问题描述】:

我需要在通知铃中显示来自 firebase 的未读消息数。 我已完成在我的 Web 应用程序中显示我收藏中的所有内容。但是当有新消息到达时,我需要通过在通知铃中显示未读消息计数来向用户提供反馈。据我了解,为此我需要设置一个firebase 集合中的已读/未读状态。有没有其他方法可以在我的 React Web 应用程序中显示未读消息的计数?

我正在使用 npm 的 firebase 包来显示消息。

以下是我的 firebase 集合中的示例数据。

name:"John Doe",
message:"you got a new appointment"

我是新手 firebase请帮助我解决这个问题。

【问题讨论】:

    标签: reactjs firebase firebase-realtime-database notifications


    【解决方案1】:

    如果我理解正确,您会想要使用状态标志(读取:布尔值),除非您不介意将所有新消息写入特定路径并将它们移动到之后的另一条路径被读取。

    如下图

    /user/unread-msg => all new messages come here
    /user/read-msg   => messages are moved here after being read.
    

    我相信这比使用简单的标志效率低。

    您可以使用 firebase 云函数来维护特定路径中子元素的计数,例如 /user/unread-msg/user/read-msg,这样您就不必下载整个数据来获取计数。

    参考示例代码https://github.com/firebase/functions-samples/tree/master/child-count

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      相关资源
      最近更新 更多