I am using Firebase and trying to build 1:1 conversations. For rooms, I used a structure like this:
- rooms
- "user1_user2" // roomName
- timestampedId1
- message: "hello"
- sender: "user2"
- timestampedId2
- message: "hey"
- sender: "user1"
- "user2_user3"
- timestampedId3
- message: "Mew"
- sender: "user3"
For room names, I used (which I got from this answer):
let roomName = (from<to ? from+"_"+to : to+"_"+from)
However, now I am trying to retrieve, and I got confused. With Firebase, what is the proper structure of creating private rooms and retrieving them?
Should I store 'from' and 'to' individually inside 'roomName' node? But if so, then how can I compare them and list them as descending timestamp (new to old)? I think there should be a way of doing it with one request. But how can I do it with this 'roomName' approach? Or is there any other better way to achieve it?
let roomRef = Firebase(url: self.url + "/rooms")
// some query?
.observeEventOfType(.Value, withBlock: { details in
})
What is the proper way of handling this kind of case? Should I change the structure completely or is there a way to query it properly?