How do you check what page you’re currently on from an event listener in app.ts?
I have a messaging app, and it receives notifications, if a publisher sends a message to a subscriber. When it receives that message (on an event
), it pops up a message. If the user is on the chats.ts page, I don’t want it to show the pop up. The thing is the event listener is on app.ts.
So how from the event listener in app.ts can I determine what page the user is on?
I thought I could maybe use this.viewCtrl.name
, but the View controller is not available in app.ts.
app.ts
push.on('registration', (data1) => {
this.events.subscribe('messages:notify', (data) => {
this.notificationService.push('null', data[0].topic, data[0].message, data[0].title);
});
});
push.on('notification', (data) => {
//if user using app and push notification comes
if (data.additionalData.foreground) {
//if application open, show popup
let confirmAlert = this.alertCtrl.create({
title: data.title,
message: data.message,
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
this.rootPage = ChatsPage;
}
}]
});
confirmAlert.present(confirmAlert);
} else {
this.rootPage = ChatsPage;
}
});
chats.ts
`this.events.publish('messages:notify', data);`