I have obeservables of these objects :
{
id : "f3055770-6e66-4936-8e9a-732b53121549"
message:"Empty Notification for test ......"
navigationLink:"/fusion/home"
seen:false
sendedOn:"2016-12-02T15:19:44.856Z"
userId :null
}
I would like to not receive duplicated object (based on ids) and i use this method to achieve it
notify(userID: string) {
return Observable.interval(5000)
.map(() => this.baseUrl + '/notification/GetUnseen?userId=' + userID)
.switchMap(url => {
return Observable.from(this.datatService.get(url));
})
.flatMap(response => Observable.from(response.json().slice()))
}
When i add distinct(x => x.id) as last operator i have only one object instead of Four any help ?
UPDATE :
I call this method in the oninit() life cycle of my component, so that the method execute every 5 second to get notification, i use distict this way :
notify(userID: string) {
return Observable.interval(5000)
.map(() => this.baseUrl + '/notification/GetUnseen?userId=' + userID)
.switchMap(url => {
return Observable.from(this.datatService.get(url));
})
.flatMap(response => Observable.from(response.json().slice()))
.distinct(x => x.id);
}
UPDATE 2
Serveur raw response :
"[{"userId":null,"sendedOn":"2016-12-02T15:19:44.856Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"f3055770-6e66-4936-8e9a-732b53121549"},{"userId":null,"sendedOn":"2016-12-02T15:19:45.146Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"ce172122-11d9-4054-a3e4-594c8c910a7d"},{"userId":null,"sendedOn":"2016-12-02T15:19:45.146Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"66e32c45-f544-4ce6-901c-e5ac64904954"},{"userId":null,"sendedOn":"2016-12-02T15:19:45.147Z","message":"Empty Notification for test ......","navigationLink":"/fusion/home","seen":false,"id":"4c2322cb-526c-490e-8a86-f1e9ced1c34f"}]"
distinctoperator?id?.json()?