MOBILE-3662 push: Implement push todo code
parent
9b522391b1
commit
63f8ae5f4d
|
@ -21,8 +21,8 @@ import { CoreContentLinksDelegate } from '@features/contentlinks/services/conten
|
||||||
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
import { CoreUserDelegate } from '@features/user/services/user-delegate';
|
||||||
import { AddonBadgesUserHandler } from './services/handlers/user';
|
import { AddonBadgesUserHandler } from './services/handlers/user';
|
||||||
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||||
// @todo import { CorePushNotificationsDelegate } from '@core/pushnotifications/services/delegate';
|
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
|
||||||
// import { AddonBadgesPushClickHandler } from './services/push-click-handler';
|
import { AddonBadgesPushClickHandler } from './services/handlers/push-click';
|
||||||
|
|
||||||
const mainMenuHomeSiblingRoutes: Routes = [
|
const mainMenuHomeSiblingRoutes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,7 @@ const mainMenuHomeSiblingRoutes: Routes = [
|
||||||
CoreContentLinksDelegate.instance.registerHandler(AddonBadgesMyBadgesLinkHandler.instance);
|
CoreContentLinksDelegate.instance.registerHandler(AddonBadgesMyBadgesLinkHandler.instance);
|
||||||
CoreContentLinksDelegate.instance.registerHandler(AddonBadgesBadgeLinkHandler.instance);
|
CoreContentLinksDelegate.instance.registerHandler(AddonBadgesBadgeLinkHandler.instance);
|
||||||
CoreUserDelegate.instance.registerHandler(AddonBadgesUserHandler.instance);
|
CoreUserDelegate.instance.registerHandler(AddonBadgesUserHandler.instance);
|
||||||
// CorePushNotificationsDelegate.instance.registerHandler(AddonBadgesPushClickHandler.instance);
|
CorePushNotificationsDelegate.instance.registerClickHandler(AddonBadgesPushClickHandler.instance);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -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<boolean> {
|
||||||
|
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<void> {
|
||||||
|
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) {}
|
|
@ -35,6 +35,7 @@ import {
|
||||||
} from '../../courses/services/courses';
|
} from '../../courses/services/courses';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreWSError } from '@classes/errors/wserror';
|
import { CoreWSError } from '@classes/errors/wserror';
|
||||||
|
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
|
||||||
|
|
||||||
const ROOT_CACHE_KEY = 'mmCourse:';
|
const ROOT_CACHE_KEY = 'mmCourse:';
|
||||||
|
|
||||||
|
@ -73,7 +74,6 @@ export class CoreCourseProvider {
|
||||||
// @todo
|
// @todo
|
||||||
// protected courseFormatDelegate: CoreCourseFormatDelegate,
|
// protected courseFormatDelegate: CoreCourseFormatDelegate,
|
||||||
// protected sitePluginsProvider: CoreSitePluginsProvider,
|
// protected sitePluginsProvider: CoreSitePluginsProvider,
|
||||||
// protected pushNotificationsProvider: CorePushNotificationsProvider,
|
|
||||||
this.logger = CoreLogger.getInstance('CoreCourseProvider');
|
this.logger = CoreLogger.getInstance('CoreCourseProvider');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,7 +857,6 @@ export class CoreCourseProvider {
|
||||||
* @return Promise resolved when the WS call is successful.
|
* @return Promise resolved when the WS call is successful.
|
||||||
* @todo use logHelper. Remove eslint disable when done.
|
* @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<void> {
|
async logView(courseId: number, sectionNumber?: number, siteId?: string, name?: string): Promise<void> {
|
||||||
const params: CoreCourseViewCourseWSParams = {
|
const params: CoreCourseViewCourseWSParams = {
|
||||||
courseid: courseId,
|
courseid: courseId,
|
||||||
|
@ -869,8 +868,7 @@ export class CoreCourseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
const site = await CoreSites.instance.getSite(siteId);
|
const site = await CoreSites.instance.getSite(siteId);
|
||||||
// @todo
|
CorePushNotifications.instance.logViewEvent(courseId, name, 'course', wsName, { sectionnumber: sectionNumber }, siteId);
|
||||||
// this.pushNotificationsProvider.logViewEvent(courseId, name, 'course', wsName, { sectionnumber: sectionNumber }, siteId);
|
|
||||||
const response: CoreStatusWithWarningsWSResponse = await site.write(wsName, params);
|
const response: CoreStatusWithWarningsWSResponse = await site.write(wsName, params);
|
||||||
|
|
||||||
if (!response.status) {
|
if (!response.status) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { CoreFile } from '@services/file';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Device Info to be shown and copied to clipboard.
|
* Device Info to be shown and copied to clipboard.
|
||||||
|
@ -50,7 +51,7 @@ interface CoreSettingsDeviceInfo {
|
||||||
osVersion?: string;
|
osVersion?: string;
|
||||||
model?: string;
|
model?: string;
|
||||||
uuid?: string;
|
uuid?: string;
|
||||||
pushId: string;
|
pushId?: string;
|
||||||
localNotifAvailable: string;
|
localNotifAvailable: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
|
||||||
networkStatus: appProvider.isOnline() ? 'online' : 'offline',
|
networkStatus: appProvider.isOnline() ? 'online' : 'offline',
|
||||||
wifiConnection: appProvider.isWifi() ? 'yes' : 'no',
|
wifiConnection: appProvider.isWifi() ? 'yes' : 'no',
|
||||||
localNotifAvailable: CoreLocalNotifications.instance.isAvailable() ? 'yes' : 'no',
|
localNotifAvailable: CoreLocalNotifications.instance.isAvailable() ? 'yes' : 'no',
|
||||||
pushId: '',// TODO pushNotificationsProvider.getPushId(),
|
pushId: CorePushNotifications.instance.getPushId(),
|
||||||
deviceType: '',
|
deviceType: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import { CoreConfig } from '@services/config';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreLang } from '@services/lang';
|
import { CoreLang } from '@services/lang';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
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';
|
import { CoreSettingsHelper, CoreColorScheme } from '../../services/settings-helper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,7 +160,7 @@ export class CoreSettingsGeneralPage {
|
||||||
* @todo
|
* @todo
|
||||||
*/
|
*/
|
||||||
async analyticsEnabledChanged(): Promise<void> {
|
async analyticsEnabledChanged(): Promise<void> {
|
||||||
// await this.pushNotificationsProvider.enableAnalytics(this.analyticsEnabled);
|
await CorePushNotifications.instance.enableAnalytics(this.analyticsEnabled);
|
||||||
|
|
||||||
CoreConfig.instance.set(CoreConstants.SETTINGS_ANALYTICS_ENABLED, this.analyticsEnabled ? 1 : 0);
|
CoreConfig.instance.set(CoreConstants.SETTINGS_ANALYTICS_ENABLED, this.analyticsEnabled ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import { CoreEvents, CoreEventUserDeletedData } from '@singletons/events';
|
||||||
import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws';
|
import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user';
|
import { USERS_TABLE_NAME, CoreUserDBRecord } from './database/user';
|
||||||
|
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
|
||||||
|
|
||||||
const ROOT_CACHE_KEY = 'mmUser:';
|
const ROOT_CACHE_KEY = 'mmUser:';
|
||||||
|
|
||||||
|
@ -526,7 +527,7 @@ export class CoreUserProvider {
|
||||||
params.courseid = courseId;
|
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);
|
return site.write(wsName, params);
|
||||||
}
|
}
|
||||||
|
@ -544,7 +545,7 @@ export class CoreUserProvider {
|
||||||
courseid: courseId,
|
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);
|
return site.write('core_user_view_user_list', params);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue