Get only new “child added” after page load

后端 未结 1 1852
臣服心动
臣服心动 2021-01-27 22:53

I have on a website facebook style notification in top right corner. I show there up to 5 latest notifications. I do initial pulling with child_added

相关标签:
1条回答
  • 2021-01-27 23:17

    One solution would be to have your local client listen for the last 5 latest notifications via ref.limitToLast(5).on('child_added', ...) and then only render them to the user if some timestamp field on each of those notifications is newer than your local timestamp on the machine.

    When writing those notifications from other clients, you could include a timestamp field as specified via Firebase.ServerValue.TIMESTAMP, which will use the server's notion of the Unix timestamp. Readers of that data could then compare that timestamp to their local clock to make the aforementioned determination.

    0 讨论(0)
提交回复
热议问题