I am using GiftedChat for RN and its working perfectly, but I can't manage proper message ordering by time if different devices have different time.
For example I have two devices that have manual time setup on them. At a specific time (let's say 12:00) the dates on the devices are: iOS - 12:00, Android: 12:03.
I would send a message from iOS to Android device at 12:01 (iOS Time) and it would show on Android at that time too (12:01, even though Android's time is 12:04).
Then, I would send a message back to iOS from Android at 12:04 (Android time) and it would show up in the right position on iOS. However, the time would be 12:04 on the message (iOS device time at that moment would be 12:01).
Last, if I send a message again from iOS at 12:02 (Android - 12:05) it would appear on Android above the last message (wrong order).
What should I do? I tried to fetch timestamps from the firebase server, but that would mean that they might not match with the actual time on the devices.
Something like firebase.firestore.Timestamp.now().seconds
would not work either because it shows client time only.
Any ideas?
Basics of my implementation:
onSend():
db.collection(`${companyId.toString()}`)
.doc("chats")
.collection(`chats-${chatRoom.toString()}`)
.add({
_id,
createdAt,
text,
user,
});
onReceive():
snapshot.docs.map((doc) => ({
_id: doc.data()._id,
createdAt: doc.data().createdAt.toDate(),
formattedDate: doc.data().formattedDate,
text: doc.data().text,
user: doc.data().user,
}))