MOBILE-2831 push: Handle notification channels
parent
30f8efd14a
commit
cca7dee8eb
|
@ -68,6 +68,7 @@
|
||||||
"addon.blog.siteblogheading": "blog",
|
"addon.blog.siteblogheading": "blog",
|
||||||
"addon.calendar.calendar": "calendar",
|
"addon.calendar.calendar": "calendar",
|
||||||
"addon.calendar.calendarevents": "local_moodlemobileapp",
|
"addon.calendar.calendarevents": "local_moodlemobileapp",
|
||||||
|
"addon.calendar.calendarreminders": "local_moodlemobileapp",
|
||||||
"addon.calendar.defaultnotificationtime": "local_moodlemobileapp",
|
"addon.calendar.defaultnotificationtime": "local_moodlemobileapp",
|
||||||
"addon.calendar.errorloadevent": "local_moodlemobileapp",
|
"addon.calendar.errorloadevent": "local_moodlemobileapp",
|
||||||
"addon.calendar.errorloadevents": "local_moodlemobileapp",
|
"addon.calendar.errorloadevents": "local_moodlemobileapp",
|
||||||
|
@ -1506,6 +1507,7 @@
|
||||||
"core.maxsizeandattachments": "moodle",
|
"core.maxsizeandattachments": "moodle",
|
||||||
"core.min": "moodle",
|
"core.min": "moodle",
|
||||||
"core.mins": "moodle",
|
"core.mins": "moodle",
|
||||||
|
"core.misc": "admin",
|
||||||
"core.mod_assign": "assign/pluginname",
|
"core.mod_assign": "assign/pluginname",
|
||||||
"core.mod_assignment": "assignment/pluginname",
|
"core.mod_assignment": "assignment/pluginname",
|
||||||
"core.mod_book": "book/pluginname",
|
"core.mod_book": "book/pluginname",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"calendar": "Calendar",
|
"calendar": "Calendar",
|
||||||
"calendarevents": "Calendar events",
|
"calendarevents": "Calendar events",
|
||||||
|
"calendarreminders": "Calendar reminders",
|
||||||
"defaultnotificationtime": "Default notification time",
|
"defaultnotificationtime": "Default notification time",
|
||||||
"errorloadevent": "Error loading event.",
|
"errorloadevent": "Error loading event.",
|
||||||
"errorloadevents": "Error loading events.",
|
"errorloadevents": "Error loading events.",
|
||||||
|
|
|
@ -13,9 +13,11 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable, NgZone } from '@angular/core';
|
import { Injectable, NgZone } from '@angular/core';
|
||||||
|
import { Platform } from 'ionic-angular';
|
||||||
import { Badge } from '@ionic-native/badge';
|
import { Badge } from '@ionic-native/badge';
|
||||||
import { Push, PushObject, PushOptions } from '@ionic-native/push';
|
import { Push, PushObject, PushOptions } from '@ionic-native/push';
|
||||||
import { Device } from '@ionic-native/device';
|
import { Device } from '@ionic-native/device';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { CoreAppProvider } from '@providers/app';
|
import { CoreAppProvider } from '@providers/app';
|
||||||
import { CoreInitDelegate } from '@providers/init';
|
import { CoreInitDelegate } from '@providers/init';
|
||||||
import { CoreLoggerProvider } from '@providers/logger';
|
import { CoreLoggerProvider } from '@providers/logger';
|
||||||
|
@ -67,10 +69,21 @@ export class AddonPushNotificationsProvider {
|
||||||
protected pushNotificationsDelegate: AddonPushNotificationsDelegate, protected sitesProvider: CoreSitesProvider,
|
protected pushNotificationsDelegate: AddonPushNotificationsDelegate, protected sitesProvider: CoreSitesProvider,
|
||||||
private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider,
|
private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider,
|
||||||
private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push,
|
private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push,
|
||||||
private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone) {
|
private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone,
|
||||||
|
private translate: TranslateService, private platform: Platform) {
|
||||||
this.logger = logger.getInstance('AddonPushNotificationsProvider');
|
this.logger = logger.getInstance('AddonPushNotificationsProvider');
|
||||||
this.appDB = appProvider.getDB();
|
this.appDB = appProvider.getDB();
|
||||||
this.appDB.createTablesFromSchema(this.tablesSchema);
|
this.appDB.createTablesFromSchema(this.tablesSchema);
|
||||||
|
|
||||||
|
platform.ready().then(() => {
|
||||||
|
// Create the default channel.
|
||||||
|
this.createDefaultChannel();
|
||||||
|
|
||||||
|
translate.onLangChange.subscribe((event: any) => {
|
||||||
|
// Update the channel name.
|
||||||
|
this.createDefaultChannel();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,6 +98,25 @@ export class AddonPushNotificationsProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the default push channel. It is used to change the name.
|
||||||
|
*
|
||||||
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected createDefaultChannel(): Promise<any> {
|
||||||
|
if (!this.platform.is('android')) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.push.createChannel({
|
||||||
|
id: 'PushPluginChannel',
|
||||||
|
description: this.translate.instant('core.misc'),
|
||||||
|
importance: 4
|
||||||
|
}).catch((error) => {
|
||||||
|
this.logger.error('Error changing push channel name', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns options for push notifications based on device.
|
* Returns options for push notifications based on device.
|
||||||
*
|
*
|
||||||
|
@ -155,13 +187,7 @@ export class AddonPushNotificationsProvider {
|
||||||
if (this.localNotificationsProvider.isAvailable()) {
|
if (this.localNotificationsProvider.isAvailable()) {
|
||||||
const localNotif: ILocalNotification = {
|
const localNotif: ILocalNotification = {
|
||||||
id: 1,
|
id: 1,
|
||||||
trigger: {
|
data: data,
|
||||||
at: new Date()
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
notif: data.notif,
|
|
||||||
site: data.site
|
|
||||||
},
|
|
||||||
title: '',
|
title: '',
|
||||||
text: ''
|
text: ''
|
||||||
},
|
},
|
||||||
|
@ -193,9 +219,6 @@ export class AddonPushNotificationsProvider {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// The notification was clicked.
|
// The notification was clicked.
|
||||||
// For compatibility with old push plugin implementation we'll merge all the notification data in a single object.
|
|
||||||
data.title = notification.title;
|
|
||||||
data.message = notification.message;
|
|
||||||
this.notificationClicked(data);
|
this.notificationClicked(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
"addon.blog.siteblogheading": "Site blog",
|
"addon.blog.siteblogheading": "Site blog",
|
||||||
"addon.calendar.calendar": "Calendar",
|
"addon.calendar.calendar": "Calendar",
|
||||||
"addon.calendar.calendarevents": "Calendar events",
|
"addon.calendar.calendarevents": "Calendar events",
|
||||||
|
"addon.calendar.calendarreminders": "Calendar reminders",
|
||||||
"addon.calendar.defaultnotificationtime": "Default notification time",
|
"addon.calendar.defaultnotificationtime": "Default notification time",
|
||||||
"addon.calendar.errorloadevent": "Error loading event.",
|
"addon.calendar.errorloadevent": "Error loading event.",
|
||||||
"addon.calendar.errorloadevents": "Error loading events.",
|
"addon.calendar.errorloadevents": "Error loading events.",
|
||||||
|
@ -1506,6 +1507,7 @@
|
||||||
"core.maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}",
|
"core.maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}",
|
||||||
"core.min": "min",
|
"core.min": "min",
|
||||||
"core.mins": "mins",
|
"core.mins": "mins",
|
||||||
|
"core.misc": "Miscellaneous",
|
||||||
"core.mod_assign": "Assignment",
|
"core.mod_assign": "Assignment",
|
||||||
"core.mod_assignment": "Assignment 2.2 (Disabled)",
|
"core.mod_assignment": "Assignment 2.2 (Disabled)",
|
||||||
"core.mod_book": "Book",
|
"core.mod_book": "Book",
|
||||||
|
|
|
@ -126,6 +126,7 @@
|
||||||
"maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}",
|
"maxsizeandattachments": "Maximum size for new files: {{$a.size}}, maximum attachments: {{$a.attachments}}",
|
||||||
"min": "min",
|
"min": "min",
|
||||||
"mins": "mins",
|
"mins": "mins",
|
||||||
|
"misc": "Miscellaneous",
|
||||||
"mod_assign": "Assignment",
|
"mod_assign": "Assignment",
|
||||||
"mod_assignment": "Assignment 2.2 (Disabled)",
|
"mod_assignment": "Assignment 2.2 (Disabled)",
|
||||||
"mod_book": "Book",
|
"mod_book": "Book",
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Platform, Alert, AlertController } from 'ionic-angular';
|
import { Platform, Alert, AlertController } from 'ionic-angular';
|
||||||
import { LocalNotifications, ILocalNotification } from '@ionic-native/local-notifications';
|
import { LocalNotifications, ILocalNotification } from '@ionic-native/local-notifications';
|
||||||
|
import { Push } from '@ionic-native/push';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { CoreAppProvider } from './app';
|
import { CoreAppProvider } from './app';
|
||||||
import { CoreConfigProvider } from './config';
|
import { CoreConfigProvider } from './config';
|
||||||
|
@ -104,7 +105,7 @@ export class CoreLocalNotificationsProvider {
|
||||||
constructor(logger: CoreLoggerProvider, private localNotifications: LocalNotifications, private platform: Platform,
|
constructor(logger: CoreLoggerProvider, private localNotifications: LocalNotifications, private platform: Platform,
|
||||||
private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private configProvider: CoreConfigProvider,
|
private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private configProvider: CoreConfigProvider,
|
||||||
private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController,
|
private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController,
|
||||||
eventsProvider: CoreEventsProvider) {
|
eventsProvider: CoreEventsProvider, private push: Push) {
|
||||||
|
|
||||||
this.logger = logger.getInstance('CoreLocalNotificationsProvider');
|
this.logger = logger.getInstance('CoreLocalNotificationsProvider');
|
||||||
this.appDB = appProvider.getDB();
|
this.appDB = appProvider.getDB();
|
||||||
|
@ -122,6 +123,14 @@ export class CoreLocalNotificationsProvider {
|
||||||
this.notifyClick(notification.data);
|
this.notifyClick(notification.data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Create the default channel for local notifications.
|
||||||
|
this.createDefaultChannel();
|
||||||
|
|
||||||
|
translate.onLangChange.subscribe((event: any) => {
|
||||||
|
// Update the channel name.
|
||||||
|
this.createDefaultChannel();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
eventsProvider.on(CoreEventsProvider.SITE_DELETED, (site) => {
|
eventsProvider.on(CoreEventsProvider.SITE_DELETED, (site) => {
|
||||||
|
@ -176,6 +185,21 @@ export class CoreLocalNotificationsProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the default channel. It is used to change the name.
|
||||||
|
*
|
||||||
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected createDefaultChannel(): Promise<any> {
|
||||||
|
return this.push.createChannel({
|
||||||
|
id: 'default-channel-id',
|
||||||
|
description: this.translate.instant('addon.calendar.calendarreminders'),
|
||||||
|
importance: 4
|
||||||
|
}).catch((error) => {
|
||||||
|
this.logger.error('Error changing channel name', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a code to create unique notifications. If there's no code assigned, create a new one.
|
* Get a code to create unique notifications. If there's no code assigned, create a new one.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue