Permalink
Browse files

Step 9.3: Use removeChat on client side

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent e260e49 commit ae81f481eab12de4528a07d3d39327b4f9eefae5
Showing with 21 additions and 3 deletions.
  1. +21 −3 src/pages/chats/chats.ts
View
@@ -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';
@@ -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();
}
@@ -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 {

0 comments on commit ae81f48

Please sign in to comment.