Permalink
Browse files

Step 15.5: Use getContactsFromAddressbook in new-chat.ts

  • Loading branch information...
darkbasic committed Jun 7, 2017
1 parent eae8c9a commit 468574084c38d2fc23fd63cb4a731cf22580a884
Showing with 16 additions and 3 deletions.
  1. +16 −3 src/pages/chats/new-chat.ts
@@ -5,6 +5,7 @@ import { AlertController, Platform, ViewController } from 'ionic-angular';
import { MeteorObservable } from 'meteor-rxjs';
import * as _ from 'lodash';
import { Observable, Subscription, BehaviorSubject } from 'rxjs';
import { PhoneService } from "../../services/phone";
@Component({
selector: 'new-chat',
@@ -15,18 +16,28 @@ export class NewChatComponent implements OnInit {
senderId: string;
users: Observable<User[]>;
usersSubscription: Subscription;
contacts: string[] = [];
contactsPromise: Promise<void>;
constructor(
private alertCtrl: AlertController,
private viewCtrl: ViewController,
private platform: Platform
private platform: Platform,
private phoneService: PhoneService
) {
this.senderId = Meteor.userId();
this.searchPattern = new BehaviorSubject(undefined);
}
ngOnInit() {
this.observeSearchBar();
this.contactsPromise = this.phoneService.getContactsFromAddressbook()
.then((phoneNumbers: string[]) => {
this.contacts = phoneNumbers;
})
.catch((e: Error) => {
console.error(e.message);
});
}
updateSubscription(newValue) {
@@ -42,7 +53,9 @@ export class NewChatComponent implements OnInit {
this.usersSubscription.unsubscribe();
}
this.usersSubscription = this.subscribeUsers();
this.contactsPromise.then(() => {
this.usersSubscription = this.subscribeUsers();
});
});
}
@@ -61,7 +74,7 @@ export class NewChatComponent implements OnInit {
subscribeUsers(): Subscription {
// Fetch all users matching search pattern
const subscription = MeteorObservable.subscribe('users', this.searchPattern.getValue());
const subscription = MeteorObservable.subscribe('users', this.searchPattern.getValue(), this.contacts);
const autorun = MeteorObservable.autorun();
return Observable.merge(subscription, autorun).subscribe(() => {

0 comments on commit 4685740

Please sign in to comment.