/
messages-options.ts
76 lines (68 loc) · 1.7 KB
/
messages-options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { Component } from '@angular/core';
import { AlertController, NavController, NavParams, ViewController } from 'ionic-angular';
import { MeteorObservable } from 'meteor-rxjs';
import { ChatsPage } from '../chats/chats';
@Component({
selector: 'messages-options',
templateUrl: 'messages-options.html'
})
export class MessagesOptionsComponent {
constructor(
public alertCtrl: AlertController,
public navCtrl: NavController,
public params: NavParams,
public viewCtrl: ViewController
) {}
remove(): void {
const alert = this.alertCtrl.create({
title: 'Remove',
message: 'Are you sure you would like to proceed?',
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Yes',
handler: () => {
this.handleRemove(alert);
return false;
}
}
]
});
this.viewCtrl.dismiss().then(() => {
alert.present();
});
}
private handleRemove(alert): void {
MeteorObservable.call('removeChat', this.params.get('chat')._id).subscribe({
next: () => {
alert.dismiss().then(() => {
this.navCtrl.setRoot(ChatsPage, {}, {
animate: true
});
});
},
error: (e: Error) => {
alert.dismiss().then(() => {
if (e) {
return this.handleError(e);
}
this.navCtrl.setRoot(ChatsPage, {}, {
animate: true
});
});
}
});
}
private handleError(e: Error): void {
console.error(e);
const alert = this.alertCtrl.create({
title: 'Oops!',
message: e.message,
buttons: ['OK']
});
alert.present();
}
}