diff --git a/src/addon/messageoutput/airnotifier/pages/devices/devices.ts b/src/addon/messageoutput/airnotifier/pages/devices/devices.ts index 0bea819b4..ddb966afa 100644 --- a/src/addon/messageoutput/airnotifier/pages/devices/devices.ts +++ b/src/addon/messageoutput/airnotifier/pages/devices/devices.ts @@ -15,7 +15,7 @@ import { Component, OnDestroy } from '@angular/core'; import { IonicPage } from 'ionic-angular'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; -import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications'; +import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; import { AddonMessageOutputAirnotifierProvider } from '../../providers/airnotifier'; /** @@ -34,7 +34,7 @@ export class AddonMessageOutputAirnotifierDevicesPage implements OnDestroy { protected updateTimeout: any; constructor(private domUtils: CoreDomUtilsProvider, private airnotifierProivder: AddonMessageOutputAirnotifierProvider, - private pushNotificationsProvider: AddonPushNotificationsProvider ) { + private pushNotificationsProvider: CorePushNotificationsProvider ) { } /** diff --git a/src/addon/messages/components/discussions/discussions.ts b/src/addon/messages/components/discussions/discussions.ts index b072b719b..983e27a13 100644 --- a/src/addon/messages/components/discussions/discussions.ts +++ b/src/addon/messages/components/discussions/discussions.ts @@ -21,7 +21,7 @@ import { AddonMessagesProvider } from '../../providers/messages'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreAppProvider } from '@providers/app'; -import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; /** * Component that displays the list of discussions. @@ -54,7 +54,7 @@ export class AddonMessagesDiscussionsComponent implements OnDestroy { constructor(private eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, translate: TranslateService, private messagesProvider: AddonMessagesProvider, private domUtils: CoreDomUtilsProvider, navParams: NavParams, private appProvider: CoreAppProvider, platform: Platform, private utils: CoreUtilsProvider, - pushNotificationsDelegate: AddonPushNotificationsDelegate) { + pushNotificationsDelegate: CorePushNotificationsDelegate) { this.search.loading = translate.instant('core.searching'); this.loadingMessages = translate.instant('core.loading'); diff --git a/src/addon/messages/messages.module.ts b/src/addon/messages/messages.module.ts index 9ea151d83..b05391378 100644 --- a/src/addon/messages/messages.module.ts +++ b/src/addon/messages/messages.module.ts @@ -35,7 +35,7 @@ import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; import { CoreSettingsDelegate } from '@core/settings/providers/delegate'; import { AddonMessagesSettingsHandler } from './providers/settings-handler'; -import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUpdateManagerProvider } from '@providers/update-manager'; @@ -75,7 +75,7 @@ export class AddonMessagesModule { localNotifications: CoreLocalNotificationsProvider, messagesProvider: AddonMessagesProvider, sitesProvider: CoreSitesProvider, linkHelper: CoreContentLinksHelperProvider, updateManager: CoreUpdateManagerProvider, settingsHandler: AddonMessagesSettingsHandler, settingsDelegate: CoreSettingsDelegate, - pushNotificationsDelegate: AddonPushNotificationsDelegate, utils: CoreUtilsProvider, + pushNotificationsDelegate: CorePushNotificationsDelegate, utils: CoreUtilsProvider, addContactHandler: AddonMessagesAddContactUserHandler, blockContactHandler: AddonMessagesBlockContactUserHandler, contactRequestLinkHandler: AddonMessagesContactRequestLinkHandler) { // Register handlers. diff --git a/src/addon/messages/pages/group-conversations/group-conversations.ts b/src/addon/messages/pages/group-conversations/group-conversations.ts index 332bae82c..d2fe94280 100644 --- a/src/addon/messages/pages/group-conversations/group-conversations.ts +++ b/src/addon/messages/pages/group-conversations/group-conversations.ts @@ -21,7 +21,7 @@ import { AddonMessagesProvider } from '../../providers/messages'; import { AddonMessagesOfflineProvider } from '../../providers/messages-offline'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreUtilsProvider } from '@providers/utils/utils'; -import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreUserProvider } from '@core/user/providers/user'; @@ -84,7 +84,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy { constructor(eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, translate: TranslateService, private messagesProvider: AddonMessagesProvider, private domUtils: CoreDomUtilsProvider, navParams: NavParams, private navCtrl: NavController, platform: Platform, private utils: CoreUtilsProvider, - pushNotificationsDelegate: AddonPushNotificationsDelegate, private messagesOffline: AddonMessagesOfflineProvider, + pushNotificationsDelegate: CorePushNotificationsDelegate, private messagesOffline: AddonMessagesOfflineProvider, private userProvider: CoreUserProvider) { this.loadingString = translate.instant('core.loading'); diff --git a/src/addon/messages/providers/mainmenu-handler.ts b/src/addon/messages/providers/mainmenu-handler.ts index 170d86082..0e530613a 100644 --- a/src/addon/messages/providers/mainmenu-handler.ts +++ b/src/addon/messages/providers/mainmenu-handler.ts @@ -22,8 +22,8 @@ import { CoreAppProvider } from '@providers/app'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; -import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications'; -import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; +import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper'; /** @@ -50,8 +50,8 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr constructor(private messagesProvider: AddonMessagesProvider, private sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, private localNotificationsProvider: CoreLocalNotificationsProvider, private textUtils: CoreTextUtilsProvider, - private pushNotificationsProvider: AddonPushNotificationsProvider, utils: CoreUtilsProvider, - pushNotificationsDelegate: AddonPushNotificationsDelegate, private emulatorHelper: CoreEmulatorHelperProvider) { + private pushNotificationsProvider: CorePushNotificationsProvider, utils: CoreUtilsProvider, + pushNotificationsDelegate: CorePushNotificationsDelegate, private emulatorHelper: CoreEmulatorHelperProvider) { eventsProvider.on(AddonMessagesProvider.UNREAD_CONVERSATION_COUNTS_EVENT, (data) => { this.unreadCount = data.favourites + data.individual + data.group; diff --git a/src/addon/notifications/notifications.module.ts b/src/addon/notifications/notifications.module.ts index 3dbd875f4..ff86d5f29 100644 --- a/src/addon/notifications/notifications.module.ts +++ b/src/addon/notifications/notifications.module.ts @@ -26,7 +26,7 @@ import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreSitesProvider } from '@providers/sites'; import { CoreUrlUtilsProvider } from '@providers/utils/url'; import { CoreUtilsProvider } from '@providers/utils/utils'; -import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; import { AddonModForumProvider } from '@addon/mod/forum/providers/forum'; // List of providers (without handlers). @@ -52,7 +52,7 @@ export class AddonNotificationsModule { cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone, appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider, notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider, - linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate, + linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: CorePushNotificationsDelegate, urlUtils: CoreUrlUtilsProvider, forumProvider: AddonModForumProvider) { mainMenuDelegate.registerHandler(mainMenuHandler); diff --git a/src/addon/notifications/pages/list/list.ts b/src/addon/notifications/pages/list/list.ts index 62add77ad..2799cc8ee 100644 --- a/src/addon/notifications/pages/list/list.ts +++ b/src/addon/notifications/pages/list/list.ts @@ -21,7 +21,7 @@ import { CoreEventsProvider, CoreEventObserver } from '@providers/events'; import { CoreSitesProvider } from '@providers/sites'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { AddonNotificationsProvider } from '../../providers/notifications'; -import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; /** * Page that displays the list of notifications. @@ -48,7 +48,7 @@ export class AddonNotificationsListPage { constructor(navParams: NavParams, private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider, private utils: CoreUtilsProvider, private notificationsProvider: AddonNotificationsProvider, - private pushNotificationsDelegate: AddonPushNotificationsDelegate) { + private pushNotificationsDelegate: CorePushNotificationsDelegate) { } /** diff --git a/src/addon/notifications/providers/mainmenu-handler.ts b/src/addon/notifications/providers/mainmenu-handler.ts index 8866d14a8..a73fd6065 100644 --- a/src/addon/notifications/providers/mainmenu-handler.ts +++ b/src/addon/notifications/providers/mainmenu-handler.ts @@ -18,8 +18,8 @@ import { CoreSitesProvider } from '@providers/sites'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@core/mainmenu/providers/delegate'; import { AddonNotificationsProvider } from './notifications'; -import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications'; -import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate'; +import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; /** * Handler to inject an option into main menu. @@ -41,8 +41,8 @@ export class AddonNotificationsMainMenuHandler implements CoreMainMenuHandler { constructor(eventsProvider: CoreEventsProvider, private sitesProvider: CoreSitesProvider, utils: CoreUtilsProvider, private notificationsProvider: AddonNotificationsProvider, - private pushNotificationsProvider: AddonPushNotificationsProvider, - pushNotificationsDelegate: AddonPushNotificationsDelegate) { + private pushNotificationsProvider: CorePushNotificationsProvider, + pushNotificationsDelegate: CorePushNotificationsDelegate) { eventsProvider.on(AddonNotificationsProvider.READ_CHANGED_EVENT, (data) => { this.updateBadge(data.siteId); diff --git a/src/app/app.module.ts b/src/app/app.module.ts index fbcdc4cb5..71ce98128 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -121,7 +121,7 @@ import { AddonMessageOutputModule } from '@addon/messageoutput/messageoutput.mod import { AddonMessageOutputAirnotifierModule } from '@addon/messageoutput/airnotifier/airnotifier.module'; import { AddonMessagesModule } from '@addon/messages/messages.module'; import { AddonNotesModule } from '../addon/notes/notes.module'; -import { AddonPushNotificationsModule } from '@addon/pushnotifications/pushnotifications.module'; +import { CorePushNotificationsModule } from '@core/pushnotifications/pushnotifications.module'; import { AddonNotificationsModule } from '@addon/notifications/notifications.module'; import { AddonRemoteThemesModule } from '@addon/remotethemes/remotethemes.module'; import { AddonQbehaviourModule } from '@addon/qbehaviour/qbehaviour.module'; @@ -201,6 +201,7 @@ export const CORE_PROVIDERS: any[] = [ CoreCommentsModule, CoreBlockModule, CoreRatingModule, + CorePushNotificationsModule, AddonBadgesModule, AddonBlogModule, AddonCalendarModule, @@ -241,7 +242,6 @@ export const CORE_PROVIDERS: any[] = [ AddonMessagesModule, AddonNotesModule, AddonNotificationsModule, - AddonPushNotificationsModule, AddonRemoteThemesModule, AddonQbehaviourModule, AddonQtypeModule diff --git a/src/core/compile/providers/compile.ts b/src/core/compile/providers/compile.ts index a17d62a8a..111db31e7 100644 --- a/src/core/compile/providers/compile.ts +++ b/src/core/compile/providers/compile.ts @@ -35,6 +35,7 @@ import { CORE_QUESTION_PROVIDERS } from '@core/question/question.module'; import { CORE_SHAREDFILES_PROVIDERS } from '@core/sharedfiles/sharedfiles.module'; import { CORE_SITEHOME_PROVIDERS } from '@core/sitehome/sitehome.module'; import { CORE_USER_PROVIDERS } from '@core/user/user.module'; +import { CORE_PUSHNOTIFICATIONS_PROVIDERS } from '@core/pushnotifications/pushnotifications.module'; import { IONIC_NATIVE_PROVIDERS } from '@core/emulator/emulator.module'; // Import only this provider to prevent circular dependencies. @@ -114,7 +115,6 @@ import { ADDON_MOD_WIKI_PROVIDERS } from '@addon/mod/wiki/wiki.module'; import { ADDON_MOD_WORKSHOP_PROVIDERS } from '@addon/mod/workshop/workshop.module'; import { ADDON_NOTES_PROVIDERS } from '@addon/notes/notes.module'; import { ADDON_NOTIFICATIONS_PROVIDERS } from '@addon/notifications/notifications.module'; -import { ADDON_PUSHNOTIFICATIONS_PROVIDERS } from '@addon/pushnotifications/pushnotifications.module'; import { ADDON_REMOTETHEMES_PROVIDERS } from '@addon/remotethemes/remotethemes.module'; // Import some addon modules that define components, directives and pipes. Only import the important ones. @@ -233,7 +233,7 @@ export class CoreCompileProvider { .concat(ADDON_MOD_QUIZ_PROVIDERS).concat(ADDON_MOD_RESOURCE_PROVIDERS).concat(ADDON_MOD_SCORM_PROVIDERS) .concat(ADDON_MOD_SURVEY_PROVIDERS).concat(ADDON_MOD_URL_PROVIDERS).concat(ADDON_MOD_WIKI_PROVIDERS) .concat(ADDON_MOD_WORKSHOP_PROVIDERS).concat(ADDON_NOTES_PROVIDERS).concat(ADDON_NOTIFICATIONS_PROVIDERS) - .concat(ADDON_PUSHNOTIFICATIONS_PROVIDERS).concat(ADDON_REMOTETHEMES_PROVIDERS).concat(CORE_BLOCK_PROVIDERS); + .concat(CORE_PUSHNOTIFICATIONS_PROVIDERS).concat(ADDON_REMOTETHEMES_PROVIDERS).concat(CORE_BLOCK_PROVIDERS); // We cannot inject anything to this constructor. Use the Injector to inject all the providers into the instance. for (const i in providers) { diff --git a/src/core/login/pages/sites/sites.ts b/src/core/login/pages/sites/sites.ts index 7140382d6..5f6c8a8c0 100644 --- a/src/core/login/pages/sites/sites.ts +++ b/src/core/login/pages/sites/sites.ts @@ -19,7 +19,7 @@ import { CoreLoggerProvider } from '@providers/logger'; import { CoreSitesProvider, CoreSiteBasicInfo } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreTextUtilsProvider } from '@providers/utils/text'; -import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications'; +import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; import { CoreLoginHelperProvider } from '../../providers/helper'; /** @@ -37,7 +37,7 @@ export class CoreLoginSitesPage { constructor(private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider, private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, logger: CoreLoggerProvider, - private translate: TranslateService, private pushNotificationsProvider: AddonPushNotificationsProvider) { + private translate: TranslateService, private pushNotificationsProvider: CorePushNotificationsProvider) { this.logger = logger.getInstance('CoreLoginSitesPage'); } diff --git a/src/addon/pushnotifications/providers/delegate.ts b/src/core/pushnotifications/providers/delegate.ts similarity index 96% rename from src/addon/pushnotifications/providers/delegate.ts rename to src/core/pushnotifications/providers/delegate.ts index 61ca92ce5..dbd0f12fe 100644 --- a/src/addon/pushnotifications/providers/delegate.ts +++ b/src/core/pushnotifications/providers/delegate.ts @@ -20,14 +20,14 @@ import { Subject } from 'rxjs'; * Service to handle push notifications actions to perform when clicked and received. */ @Injectable() -export class AddonPushNotificationsDelegate { +export class CorePushNotificationsDelegate { protected logger; protected observables: { [s: string]: Subject } = {}; protected counterHandlers: { [s: string]: string } = {}; constructor(loggerProvider: CoreLoggerProvider) { - this.logger = loggerProvider.getInstance('AddonPushNotificationsDelegate'); + this.logger = loggerProvider.getInstance('CorePushNotificationsDelegate'); this.observables['click'] = new Subject(); this.observables['receive'] = new Subject(); } diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts similarity index 90% rename from src/addon/pushnotifications/providers/pushnotifications.ts rename to src/core/pushnotifications/providers/pushnotifications.ts index df36c3bed..2fa632956 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -23,7 +23,7 @@ import { CoreInitDelegate } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreSitesFactoryProvider } from '@providers/sites-factory'; -import { AddonPushNotificationsDelegate } from './delegate'; +import { CorePushNotificationsDelegate } from './delegate'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreTextUtilsProvider } from '@providers/utils/text'; @@ -37,7 +37,7 @@ import { CoreSite } from '@classes/site'; /** * Data needed to register a device in a Moodle site. */ -export interface AddonPushNotificationsRegisterData { +export interface CorePushNotificationsRegisterData { /** * App ID. * @type {string} @@ -85,19 +85,19 @@ export interface AddonPushNotificationsRegisterData { * Service to handle push notifications. */ @Injectable() -export class AddonPushNotificationsProvider { +export class CorePushNotificationsProvider { protected logger; protected pushID: string; protected appDB: SQLiteDB; - static COMPONENT = 'AddonPushNotificationsProvider'; + static COMPONENT = 'CorePushNotificationsProvider'; - // Variables for database. + // Variables for database. The name still contains the name "addon" for backwards compatibility. static BADGE_TABLE = 'addon_pushnotifications_badge'; static PENDING_UNREGISTER_TABLE = 'addon_pushnotifications_pending_unregister'; static REGISTERED_DEVICES_TABLE = 'addon_pushnotifications_registered_devices'; protected appTablesSchema: SQLiteDBTableSchema[] = [ { - name: AddonPushNotificationsProvider.BADGE_TABLE, + name: CorePushNotificationsProvider.BADGE_TABLE, columns: [ { name: 'siteid', @@ -115,7 +115,7 @@ export class AddonPushNotificationsProvider { primaryKeys: ['siteid', 'addon'] }, { - name: AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, + name: CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, columns: [ { name: 'siteid', @@ -138,11 +138,11 @@ export class AddonPushNotificationsProvider { } ]; protected siteSchema: CoreSiteSchema = { - name: 'AddonPushNotificationsProvider', + name: 'AddonPushNotificationsProvider', // The name still contains "Addon" for backwards compatibility. version: 1, tables: [ { - name: AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, + name: CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, columns: [ { name: 'appid', @@ -179,12 +179,12 @@ export class AddonPushNotificationsProvider { }; constructor(logger: CoreLoggerProvider, protected appProvider: CoreAppProvider, private initDelegate: CoreInitDelegate, - protected pushNotificationsDelegate: AddonPushNotificationsDelegate, protected sitesProvider: CoreSitesProvider, + protected pushNotificationsDelegate: CorePushNotificationsDelegate, protected sitesProvider: CoreSitesProvider, private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider, private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push, private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone, private translate: TranslateService, private platform: Platform, private sitesFactory: CoreSitesFactoryProvider) { - this.logger = logger.getInstance('AddonPushNotificationsProvider'); + this.logger = logger.getInstance('CorePushNotificationsProvider'); this.appDB = appProvider.getDB(); this.appDB.createTablesFromSchema(this.appTablesSchema); this.sitesProvider.registerSiteSchema(this.siteSchema); @@ -207,7 +207,7 @@ export class AddonPushNotificationsProvider { * @return {Promise} Resolved when done. */ cleanSiteCounters(siteId: string): Promise { - return this.appDB.deleteRecords(AddonPushNotificationsProvider.BADGE_TABLE, {siteid: siteId} ).finally(() => { + return this.appDB.deleteRecords(CorePushNotificationsProvider.BADGE_TABLE, {siteid: siteId} ).finally(() => { this.updateAppCounter(); }); } @@ -267,9 +267,9 @@ export class AddonPushNotificationsProvider { /** * Get data to register the device in Moodle. * - * @return {AddonPushNotificationsRegisterData} Data. + * @return {CorePushNotificationsRegisterData} Data. */ - protected getRegisterData(): AddonPushNotificationsRegisterData { + protected getRegisterData(): CorePushNotificationsRegisterData { return { appid: CoreConfigConstants.app_id, name: this.device.manufacturer || '', @@ -338,7 +338,7 @@ export class AddonPushNotificationsProvider { })); Promise.all(promises).then(() => { - this.localNotificationsProvider.schedule(localNotif, AddonPushNotificationsProvider.COMPONENT, data.site); + this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site); }); } @@ -381,11 +381,11 @@ export class AddonPushNotificationsProvider { const promises = []; // Remove the device from the local DB. - promises.push(site.getDb().deleteRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, + promises.push(site.getDb().deleteRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, this.getRegisterData())); // Remove pending unregisters for this site. - promises.push(this.appDB.deleteRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id})); + promises.push(this.appDB.deleteRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id})); return Promise.all(promises).catch(() => { // Ignore errors. @@ -397,7 +397,7 @@ export class AddonPushNotificationsProvider { } // Store the pending unregister so it's retried again later. - return this.appDB.insertRecord(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, { + return this.appDB.insertRecord(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, { siteid: site.id, siteurl: site.getURL(), token: site.getToken(), @@ -587,7 +587,7 @@ export class AddonPushNotificationsProvider { // Now register the device. return site.write('core_user_add_user_device', this.utils.clone(data)).then((response) => { // Insert the device in the local DB. - return site.getDb().insertRecord(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, data) + return site.getDb().insertRecord(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, data) .catch((error) => { // Ignore errors. }); @@ -595,7 +595,7 @@ export class AddonPushNotificationsProvider { } }).finally(() => { // Remove pending unregisters for this site. - this.appDB.deleteRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id}).catch(() => { + this.appDB.deleteRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id}).catch(() => { // Ignore errors. }); }); @@ -609,7 +609,7 @@ export class AddonPushNotificationsProvider { * @return {Promise} Promise resolved with the stored badge counter for the addon or site or 0 if none. */ protected getAddonBadge(siteId?: string, addon: string = 'site'): Promise { - return this.appDB.getRecord(AddonPushNotificationsProvider.BADGE_TABLE, {siteid: siteId, addon: addon}).then((entry) => { + return this.appDB.getRecord(CorePushNotificationsProvider.BADGE_TABLE, {siteid: siteId, addon: addon}).then((entry) => { return (entry && entry.number) || 0; }).catch(() => { return 0; @@ -627,10 +627,10 @@ export class AddonPushNotificationsProvider { if (siteId) { // Check if the site has a pending unregister. - promise = this.appDB.getRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, {siteid: siteId}); + promise = this.appDB.getRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, {siteid: siteId}); } else { // Get all pending unregisters. - promise = this.appDB.getAllRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE); + promise = this.appDB.getAllRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE); } return promise.then((results) => { @@ -665,7 +665,7 @@ export class AddonPushNotificationsProvider { number: value }; - return this.appDB.insertRecord(AddonPushNotificationsProvider.BADGE_TABLE, entry).then(() => { + return this.appDB.insertRecord(CorePushNotificationsProvider.BADGE_TABLE, entry).then(() => { return value; }); } @@ -673,21 +673,21 @@ export class AddonPushNotificationsProvider { /** * Check if device should be registered (and unregistered first). * - * @param {AddonPushNotificationsRegisterData} data Data of the device. + * @param {CorePushNotificationsRegisterData} data Data of the device. * @param {CoreSite} site Site to use. * @return {Promise<{register: boolean, unregister: boolean}>} Promise resolved with booleans: whether to register/unregister. */ - protected shouldRegister(data: AddonPushNotificationsRegisterData, site: CoreSite) + protected shouldRegister(data: CorePushNotificationsRegisterData, site: CoreSite) : Promise<{register: boolean, unregister: boolean}> { // Check if the device is already registered. - return site.getDb().getRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, { + return site.getDb().getRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, { appid: data.appid, uuid: data.uuid }).catch(() => { // Ignore errors. return []; - }).then((records: AddonPushNotificationsRegisterData[]) => { + }).then((records: CorePushNotificationsRegisterData[]) => { let isStored = false, versionOrPushChanged = false; diff --git a/src/addon/pushnotifications/providers/register-cron-handler.ts b/src/core/pushnotifications/providers/register-cron-handler.ts similarity index 88% rename from src/addon/pushnotifications/providers/register-cron-handler.ts rename to src/core/pushnotifications/providers/register-cron-handler.ts index fd3ea87ff..0f04874b5 100644 --- a/src/addon/pushnotifications/providers/register-cron-handler.ts +++ b/src/core/pushnotifications/providers/register-cron-handler.ts @@ -14,16 +14,16 @@ import { Injectable } from '@angular/core'; import { CoreCronHandler } from '@providers/cron'; -import { AddonPushNotificationsProvider } from './pushnotifications'; +import { CorePushNotificationsProvider } from './pushnotifications'; /** * Cron handler to force a register on a Moodle site when a site is manually synchronized. */ @Injectable() -export class AddonPushNotificationsRegisterCronHandler implements CoreCronHandler { - name = 'AddonPushNotificationsRegisterCronHandler'; +export class CorePushNotificationsRegisterCronHandler implements CoreCronHandler { + name = 'CorePushNotificationsRegisterCronHandler'; - constructor(private pushNotificationsProvider: AddonPushNotificationsProvider) {} + constructor(private pushNotificationsProvider: CorePushNotificationsProvider) {} /** * Check whether the sync can be executed manually. Call isSync if not defined. diff --git a/src/addon/pushnotifications/providers/unregister-cron-handler.ts b/src/core/pushnotifications/providers/unregister-cron-handler.ts similarity index 82% rename from src/addon/pushnotifications/providers/unregister-cron-handler.ts rename to src/core/pushnotifications/providers/unregister-cron-handler.ts index 548d44bd0..f533efaa0 100644 --- a/src/addon/pushnotifications/providers/unregister-cron-handler.ts +++ b/src/core/pushnotifications/providers/unregister-cron-handler.ts @@ -14,16 +14,16 @@ import { Injectable } from '@angular/core'; import { CoreCronHandler } from '@providers/cron'; -import { AddonPushNotificationsProvider } from './pushnotifications'; +import { CorePushNotificationsProvider } from './pushnotifications'; /** * Cron handler to retry pending unregisters. */ @Injectable() -export class AddonPushNotificationsUnregisterCronHandler implements CoreCronHandler { - name = 'AddonPushNotificationsUnregisterCronHandler'; +export class CorePushNotificationsUnregisterCronHandler implements CoreCronHandler { + name = 'CorePushNotificationsUnregisterCronHandler'; - constructor(private pushNotificationsProvider: AddonPushNotificationsProvider) {} + constructor(private pushNotificationsProvider: CorePushNotificationsProvider) {} /** * Execute the process. diff --git a/src/addon/pushnotifications/pushnotifications.module.ts b/src/core/pushnotifications/pushnotifications.module.ts similarity index 70% rename from src/addon/pushnotifications/pushnotifications.module.ts rename to src/core/pushnotifications/pushnotifications.module.ts index d36a0ce43..d8d562108 100644 --- a/src/addon/pushnotifications/pushnotifications.module.ts +++ b/src/core/pushnotifications/pushnotifications.module.ts @@ -14,10 +14,10 @@ import { NgModule } from '@angular/core'; import { Platform } from 'ionic-angular'; -import { AddonPushNotificationsProvider } from './providers/pushnotifications'; -import { AddonPushNotificationsDelegate } from './providers/delegate'; -import { AddonPushNotificationsRegisterCronHandler } from './providers/register-cron-handler'; -import { AddonPushNotificationsUnregisterCronHandler } from './providers/unregister-cron-handler'; +import { CorePushNotificationsProvider } from './providers/pushnotifications'; +import { CorePushNotificationsDelegate } from './providers/delegate'; +import { CorePushNotificationsRegisterCronHandler } from './providers/register-cron-handler'; +import { CorePushNotificationsUnregisterCronHandler } from './providers/unregister-cron-handler'; import { CoreCronDelegate } from '@providers/cron'; import { CoreEventsProvider } from '@providers/events'; import { CoreLoggerProvider } from '@providers/logger'; @@ -25,9 +25,9 @@ import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreUpdateManagerProvider } from '@providers/update-manager'; // List of providers (without handlers). -export const ADDON_PUSHNOTIFICATIONS_PROVIDERS: any[] = [ - AddonPushNotificationsProvider, - AddonPushNotificationsDelegate +export const CORE_PUSHNOTIFICATIONS_PROVIDERS: any[] = [ + CorePushNotificationsProvider, + CorePushNotificationsDelegate ]; @NgModule({ @@ -36,20 +36,20 @@ export const ADDON_PUSHNOTIFICATIONS_PROVIDERS: any[] = [ imports: [ ], providers: [ - AddonPushNotificationsProvider, - AddonPushNotificationsDelegate, - AddonPushNotificationsRegisterCronHandler, - AddonPushNotificationsUnregisterCronHandler + CorePushNotificationsProvider, + CorePushNotificationsDelegate, + CorePushNotificationsRegisterCronHandler, + CorePushNotificationsUnregisterCronHandler ] }) -export class AddonPushNotificationsModule { - constructor(platform: Platform, pushNotificationsProvider: AddonPushNotificationsProvider, eventsProvider: CoreEventsProvider, +export class CorePushNotificationsModule { + constructor(platform: Platform, pushNotificationsProvider: CorePushNotificationsProvider, eventsProvider: CoreEventsProvider, localNotificationsProvider: CoreLocalNotificationsProvider, loggerProvider: CoreLoggerProvider, updateManager: CoreUpdateManagerProvider, cronDelegate: CoreCronDelegate, - registerCronHandler: AddonPushNotificationsRegisterCronHandler, - unregisterCronHandler: AddonPushNotificationsUnregisterCronHandler) { + registerCronHandler: CorePushNotificationsRegisterCronHandler, + unregisterCronHandler: CorePushNotificationsUnregisterCronHandler) { - const logger = loggerProvider.getInstance('AddonPushNotificationsModule'); + const logger = loggerProvider.getInstance('CorePushNotificationsModule'); // Register the handlers. cronDelegate.register(registerCronHandler); @@ -80,13 +80,13 @@ export class AddonPushNotificationsModule { }); // Listen for local notification clicks (generated by the app). - localNotificationsProvider.registerClick(AddonPushNotificationsProvider.COMPONENT, + localNotificationsProvider.registerClick(CorePushNotificationsProvider.COMPONENT, pushNotificationsProvider.notificationClicked.bind(pushNotificationsProvider)); // Allow migrating the table from the old app to the new schema. updateManager.registerAppTableMigration({ name: 'mma_pushnotifications_badge', - newName: AddonPushNotificationsProvider.BADGE_TABLE, + newName: CorePushNotificationsProvider.BADGE_TABLE, fields: [ { name: 'siteid', @@ -96,6 +96,6 @@ export class AddonPushNotificationsModule { }); // Migrate the component name. - updateManager.registerLocalNotifComponentMigration('mmaPushNotifications', AddonPushNotificationsProvider.COMPONENT); + updateManager.registerLocalNotifComponentMigration('mmaPushNotifications', CorePushNotificationsProvider.COMPONENT); } } diff --git a/src/core/settings/pages/about/about.ts b/src/core/settings/pages/about/about.ts index 3c6497f49..1c339f5c1 100644 --- a/src/core/settings/pages/about/about.ts +++ b/src/core/settings/pages/about/about.ts @@ -22,7 +22,7 @@ import { CoreLangProvider } from '@providers/lang'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreSitesProvider } from '@providers/sites'; import { CoreConfigConstants } from '../../../../configconstants'; -import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications'; +import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; /** * Page that displays the about settings. @@ -58,7 +58,7 @@ export class CoreSettingsAboutPage { constructor(platform: Platform, device: Device, appProvider: CoreAppProvider, fileProvider: CoreFileProvider, initDelegate: CoreInitDelegate, langProvider: CoreLangProvider, sitesProvider: CoreSitesProvider, - localNotificationsProvider: CoreLocalNotificationsProvider, pushNotificationsProvider: AddonPushNotificationsProvider) { + localNotificationsProvider: CoreLocalNotificationsProvider, pushNotificationsProvider: CorePushNotificationsProvider) { const currentSite = sitesProvider.getCurrentSite(); diff --git a/upgrade.txt b/upgrade.txt index bf90adbac..3a771557b 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in the Moodle Mobile app, information provided here is intended especially for developers. +=== 3.7.0 === + +- The pushnotifications addon has been moved to core. All imports of that addon need to be fixed to use the right path and name. + === 3.6.1 === - The local notifications plugin was updated to its latest version. The new API has some breaking changes, so please check its documentation if you're using local notifications. Also, you need to run "npm install" to update the ionic-native library.