我有以下关于创建聊天室的问题。消息模型有一个creationTimeStamp
属性,它是在用户从设备发送消息时分配的。当另一个用户(或多个用户)收到此消息时,目前我不会在设备本地接收消息时更改此属性。我在 Realm 中本地保存的消息。问题是,例如消息是一次发送给第一个用户的,但是由于互联网连接速度较慢,第二个用户已经有时间发送他的消息(或消息),然后第二个用户在他之后出现此消息发送消息给ChatViewController
, 但是当他离开这个控制器并返回时,他的消息将显示在最后,而不是第一个用户的消息,因为当我从 Realm 获取消息时,我按creationTimeStamp 对它们进行排序。所以我想学习保存时间戳的最佳实践,对于这种情况。
是否可以更好地更改creationTimeStamp
设备上收到消息的时间?但是如果用户拥有不止一台设备,这里也存在问题。虽然我认为这就是消息在 iMessage 中的存储方式,因为它们具有设备之间的同步性,所以我在快速创建消息时附加了相同对应的屏幕截图。
不幸的是,我没有适合您的最佳实践,只有一些想法。
I think what you want to achieve is quite hard to achieve without inconveniencing users. What I mean is that due to internet connection speed, different users may all have different point of view about timing of your messages. You could correct/sync their view after some time using creationTimeStamp
to resort messages, but then messages on screen will be reordered which could be annoying.
I guess you could think about different approach - is it that important that all users have the same timeline view? When some time ago we were implementing a group chat we agreed on the notion that single user can have different timeline view. Then we used recievedTimeStamp
for sorting, for local messages receivedTimeStamp
is the same as creationTimeStamp
. It worked out pretty well for us, but of course you can have different requirements.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句