Is there a simple way to structure a database that has messaging between two users. In firebase-database can you have to pointers to the same thing? I want to be able to make a pseudo clone of the conversation under both users. This way user1 has a list of people he is having a conversation with and so does user2 and the conversation information only needs to be stored once. I may have answered my own question as I am writing this, but these are two alternatives that I was considering. Block 2 seems significantly more space efficient. Does anyone have any other suggestions for how to approach this.
Block 1: Each time a message is sent stor it under both users.
{
messaging:
user1:
user2:
message1:
messageBody: "text"
sender: "user1"
message2:
messageBody: "text"
sender: "user2"
message3:
messageBody: "text"
sender: "user1"
user2:
user1:
message1:
messageBody: "text"
sender: "user1"
message2:
messageBody: "text"
sender: "user2"
message3:
messageBody: "text"
sender: "user1"
}
or an alternative is Block2: Each time a message is sent store it under that conversation reference but have a reference to that conversation for each pair of users.
{
conversations:
conversation1:
message1:
messageBody: "text"
sender: "user1"
message2:
messageBody: "text"
sender: "user2"
message3:
messageBody: "text"
sender: "user1"
pairs:
user2:
user1:
conversationName: "conversation1"
user1:
user2:
conversationName: "conversation1"
}
Is there a way to say in the database, to say no matter the order of the children, point to the same thing? So that lines two and three would reference the same thing:
let dbRef = FIRDatabase.database().reference().child("messages")
let user1MessagesRef = dbRef.child("user1").child("user2")
let user2MessagesRef = dbRef.child("user1").child("user2")