I am using Ionic 2 and Firebase to build a chat app.
I have the following code, that creates an entry:
import {
FirebaseAuth,
AngularFire,
FirebaseListObservable
} from 'angularfire2';
public af: AngularFire
...
let memberIds: string[] = [senderId, receiverId];
...
this.af.database.list('/chat/').push({
memberIds: memberIds,
negativtimestamp: -Date.now()
})
As you can see, it adds a chat
for the specified memberIds
made up of a senderId
and a receiverId
.
The following code, returns a list of all the chats
.
this.firelist = this.af.database.list('/chat/', {
query: {
orderByChild: 'negativtimestamp',
}
});
Now, I want to only be able to retrieve the chats
for specified memberIds
.
Question
How do I retrieve a list of chats
for only a specified senderId
or receiverId
? i.e. The chats
that contain either a matching senderId
or receiverId
in the memberIds
.
Any help appreciated.
UPDATE
I add the following which is supposed to be used to add a filter:
import 'rxjs/add/operator/filter';
...
this.firelist = this.af.database.list('/chat/', {
query: {
orderByChild: 'negativtimestamp'
}
}).filter(item => item.memberIds === 'xxx');
However, I get the following:
[ts] Property ‘filter’ does not exist on type
‘FirebaseListObservable<any>’.