All we have to do now is to implement our service. To do this, change the listenToMessages() service in the file services.js to use this implementation:
listenToMessages(payload,observable){ let me = payload.me; observable = observable || dataSource.get(); return observable.filter(function(message){ return !message.to || message.to === me || message.from === me; }); }
Our service is simple: on the first line we store the user, on the next line we store the observable we will listen to; if no observable is provided we get the observable from the DataSource containing all messages,; we then return the observable resulting from applying a filter to check that the message does not have a to property (broadcast), ...