Merge pull request #2583 from dpalou/MOBILE-3507

MOBILE-3507 push: Call get_user_devices after register in Moodle
main
Juan Leyva 2020-10-30 14:53:40 +01:00 committed by GitHub
commit 3c49b7f24c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 2 deletions

View File

@ -13,6 +13,7 @@
// limitations under the License.
import { NgModule } from '@angular/core';
import { CoreEventsProvider } from '@providers/events';
import { AddonMessageOutputDelegate } from '@addon/messageoutput/providers/delegate';
import { AddonMessageOutputAirnotifierProvider } from './providers/airnotifier';
import { AddonMessageOutputAirnotifierHandler } from './providers/handler';
@ -28,7 +29,13 @@ import { AddonMessageOutputAirnotifierHandler } from './providers/handler';
]
})
export class AddonMessageOutputAirnotifierModule {
constructor(messageOutputDelegate: AddonMessageOutputDelegate, airnotifierHandler: AddonMessageOutputAirnotifierHandler) {
constructor(messageOutputDelegate: AddonMessageOutputDelegate, airnotifierHandler: AddonMessageOutputAirnotifierHandler,
eventsProvider: CoreEventsProvider, airnotifierProvider: AddonMessageOutputAirnotifierProvider) {
messageOutputDelegate.registerHandler(airnotifierHandler);
eventsProvider.on(CoreEventsProvider.DEVICE_REGISTERED_IN_MOODLE, async (data) => {
// Get user devices to make Moodle send the devices data to Airnotifier.
airnotifierProvider.getUserDevices(true, data.siteId);
});
}
}

View File

@ -74,10 +74,11 @@ export class AddonMessageOutputAirnotifierProvider {
/**
* Get user devices.
*
* @param ignoreCache Whether to ignore cache.
* @param siteId Site ID. If not defined, use current site.
* @return Promise resolved with the devices.
*/
getUserDevices(siteId?: string): Promise<AddonMessageOutputAirnotifierDevice[]> {
getUserDevices(ignoreCache?: boolean, siteId?: string): Promise<AddonMessageOutputAirnotifierDevice[]> {
this.logger.debug('Get user devices');
return this.sitesProvider.getSite(siteId).then((site) => {
@ -89,6 +90,11 @@ export class AddonMessageOutputAirnotifierProvider {
updateFrequency: CoreSite.FREQUENCY_RARELY
};
if (ignoreCache) {
preSets['getFromCache'] = false;
preSets['emergencyCache'] = false;
}
return site.read('message_airnotifier_get_user_devices', data, preSets)
.then((data: AddonMessageOutputAirnotifierGetUserDevicesResult) => {
return data.devices;

View File

@ -19,6 +19,7 @@ import { Push, PushObject, PushOptions } from '@ionic-native/push';
import { Device } from '@ionic-native/device';
import { TranslateService } from '@ngx-translate/core';
import { CoreApp, CoreAppProvider, CoreAppSchema } from '@providers/app';
import { CoreEvents, CoreEventsProvider } from '@providers/events';
import { CoreInitDelegate } from '@providers/init';
import { CoreLoggerProvider } from '@providers/logger';
import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites';
@ -789,6 +790,8 @@ export class CorePushNotificationsProvider {
// Now register the device.
await site.write('core_user_add_user_device', this.utils.clone(data));
CoreEvents.instance.trigger(CoreEventsProvider.DEVICE_REGISTERED_IN_MOODLE, {}, site.getId());
// Insert the device in the local DB.
try {
await site.getDb().insertRecord(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, data);

View File

@ -68,6 +68,7 @@ export class CoreEventsProvider {
static SITE_STORAGE_DELETED = 'site_storage_deleted';
static FORM_ACTION = 'form_action';
static ACTIVITY_DATA_SENT = 'activity_data_sent';
static DEVICE_REGISTERED_IN_MOODLE = 'device_registered_in_moodle';
protected logger;
protected observables: { [s: string]: Subject<any> } = {};