MOBILE-4270 push: Fix treat undefined customdata in push click handlers
parent
71784abfad
commit
060e66011b
|
@ -24,6 +24,7 @@ import { CoreUtils } from '@services/utils/utils';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
|
|
||||||
import { AddonModForumModuleHandlerService } from './module';
|
import { AddonModForumModuleHandlerService } from './module';
|
||||||
|
import { isSafeNumber } from '@/core/utils/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for forum push notifications clicks.
|
* Handler for forum push notifications clicks.
|
||||||
|
@ -44,7 +45,8 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio
|
||||||
async handles(notification: NotificationData): Promise<boolean> {
|
async handles(notification: NotificationData): Promise<boolean> {
|
||||||
return CoreUtils.isTrueOrOne(notification.notif)
|
return CoreUtils.isTrueOrOne(notification.notif)
|
||||||
&& notification.moodlecomponent == 'mod_forum'
|
&& notification.moodlecomponent == 'mod_forum'
|
||||||
&& notification.name == 'posts';
|
&& notification.name == 'posts'
|
||||||
|
&& !!(notification.contexturl || notification.customdata?.postid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,13 +60,17 @@ export class AddonModForumPushClickHandlerService implements CorePushNotificatio
|
||||||
const data = notification.customdata || {};
|
const data = notification.customdata || {};
|
||||||
const courseId = Number(notification.courseid);
|
const courseId = Number(notification.courseid);
|
||||||
const discussionId = Number(contextUrlParams.d || data.discussionid);
|
const discussionId = Number(contextUrlParams.d || data.discussionid);
|
||||||
const cmId = Number(data.cmid);
|
const cmId = data.cmid && Number(data.cmid);
|
||||||
const pageParams: Params = {
|
const pageParams: Params = {
|
||||||
forumId: Number(data.instance),
|
forumId: Number(data.instance),
|
||||||
cmId,
|
cmId,
|
||||||
courseId,
|
courseId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!isSafeNumber(discussionId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (data.postid || contextUrlParams.urlHash) {
|
if (data.postid || contextUrlParams.urlHash) {
|
||||||
pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', ''));
|
pageParams.postId = Number(data.postid || contextUrlParams.urlHash.replace('p', ''));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { isSafeNumber } from '@/core/utils/types';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { CoreGrades } from '@features/grades/services/grades';
|
import { CoreGrades } from '@features/grades/services/grades';
|
||||||
|
@ -38,8 +39,12 @@ export class AddonModLessonPushClickHandlerService implements CorePushNotificati
|
||||||
* @returns Whether the notification click is handled by this handler.
|
* @returns Whether the notification click is handled by this handler.
|
||||||
*/
|
*/
|
||||||
async handles(notification: NotificationData): Promise<boolean> {
|
async handles(notification: NotificationData): Promise<boolean> {
|
||||||
if (CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_lesson' &&
|
if (
|
||||||
notification.name == 'graded_essay') {
|
CoreUtils.isTrueOrOne(notification.notif) &&
|
||||||
|
notification.moodlecomponent == 'mod_lesson' &&
|
||||||
|
notification.name == 'graded_essay' &&
|
||||||
|
notification.customdata?.cmid
|
||||||
|
) {
|
||||||
|
|
||||||
return CoreGrades.isPluginEnabledForCourse(Number(notification.courseid), notification.site);
|
return CoreGrades.isPluginEnabledForCourse(Number(notification.courseid), notification.site);
|
||||||
}
|
}
|
||||||
|
@ -53,11 +58,15 @@ export class AddonModLessonPushClickHandlerService implements CorePushNotificati
|
||||||
* @param notification The notification to check.
|
* @param notification The notification to check.
|
||||||
* @returns Promise resolved when done.
|
* @returns Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
handleClick(notification: NotificationData): Promise<void> {
|
async handleClick(notification: NotificationData): Promise<void> {
|
||||||
const data = notification.customdata || {};
|
const data = notification.customdata || {};
|
||||||
const courseId = Number(notification.courseid);
|
const courseId = Number(notification.courseid);
|
||||||
const moduleId = Number(data.cmid);
|
const moduleId = Number(data.cmid);
|
||||||
|
|
||||||
|
if (!isSafeNumber(moduleId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return CoreGradesHelper.goToGrades(courseId, undefined, moduleId, notification.site);
|
return CoreGradesHelper.goToGrades(courseId, undefined, moduleId, notification.site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { CoreUtils } from '@services/utils/utils';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonModQuiz } from '../quiz';
|
import { AddonModQuiz } from '../quiz';
|
||||||
import { AddonModQuizHelper } from '../quiz-helper';
|
import { AddonModQuizHelper } from '../quiz-helper';
|
||||||
|
import { isSafeNumber } from '@/core/utils/types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for quiz push notifications clicks.
|
* Handler for quiz push notifications clicks.
|
||||||
|
@ -43,7 +44,8 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification
|
||||||
*/
|
*/
|
||||||
async handles(notification: AddonModQuizPushNotificationData): Promise<boolean> {
|
async handles(notification: AddonModQuizPushNotificationData): Promise<boolean> {
|
||||||
return CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_quiz' &&
|
return CoreUtils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_quiz' &&
|
||||||
this.SUPPORTED_NAMES.indexOf(notification.name ?? '') != -1;
|
this.SUPPORTED_NAMES.indexOf(notification.name ?? '') !== -1 &&
|
||||||
|
!!(notification.customdata?.instance || notification.contexturl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +59,12 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification
|
||||||
const data = notification.customdata || {};
|
const data = notification.customdata || {};
|
||||||
const courseId = Number(notification.courseid);
|
const courseId = Number(notification.courseid);
|
||||||
|
|
||||||
if (notification.name == 'submission') {
|
if (
|
||||||
|
notification.name === 'submission' &&
|
||||||
|
data.instance !== undefined &&
|
||||||
|
contextUrlParams.attempt !== undefined &&
|
||||||
|
contextUrlParams.page !== undefined
|
||||||
|
) {
|
||||||
// A student made a submission, go to view the attempt.
|
// A student made a submission, go to view the attempt.
|
||||||
return AddonModQuizHelper.handleReviewLink(
|
return AddonModQuizHelper.handleReviewLink(
|
||||||
Number(contextUrlParams.attempt),
|
Number(contextUrlParams.attempt),
|
||||||
|
@ -69,6 +76,9 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification
|
||||||
|
|
||||||
// Open the activity.
|
// Open the activity.
|
||||||
const moduleId = Number(contextUrlParams.id);
|
const moduleId = Number(contextUrlParams.id);
|
||||||
|
if (!isSafeNumber(moduleId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await CoreUtils.ignoreErrors(AddonModQuiz.invalidateContent(moduleId, courseId, notification.site));
|
await CoreUtils.ignoreErrors(AddonModQuiz.invalidateContent(moduleId, courseId, notification.site));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue