I'm making now a chat app by using the Firestore database and im thinking how to avoid the same chat to be created twice.
For example, if person A sends message to person B, I had like the message to enter the same chat collection as if person B send the message to person A.
I have found the following suggestion here
It recommends to compare the users UID which I know and construct some chatID based on the combination of those string.
private String setOneToOneChat(String uid1, String uid2)
{
if(uid1 <uid2){
return uid1+uid2;
}
else{
return uid2+uid1;
}
}
comparing the length of both UID doesn't work since all (or at least all I have seen are from the same length).
However, first I didn't really understand how to use math operator such as <
on a string
, second im not sure if it really catches all cases.
If there are any suggestions to implement such thing I would like to hear.
Thank you