I am building a chat application using firebase, i have set the model in a way that i store a conversation object and then later store the Messages and Participants in that object.
I get message through a service where i get the sender id and receiver id, how can i get a conversation based on the participants ids?
i am looking for a conversation which has participants with ids 468 and 478, any thoughts?
I only have sender and receiver ids and what i am trying to achieve here is that when i receive a message, i would like to put it under exact conversation, Any sugession of a better database structure if the its not possible to get the conversation based on sender and receiver ids
Firebase Related code
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference convRef = database.getReference("conversations");
String key = convRef.push().getKey();
Log.d("FIREBASE_WRITE", "Key is="+key);
convRef.child(key).setValue(new Conversation("Test"));
Message message = new Message("478","ali k","hi a message","12 May 2009",key);
String msgKey = convRef.child(key).push().getKey();
convRef.child(key).child(msgKey).setValue(message);
convRef.child(key).child("participants").push().setValue(new Participant("468","John Doe1"));
convRef.child(key).child("participants").push().setValue(new Participant("478","John Doe2"));