From 98863624997aa20edc89bea27a943a2a2e19a05e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 2 Apr 2019 10:51:09 +0200 Subject: [PATCH] MOBILE-2953 push: Use customdata in push click handlers --- src/addon/badges/providers/push-click-handler.ts | 13 ++++++++++--- src/addon/mod/forum/providers/push-click-handler.ts | 9 ++++++--- src/addon/mod/quiz/providers/push-click-handler.ts | 3 ++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/addon/badges/providers/push-click-handler.ts b/src/addon/badges/providers/push-click-handler.ts index 555a99240..1aabf4f28 100644 --- a/src/addon/badges/providers/push-click-handler.ts +++ b/src/addon/badges/providers/push-click-handler.ts @@ -37,9 +37,10 @@ export class AddonBadgesPushClickHandler implements CorePushNotificationsClickHa * @return {boolean} Whether the notification click is handled by this handler */ handles(notification: any): boolean | Promise { - // @todo: Support 'badgecreatornotice' once we receive the hash or contexturl. + const data = notification.customdata || {}; + if (this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'moodle' && - notification.name == 'badgerecipientnotice') { + (notification.name == 'badgerecipientnotice' || (notification.name == 'badgecreatornotice' && data.hash))) { return this.badgesProvider.isPluginEnabled(notification.site); } @@ -53,8 +54,14 @@ export class AddonBadgesPushClickHandler implements CorePushNotificationsClickHa * @return {Promise} Promise resolved when done. */ handleClick(notification: any): Promise { - // @todo: Go to the badge page once we receive the hash or contexturl. + const data = notification.customdata || {}; + if (data.hash) { + // We have the hash, open the badge directly. + return this.loginHelper.redirect('AddonBadgesIssuedBadgePage', {courseId: 0, badgeHash: data.hash}, notification.site); + } + + // No hash, open the list of user badges. return this.badgesProvider.invalidateUserBadges(0, Number(notification.usertoid), notification.site).catch(() => { // Ignore errors. }).then(() => { diff --git a/src/addon/mod/forum/providers/push-click-handler.ts b/src/addon/mod/forum/providers/push-click-handler.ts index 4a224a843..01cff72f8 100644 --- a/src/addon/mod/forum/providers/push-click-handler.ts +++ b/src/addon/mod/forum/providers/push-click-handler.ts @@ -50,13 +50,16 @@ export class AddonModForumPushClickHandler implements CorePushNotificationsClick */ handleClick(notification: any): Promise { const contextUrlParams = this.urlUtils.extractUrlParams(notification.contexturl), + data = notification.customdata || {}, pageParams: any = { courseId: Number(notification.courseid), - discussionId: Number(contextUrlParams.d), + discussionId: Number(contextUrlParams.d || data.discussionid), + cmId: Number(data.cmid), + forumId: Number(data.instance) }; - if (contextUrlParams.urlHash) { - pageParams.postId = Number(contextUrlParams.urlHash.replace('p', '')); + if (data.postid || contextUrlParams.urlHash) { + pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', '')); } return this.forumProvider.invalidateDiscussionPosts(pageParams.discussionId, notification.site).catch(() => { diff --git a/src/addon/mod/quiz/providers/push-click-handler.ts b/src/addon/mod/quiz/providers/push-click-handler.ts index 2373bd622..799d32808 100644 --- a/src/addon/mod/quiz/providers/push-click-handler.ts +++ b/src/addon/mod/quiz/providers/push-click-handler.ts @@ -54,12 +54,13 @@ export class AddonModQuizPushClickHandler implements CorePushNotificationsClickH */ handleClick(notification: any): Promise { const contextUrlParams = this.urlUtils.extractUrlParams(notification.contexturl), + data = notification.customdata || {}, courseId = Number(notification.courseid); if (notification.name == 'submission') { // A student made a submission, go to view the attempt. return this.quizHelper.handleReviewLink(undefined, Number(contextUrlParams.attempt), Number(contextUrlParams.page), - courseId, undefined, notification.site); + courseId, data.instance, notification.site); } else { // Open the activity. const moduleId = Number(contextUrlParams.id);