import { Injectable } from '@angular/core' ; import { Http } from '@angular/http' ; import 'rxjs/add/operator/map' ; import { AngularFireDatabase , AngularFireList } from 'angularfire2/database' ; import { BaseService } from "./base.service" ; import { Message } from '../models/message.model' ; import * as firebase from 'firebase/app' ; import { Observable } from 'rxjs/Observable' ; @ Injectable ( ) export class MessageService extends BaseService { constructor ( public db , public http ) { super ( ) ; } create ( message , listMessages ) { return Promise . resolve ( listMessages . push ( message ) ) ; } getMessages ( userId1 , userId2 ) { console . log ( userId1 , userId2 ) ; return this . db . list ( `/messages/${ userId1 }-${ userId2 }` , ( ref ) => ref . limitToLast ( 30 ) . orderByChild ( 'timestamp' ) ) ; } }