I'm building a basic kind of whatsapp functionality for an app and I need to be able to query firebase for messages that match user1 and user2's IDs as noted below in receiver and sender.
I'm using Ionic 2 and I have both firebase and angularfire 2 libraries imported into the app already I am having a bit of trouble how I can pull all messages that contain both user1 and user2 but no other messages at all.
This is kind of what I am looking for but theres nothing in the docs that would support this kind of advanced query or possibly I have missed it. Thinking out loud its going to have to be some kind of correlated subquery or something like left joins on the same table (if it was mysql)
this.items2 = af.database.list('/messages', {
query: {
orderByChild_1: 'sender',
equalTo: user1 || user2,
and
orderByChild_2: 'receiver',
equalTo: user1 || user2,
}
});
here is the database structure:
messages:
- Kc8da64IZjqv8PSsAGI
message: "Hi How are you"
receiver: "XRgPwmaPJWWIF8xLzvuQ28j5nKe2"
sender: "ddL5H70N3hYW8n4WpDrhNfm32Fc2"
- dkdwrehjdsfhaseuyr89
message: "Im great and you ?"
receiver: "ddL5H70N3hYW8n4WpDrhNfm32Fc2"
sender: "XRgPwmaPJWWIF8xLzvuQ28j5nKe2"
- i3uer8ufdisjhdsiflhlsdkhf
message: "pretty good, where are you ?"
receiver: "XRgPwmaPJWWIF8xLzvuQ28j5nKe2"
sender: "ddL5H70N3hYW8n4WpDrhNfm32Fc2"
- 23r9eyfdusikljnmsfjlskdjfklsjdfkl
message: "Im in cuba"
receiver: "XRgPwmaPJWWIF8xLzvuQ28j5nKe2"
sender: "ddL5H70N3hYW8n4WpDrhNfm32Fc2"