turms-im / turms

🕊️ The world's most advanced open source instant messaging engine for 100K~10M concurrent users https://turms-im.github.io/docs
Apache License 2.0
1.75k stars 270 forks source link

关于客户端同步离线消息时机的疑问 #1512

Open lovemianhuatang opened 3 months ago

lovemianhuatang commented 3 months ago

在客户端启动时,如何同步离线时的数据变更?

我的想法是: 在客户端初始化时需要先同步离线期间需要同步的消息,比如:好友资料、群资料、最近会话、消息等。通过HTTP API同步。 然后登录建立TCP或者WebSocket连接,接收新消息。

如果直接建立TCP或者WebSocket,这时会收到新消息,但离线消息还没同步完成。客户端处理时会有冲突。有什么好的方式吗?

JamesChenX commented 3 months ago

好友资料、群资料、最近会话、消息等。通过HTTP API同步

The HTTP APIs are provided for admin users, and should not be used by application users directly. The APIs in client SDKs are provided for client applications to use.

客户端处理时会有冲突。有什么好的方式吗?

You can store your data (e.g. messages) in either local storage or memory, and deduplicate data by their IDs. For example, you can let your client application log in first, and then call client APIs to find history messages sent when the user is offline. At the same time, your client application can still receive the new messages. Just remember to deduplicate messages by their IDs.