如何知道Firebase DataSnapshot何时保留在服务器端

时间:2022-10-29 12:52:21

I'm building a chat using Firebase, using offline feature (keepSynced(true))

我正在使用Firebase构建聊天,使用离线功能(keepSynced(true))

It works very well except that I cant find a way to know if the DataSnapshot message has indeed been saved server side, as if I query for the message Firebase will tell me that it exists (it does locally!).

它工作得非常好,除了我无法找到一种方法来了解DataSnapshot消息是否确实已经保存在服务器端,就好像我查询消息Firebase将告诉我它存在(它在本地!)。

I found about transactions but it does not save offline.

我找到了关于交易的信息,但它没有离线保存。

I also found about checking the connection status of Firebase, but it is a global status, and does not reflect one by one snapshot status.

我还发现了检查Firebase的连接状态,但它是全局状态,并不反映逐个快照状态。

The only solution that I found is adding a property "persisted" on my message objected, this property being set by a server side function, but that seems overkill for this purpose. I'm pretty sure Firebase does know locally which values are not persisted yet ?

我找到的唯一解决方案是在我的消息中添加一个“持久”属性,该属性由服务器端函数设置,但这似乎有点过分。我很确定Firebase确实知道哪些值还没有持久化?

1 个解决方案

#1


1  

On Android, when you perform any operation that writes, you will either get a Task object in return, or you may specify a CompletionListener as an argument. Either of these will indicate when the data is received by the server. If you don't use these, you have no other indication.

在Android上,当您执行任何写入操作时,您将获得一个Task对象作为回报,或者您可以指定CompletionListener作为参数。这些中的任何一个都将指示服务器何时接收数据。如果您不使用这些,则没有其他指示。

Using a Cloud Function to tag the location upon write is certainly another way to do it, if you can't hold on to the Task or CompletionListener.

如果您无法保留Task或CompletionListener,则使用Cloud Function在写入时标记位置当然是另一种方法。

#1


1  

On Android, when you perform any operation that writes, you will either get a Task object in return, or you may specify a CompletionListener as an argument. Either of these will indicate when the data is received by the server. If you don't use these, you have no other indication.

在Android上,当您执行任何写入操作时,您将获得一个Task对象作为回报,或者您可以指定CompletionListener作为参数。这些中的任何一个都将指示服务器何时接收数据。如果您不使用这些,则没有其他指示。

Using a Cloud Function to tag the location upon write is certainly another way to do it, if you can't hold on to the Task or CompletionListener.

如果您无法保留Task或CompletionListener,则使用Cloud Function在写入时标记位置当然是另一种方法。