Skip to content

Commit

Permalink
Step 9.3: Use removeChat on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Mar 23, 2017
1 parent eeef8d1 commit 1617ae7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/pages/chats/chats.ts
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Chats, Messages, Users } from 'api/collections';
import { Chat, Message } from 'api/models';
import { NavController, PopoverController, ModalController } from 'ionic-angular';
import { NavController, PopoverController, ModalController, AlertController } from 'ionic-angular';
import { MeteorObservable } from 'meteor-rxjs';
import { Observable, Subscriber } from 'rxjs';
import { MessagesPage } from '../messages/messages';
Expand All @@ -18,7 +18,8 @@ export class ChatsPage implements OnInit {
constructor(
private navCtrl: NavController,
private popoverCtrl: PopoverController,
private modalCtrl: ModalController) {
private modalCtrl: ModalController,
private alertCtrl: AlertController) {
this.senderId = Meteor.userId();
}

Expand Down Expand Up @@ -90,8 +91,25 @@ export class ChatsPage implements OnInit {
}

removeChat(chat: Chat): void {
Chats.remove({_id: chat._id}).subscribe(() => {
MeteorObservable.call('removeChat', chat._id).subscribe({
error: (e: Error) => {
if (e) {
this.handleError(e);
}
}
});
}

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

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

alert.present();
}

showOptions(): void {
Expand Down

0 comments on commit 1617ae7

Please sign in to comment.