I'm new in Firebase with Android. I'm trying to build nearby chat application, which search for nearby people and make geo query with Geofire library and get the nearby location which has the key equal to nearby user key.
I've done this part already in one activity and display the nearby users list in list view.
Then I make onClick listener in each element ( user) in nearby list view, the click listener doing this :
take the
geoLocation
id which is equal to nearby user id .put this id into intent and start new chat activity which is responsible for chating .
My problem start in chat activity. I don't know how to implement the Unique chat ID that's should be equal for 2 user, so that both users will end up in one chat session.
I try to combine the user ID 1 + user ID2 and concatenate this both ID and generate the unique ID , the problem is if each user start the chat activity. But they end up with chat ID with user1 + user2 always. The result is that each user will have it's own session and they end up chatting with himself.
This is my database design:
{
"users" : {
"UserID1" : {
"name" : "Abood"
} ,
"UserID2" : {
"name" : "Yousef"
} ,
} ,
"chats" : {
"chat_userID1_userID2" : {
"messages" : {
"messageID1" : {
"singleMessage" : {
"name " : "Abood" ,
"text" : "hello how are you ?" ,
"sendIn" : "2016.11.24"
},
"messageID2" : {
"singleMessage" : {
"name" : "Yousef" ,
"text" : "Im fine , thank you " ,
"sendIn" : "2016.11.25"
}
}
}
}
}
} ,
"chat_meta_data" : {
"chat_userID1_userID2" : {
"lastMessage" : {
"from" : "Yousef" ,
"date" : "2016.11.25"
}
}
}
}
I search in stackoverflow and I see the same problem but it's was in javascript , Best way to manage Chat channels in Firebase
I don't know how to implement it in java.
How I generate the chat id from combining both user id 1 + user id 2 , but its should be equal for both user?