Skip to content

Commit 8d8e8a1

Browse files
authored
Merge pull request #1959 from dpalou/MOBILE-3039
Mobile 3039
2 parents c3ddf6e + f4cd6f3 commit 8d8e8a1

File tree

8 files changed

+54
-13
lines changed

8 files changed

+54
-13
lines changed

src/core/mainmenu/pages/more/more.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export class CoreMainMenuMorePage implements OnDestroy {
7272
*/
7373
ngOnDestroy(): void {
7474
window.removeEventListener('resize', this.initHandlers.bind(this));
75+
this.langObserver && this.langObserver.off();
76+
this.updateSiteObserver && this.updateSiteObserver.off();
7577

7678
if (this.subscription) {
7779
this.subscription.unsubscribe();

src/core/pushnotifications/providers/pushnotifications.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ export class CorePushNotificationsProvider {
200200
});
201201
}
202202

203+
/**
204+
* Check whether the device can be registered in Moodle to receive push notifications.
205+
*
206+
* @return {boolean} Whether the device can be registered in Moodle.
207+
*/
208+
canRegisterOnMoodle(): boolean {
209+
return this.pushID && this.appProvider.isMobile();
210+
}
211+
203212
/**
204213
* Delete all badge records for a given site.
205214
*
@@ -394,6 +403,11 @@ export class CorePushNotificationsProvider {
394403
const data = notification ? notification.additionalData : {};
395404

396405
this.sitesProvider.getSite(data.site).then(() => {
406+
407+
if (typeof data.customdata == 'string') {
408+
data.customdata = this.textUtils.parseJSON(data.customdata, {});
409+
}
410+
397411
if (this.utils.isTrueOrOne(data.foreground)) {
398412
// If the app is in foreground when the notification is received, it's not shown. Let's show it ourselves.
399413
if (this.localNotificationsProvider.isAvailable()) {
@@ -658,7 +672,7 @@ export class CorePushNotificationsProvider {
658672
registerDeviceOnMoodle(siteId?: string, forceUnregister?: boolean): Promise<any> {
659673
this.logger.debug('Register device on Moodle.');
660674

661-
if (!this.pushID || !this.appProvider.isMobile()) {
675+
if (!this.canRegisterOnMoodle()) {
662676
return Promise.reject(null);
663677
}
664678

@@ -729,7 +743,7 @@ export class CorePushNotificationsProvider {
729743

730744
if (siteId) {
731745
// Check if the site has a pending unregister.
732-
promise = this.appDB.getRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, {siteid: siteId});
746+
promise = this.appDB.getRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: siteId});
733747
} else {
734748
// Get all pending unregisters.
735749
promise = this.appDB.getAllRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE);

src/core/pushnotifications/providers/register-cron-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class CorePushNotificationsRegisterCronHandler implements CoreCronHandler
4242
* @return {Promise<any>} Promise resolved when done, rejected if failure.
4343
*/
4444
execute(siteId?: string): Promise<any> {
45-
if (!siteId) {
45+
if (!siteId || !this.pushNotificationsProvider.canRegisterOnMoodle()) {
4646
// It's not a specific site, don't do anything.
4747
return Promise.resolve();
4848
}

src/core/sharedfiles/pages/choose-site/choose-site.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
<p class="item-heading">{{ 'core.sharedfiles.chooseaccountstorefile' | translate }}</p>
1111
<p>{{fileName}}</p>
1212
</ion-item>
13-
<a ion-item *ngFor="let site of sites" (click)="storeInSite(site.id)">
14-
<img [src]="site.avatar" item-start>
13+
<a ion-item *ngFor="let site of sites" (click)="storeInSite(site.id)" detail-none>
14+
<ion-avatar item-start>
15+
<img [src]="site.avatar" core-external-content [siteId]="site.id" alt="{{ 'core.pictureof' | translate:{$a: site.fullname} }}" role="presentation" onError="this.src='assets/img/user-avatar.png'">
16+
</ion-avatar>
1517
<h2>{{site.fullName}}</h2>
16-
<p><core-format-text clean="true" [text]="site.siteName"></core-format-text></p>
18+
<p><core-format-text clean="true" [text]="site.siteName" [siteId]="site.id"></core-format-text></p>
1719
<p>{{site.siteUrl}}</p>
1820
</a>
1921
</ion-list>

src/providers/app.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class CoreAppProvider {
7373
protected backActions = [];
7474
protected mainMenuId = 0;
7575
protected mainMenuOpen: number;
76+
protected forceOffline = false;
7677

7778
constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard, private appCtrl: App,
7879
private network: Network, logger: CoreLoggerProvider, private events: CoreEventsProvider, zone: NgZone,
@@ -102,6 +103,9 @@ export class CoreAppProvider {
102103
this.platform.registerBackButtonAction(() => {
103104
this.backButtonAction();
104105
}, 100);
106+
107+
// Export the app provider so Behat tests can change the forceOffline flag.
108+
(<any> window).appProvider = this;
105109
}
106110

107111
/**
@@ -257,6 +261,10 @@ export class CoreAppProvider {
257261
* @return {boolean} Whether the app is online.
258262
*/
259263
isOnline(): boolean {
264+
if (this.forceOffline) {
265+
return false;
266+
}
267+
260268
let online = this.network.type !== null && this.network.type != Connection.NONE && this.network.type != Connection.UNKNOWN;
261269
// Double check we are not online because we cannot rely 100% in Cordova APIs. Also, check it in browser.
262270
if (!online && navigator.onLine) {
@@ -567,4 +575,13 @@ export class CoreAppProvider {
567575
this.statusBar.styleLightContent() : this.statusBar.styleDefault();
568576
}
569577
}
578+
579+
/**
580+
* Set value of forceOffline flag. If true, the app will think the device is offline.
581+
*
582+
* @param {boolean} value Value to set.
583+
*/
584+
setForceOffline(value: boolean): void {
585+
this.forceOffline = !!value;
586+
}
570587
}

src/providers/sites.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { CoreConfigConstants } from '../configconstants';
2727
import { CoreSite } from '@classes/site';
2828
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
2929
import { Md5 } from 'ts-md5/dist/md5';
30+
import { Location } from '@angular/common';
3031

3132
/**
3233
* Response of checking if a site exists and its configuration.
@@ -320,7 +321,7 @@ export class CoreSitesProvider {
320321

321322
constructor(logger: CoreLoggerProvider, private http: HttpClient, private sitesFactory: CoreSitesFactoryProvider,
322323
private appProvider: CoreAppProvider, private translate: TranslateService, private urlUtils: CoreUrlUtilsProvider,
323-
private eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider,
324+
private eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider, private location: Location,
324325
private utils: CoreUtilsProvider) {
325326
this.logger = logger.getInstance('CoreSitesProvider');
326327

@@ -1161,6 +1162,9 @@ export class CoreSitesProvider {
11611162
promises.push(this.appDB.deleteRecords(this.CURRENT_SITE_TABLE, { id: 1 }));
11621163

11631164
return Promise.all(promises).finally(() => {
1165+
// Due to DeepLinker, we need to remove the path from the URL, otherwise some pages are re-created when they shouldn't.
1166+
this.location.replaceState('');
1167+
11641168
this.eventsProvider.trigger(CoreEventsProvider.LOGOUT, {}, siteId);
11651169
});
11661170
}

src/providers/urlschemes.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ export class CoreCustomURLSchemesProvider {
125125
// Some sites add a # at the end of the URL. If it's there, remove it.
126126
url = url.replace(/\/?#?\/?$/, '');
127127

128-
// In iOS, the protocol after the scheme doesn't have ":". Add it.
129-
// E.g. "moodlemobile://https://..." is received as "moodlemobile://https//..."
130-
url = url.replace(/\/\/(https?)\/\//, '//$1://');
131-
132128
modal = this.domUtils.showModalLoading();
133129

134130
// Get the data from the URL.
@@ -137,8 +133,14 @@ export class CoreCustomURLSchemesProvider {
137133

138134
return this.getCustomURLTokenData(url);
139135
} else if (this.isCustomURLLink(url)) {
136+
// In iOS, the protocol after the scheme doesn't have ":". Add it.
137+
url = url.replace(/\/\/link=(https?)\/\//, '//link=$1://');
138+
140139
return this.getCustomURLLinkData(url);
141140
} else {
141+
// In iOS, the protocol after the scheme doesn't have ":". Add it.
142+
url = url.replace(/\/\/(https?)\/\//, '//$1://');
143+
142144
return this.getCustomURLData(url);
143145
}
144146
}).then((result) => {

src/providers/utils/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,11 @@ export class CoreUtilsProvider {
742742
* @return {boolean} Whether the error was returned by the WebService.
743743
*/
744744
isWebServiceError(error: any): boolean {
745-
return typeof error.warningcode != 'undefined' || (typeof error.errorcode != 'undefined' &&
745+
return error && (typeof error.warningcode != 'undefined' || (typeof error.errorcode != 'undefined' &&
746746
error.errorcode != 'invalidtoken' && error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
747747
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
748748
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
749-
(error.errorcode != 'accessexception' || error.message.indexOf('Invalid token - token expired') == -1));
749+
(error.errorcode != 'accessexception' || error.message.indexOf('Invalid token - token expired') == -1)));
750750
}
751751

752752
/**

0 commit comments

Comments
 (0)