Skip to content

Commit

Permalink
Step 7.9: Use chat removal method in cahts component
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB committed Feb 26, 2017
1 parent 2a9e464 commit b722d70
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/pages/chats/chats.ts
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Observable } from "rxjs";
import { Chat } from "api/models/whatsapp-models";
import { Chats, Messages, Users } from "api/collections/whatsapp-collections";
import { NavController, PopoverController, ModalController } from "ionic-angular";
import { NavController, PopoverController, ModalController, AlertController } from "ionic-angular";
import { MessagesPage } from "../messages/messages";
import { ChatsOptionsComponent } from "../chat-options/chat-options";
import { NewChatComponent } from "../new-chat/new-chat";
Expand All @@ -17,7 +17,8 @@ export class ChatsPage implements OnInit {
constructor(
public navCtrl: NavController,
public popoverCtrl: PopoverController,
public modalCtrl: ModalController
public modalCtrl: ModalController,
public alertCtrl: AlertController
) {}

ngOnInit() {
Expand Down Expand Up @@ -71,10 +72,25 @@ export class ChatsPage implements OnInit {
}

removeChat(chat: Chat): void {
this.chats = this.chats.map<Chat[]>(chatsArray => {
const chatIndex = chatsArray.indexOf(chat);
chatsArray.splice(chatIndex, 1);
return chatsArray;
MeteorObservable.call('removeChat', chat._id).subscribe({
complete: () => {
this.chats = this.chats.zone();
},
error: (e: Error) => {
if (e) this.handleError(e);
}
});
}

private handleError(e: Error): void {
console.error(e);

const alert = this.alertCtrl.create({
title: 'Oops!',
message: e.message,
buttons: ['OK']
});

alert.present();
}
}

0 comments on commit b722d70

Please sign in to comment.