Skip to content

Commit 06ce5e7

Browse files
committed
MOBILE-3507 notifications: Support view rich text when clicked
1 parent 5d3e75e commit 06ce5e7

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/addon/notifications/providers/push-click-handler.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import { Injectable } from '@angular/core';
1616
import { CoreEventsProvider } from '@providers/events';
17+
import { CoreTextUtils } from '@providers/utils/text';
1718
import { CoreUtilsProvider } from '@providers/utils/utils';
1819
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
1920
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
@@ -60,38 +61,35 @@ export class AddonNotificationsPushClickHandler implements CorePushNotifications
6061
* @param notification The notification to check.
6162
* @return Promise resolved when done.
6263
*/
63-
handleClick(notification: any): Promise<any> {
64-
let promise;
64+
async handleClick(notification: any): Promise<void> {
65+
66+
if (notification.customdata.extendedtext) {
67+
// Display the text in a modal.
68+
return CoreTextUtils.instance.viewText(notification.title, notification.customdata.extendedtext, {
69+
displayCopyButton: true,
70+
modalOptions: { cssClass: 'core-modal-fullscreen' },
71+
});
72+
}
6573

6674
// Try to handle the appurl first.
6775
if (notification.customdata && notification.customdata.appurl) {
68-
promise = this.linkHelper.handleLink(notification.customdata.appurl, undefined, undefined, true);
69-
} else {
70-
promise = Promise.resolve(false);
76+
if (this.linkHelper.handleLink(notification.customdata.appurl, undefined, undefined, true)) {
77+
// Link treated, stop.
78+
return;
79+
}
7180
}
7281

73-
return promise.then((treated) => {
74-
75-
if (!treated) {
76-
// No link or cannot be handled by the app. Try to handle the contexturl now.
77-
if (notification.contexturl) {
78-
return this.linkHelper.handleLink(notification.contexturl);
79-
} else {
80-
return false;
81-
}
82+
// No appurl or cannot be handled by the app. Try to handle the contexturl now.
83+
if (notification.contexturl) {
84+
if (this.linkHelper.handleLink(notification.contexturl)) {
85+
// Link treated, stop.
86+
return;
8287
}
88+
}
8389

84-
return true;
85-
}).then((treated) => {
90+
// No contexturl or cannot be handled by the app. Open the notifications page.
91+
await this.utils.ignoreErrors(this.notificationsProvider.invalidateNotificationsList(notification.site));
8692

87-
if (!treated) {
88-
// No link or cannot be handled by the app. Open the notifications page.
89-
return this.notificationsProvider.invalidateNotificationsList(notification.site).catch(() => {
90-
// Ignore errors.
91-
}).then(() => {
92-
return this.linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site);
93-
});
94-
}
95-
});
93+
await this.linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site);
9694
}
9795
}

src/providers/utils/text.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import { Injectable } from '@angular/core';
1616
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
17-
import { ModalController } from 'ionic-angular';
17+
import { ModalController, ModalOptions } from 'ionic-angular';
1818
import { TranslateService } from '@ngx-translate/core';
1919
import { CoreLangProvider } from '../lang';
2020
import { makeSingleton } from '@singletons/core.singletons';
@@ -1163,7 +1163,7 @@ export class CoreTextUtilsProvider {
11631163

11641164
Object.assign(params, options);
11651165

1166-
const modal = this.modalCtrl.create('CoreViewerTextPage', params);
1166+
const modal = this.modalCtrl.create('CoreViewerTextPage', params, options.modalOptions);
11671167
modal.present();
11681168
}
11691169
}
@@ -1181,6 +1181,7 @@ export type CoreTextUtilsViewTextOptions = {
11811181
instanceId?: number; // The instance ID related to the context.
11821182
courseId?: number; // Course ID the text belongs to. It can be used to improve performance with filters.
11831183
displayCopyButton?: boolean; // Whether to display a button to copy the text.
1184+
modalOptions?: ModalOptions; // Modal options.
11841185
};
11851186

11861187
export class CoreTextUtils extends makeSingleton(CoreTextUtilsProvider) {}

0 commit comments

Comments
 (0)