MOBILE-2953 push: Use customdata in push click handlers
parent
b9aa0e0a90
commit
9886362499
|
@ -37,9 +37,10 @@ export class AddonBadgesPushClickHandler implements CorePushNotificationsClickHa
|
||||||
* @return {boolean} Whether the notification click is handled by this handler
|
* @return {boolean} Whether the notification click is handled by this handler
|
||||||
*/
|
*/
|
||||||
handles(notification: any): boolean | Promise<boolean> {
|
handles(notification: any): boolean | Promise<boolean> {
|
||||||
// @todo: Support 'badgecreatornotice' once we receive the hash or contexturl.
|
const data = notification.customdata || {};
|
||||||
|
|
||||||
if (this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'moodle' &&
|
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);
|
return this.badgesProvider.isPluginEnabled(notification.site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +54,14 @@ export class AddonBadgesPushClickHandler implements CorePushNotificationsClickHa
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
handleClick(notification: any): Promise<any> {
|
handleClick(notification: any): Promise<any> {
|
||||||
// @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(() => {
|
return this.badgesProvider.invalidateUserBadges(0, Number(notification.usertoid), notification.site).catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
|
|
@ -50,13 +50,16 @@ export class AddonModForumPushClickHandler implements CorePushNotificationsClick
|
||||||
*/
|
*/
|
||||||
handleClick(notification: any): Promise<any> {
|
handleClick(notification: any): Promise<any> {
|
||||||
const contextUrlParams = this.urlUtils.extractUrlParams(notification.contexturl),
|
const contextUrlParams = this.urlUtils.extractUrlParams(notification.contexturl),
|
||||||
|
data = notification.customdata || {},
|
||||||
pageParams: any = {
|
pageParams: any = {
|
||||||
courseId: Number(notification.courseid),
|
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) {
|
if (data.postid || contextUrlParams.urlHash) {
|
||||||
pageParams.postId = Number(contextUrlParams.urlHash.replace('p', ''));
|
pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.forumProvider.invalidateDiscussionPosts(pageParams.discussionId, notification.site).catch(() => {
|
return this.forumProvider.invalidateDiscussionPosts(pageParams.discussionId, notification.site).catch(() => {
|
||||||
|
|
|
@ -54,12 +54,13 @@ export class AddonModQuizPushClickHandler implements CorePushNotificationsClickH
|
||||||
*/
|
*/
|
||||||
handleClick(notification: any): Promise<any> {
|
handleClick(notification: any): Promise<any> {
|
||||||
const contextUrlParams = this.urlUtils.extractUrlParams(notification.contexturl),
|
const contextUrlParams = this.urlUtils.extractUrlParams(notification.contexturl),
|
||||||
|
data = notification.customdata || {},
|
||||||
courseId = Number(notification.courseid);
|
courseId = Number(notification.courseid);
|
||||||
|
|
||||||
if (notification.name == 'submission') {
|
if (notification.name == 'submission') {
|
||||||
// A student made a submission, go to view the attempt.
|
// A student made a submission, go to view the attempt.
|
||||||
return this.quizHelper.handleReviewLink(undefined, Number(contextUrlParams.attempt), Number(contextUrlParams.page),
|
return this.quizHelper.handleReviewLink(undefined, Number(contextUrlParams.attempt), Number(contextUrlParams.page),
|
||||||
courseId, undefined, notification.site);
|
courseId, data.instance, notification.site);
|
||||||
} else {
|
} else {
|
||||||
// Open the activity.
|
// Open the activity.
|
||||||
const moduleId = Number(contextUrlParams.id);
|
const moduleId = Number(contextUrlParams.id);
|
||||||
|
|
Loading…
Reference in New Issue