diff --git a/src/addons/badges/badges.module.ts b/src/addons/badges/badges.module.ts index 42a91fa22..733fafa15 100644 --- a/src/addons/badges/badges.module.ts +++ b/src/addons/badges/badges.module.ts @@ -21,8 +21,8 @@ import { CoreContentLinksDelegate } from '@features/contentlinks/services/conten import { CoreUserDelegate } from '@features/user/services/user-delegate'; import { AddonBadgesUserHandler } from './services/handlers/user'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; -// @todo import { CorePushNotificationsDelegate } from '@core/pushnotifications/services/delegate'; -// import { AddonBadgesPushClickHandler } from './services/push-click-handler'; +import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate'; +import { AddonBadgesPushClickHandler } from './services/handlers/push-click'; const mainMenuHomeSiblingRoutes: Routes = [ { @@ -44,7 +44,7 @@ const mainMenuHomeSiblingRoutes: Routes = [ CoreContentLinksDelegate.instance.registerHandler(AddonBadgesMyBadgesLinkHandler.instance); CoreContentLinksDelegate.instance.registerHandler(AddonBadgesBadgeLinkHandler.instance); CoreUserDelegate.instance.registerHandler(AddonBadgesUserHandler.instance); - // CorePushNotificationsDelegate.instance.registerHandler(AddonBadgesPushClickHandler.instance); + CorePushNotificationsDelegate.instance.registerClickHandler(AddonBadgesPushClickHandler.instance); }, }, ], diff --git a/src/addons/badges/services/handlers/push-click.ts b/src/addons/badges/services/handlers/push-click.ts new file mode 100644 index 000000000..e31f48531 --- /dev/null +++ b/src/addons/badges/services/handlers/push-click.ts @@ -0,0 +1,79 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; + +import { CoreUtils } from '@services/utils/utils'; +import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate'; +import { AddonBadges } from '../badges'; +import { makeSingleton } from '@singletons'; +import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications'; +import { CoreNavHelper } from '@services/nav-helper'; + +/** + * Handler for badges push notifications clicks. + */ +@Injectable({ providedIn: 'root' }) +export class AddonBadgesPushClickHandlerService implements CorePushNotificationsClickHandler { + + name = 'AddonBadgesPushClickHandler'; + priority = 200; + featureName = 'CoreUserDelegate_AddonBadges'; + + /** + * Check if a notification click is handled by this handler. + * + * @param notification The notification to check. + * @return Whether the notification click is handled by this handler + */ + async handles(notification: CorePushNotificationsNotificationBasicData): Promise { + const data = notification.customdata || {}; + + if (CoreUtils.instance.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'moodle' && + (notification.name == 'badgerecipientnotice' || (notification.name == 'badgecreatornotice' && data.hash))) { + return AddonBadges.instance.isPluginEnabled(notification.site); + } + + return false; + } + + /** + * Handle the notification click. + * + * @param notification The notification to check. + * @return Promise resolved when done. + */ + async handleClick(notification: CorePushNotificationsNotificationBasicData): Promise { + const data = notification.customdata || {}; + + if (data.hash) { + // We have the hash, open the badge directly. + return CoreNavHelper.instance.goInSite('/badges/issue', { courseId: 0, badgeHash: data.hash }, notification.site); + } + + // No hash, open the list of user badges. + await CoreUtils.instance.ignoreErrors( + AddonBadges.instance.invalidateUserBadges( + 0, + Number(notification.usertoid), + notification.site, + ), + ); + + await CoreNavHelper.instance.goInSite('/badges/user', {}, notification.site); + } + +} + +export class AddonBadgesPushClickHandler extends makeSingleton(AddonBadgesPushClickHandlerService) {} diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 3086104af..51fad9ab4 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -35,6 +35,7 @@ import { } from '../../courses/services/courses'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreWSError } from '@classes/errors/wserror'; +import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; const ROOT_CACHE_KEY = 'mmCourse:'; @@ -73,7 +74,6 @@ export class CoreCourseProvider { // @todo // protected courseFormatDelegate: CoreCourseFormatDelegate, // protected sitePluginsProvider: CoreSitePluginsProvider, - // protected pushNotificationsProvider: CorePushNotificationsProvider, this.logger = CoreLogger.getInstance('CoreCourseProvider'); } @@ -857,7 +857,6 @@ export class CoreCourseProvider { * @return Promise resolved when the WS call is successful. * @todo use logHelper. Remove eslint disable when done. */ - // eslint-disable-next-line @typescript-eslint/no-unused-vars async logView(courseId: number, sectionNumber?: number, siteId?: string, name?: string): Promise { const params: CoreCourseViewCourseWSParams = { courseid: courseId, @@ -869,8 +868,7 @@ export class CoreCourseProvider { } const site = await CoreSites.instance.getSite(siteId); - // @todo - // this.pushNotificationsProvider.logViewEvent(courseId, name, 'course', wsName, { sectionnumber: sectionNumber }, siteId); + CorePushNotifications.instance.logViewEvent(courseId, name, 'course', wsName, { sectionnumber: sectionNumber }, siteId); const response: CoreStatusWithWarningsWSResponse = await site.write(wsName, params); if (!response.status) { diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts index dfdb6d003..e0ed13a45 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts @@ -22,6 +22,7 @@ import { CoreFile } from '@services/file'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { Subscription } from 'rxjs'; +import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; /** * Device Info to be shown and copied to clipboard. @@ -50,7 +51,7 @@ interface CoreSettingsDeviceInfo { osVersion?: string; model?: string; uuid?: string; - pushId: string; + pushId?: string; localNotifAvailable: string; } @@ -86,7 +87,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { networkStatus: appProvider.isOnline() ? 'online' : 'offline', wifiConnection: appProvider.isWifi() ? 'yes' : 'no', localNotifAvailable: CoreLocalNotifications.instance.isAvailable() ? 'yes' : 'no', - pushId: '',// TODO pushNotificationsProvider.getPushId(), + pushId: CorePushNotifications.instance.getPushId(), deviceType: '', }; diff --git a/src/core/features/settings/pages/general/general.ts b/src/core/features/settings/pages/general/general.ts index 40cfd96a9..3bcb997e8 100644 --- a/src/core/features/settings/pages/general/general.ts +++ b/src/core/features/settings/pages/general/general.ts @@ -18,7 +18,7 @@ import { CoreConfig } from '@services/config'; import { CoreEvents } from '@singletons/events'; import { CoreLang } from '@services/lang'; import { CoreDomUtils } from '@services/utils/dom'; -// import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; +import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; import { CoreSettingsHelper, CoreColorScheme } from '../../services/settings-helper'; /** @@ -160,7 +160,7 @@ export class CoreSettingsGeneralPage { * @todo */ async analyticsEnabledChanged(): Promise { - // await this.pushNotificationsProvider.enableAnalytics(this.analyticsEnabled); + await CorePushNotifications.instance.enableAnalytics(this.analyticsEnabled); CoreConfig.instance.set(CoreConstants.SETTINGS_ANALYTICS_ENABLED, this.analyticsEnabled ? 1 : 0); } diff --git a/src/core/features/user/services/user.ts b/src/core/features/user/services/user.ts index f5055fa26..260956e93 100644 --- a/src/core/features/user/services/user.ts +++ b/src/core/features/user/services/user.ts @@ -26,6 +26,7 @@ import { CoreEvents, CoreEventUserDeletedData } from '@singletons/events'; import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws'; import { CoreError } from '@classes/errors/error'; import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user'; +import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; const ROOT_CACHE_KEY = 'mmUser:'; @@ -526,7 +527,7 @@ export class CoreUserProvider { params.courseid = courseId; } - // @todo this.pushNotificationsProvider.logViewEvent(userId, name, 'user', wsName, {courseid: courseId}); + CorePushNotifications.instance.logViewEvent(userId, name, 'user', wsName, { courseid: courseId }); return site.write(wsName, params); } @@ -544,7 +545,7 @@ export class CoreUserProvider { courseid: courseId, }; - // @todo this.pushNotificationsProvider.logViewListEvent('user', 'core_user_view_user_list', params); + CorePushNotifications.instance.logViewListEvent('user', 'core_user_view_user_list', params); return site.write('core_user_view_user_list', params); }