From 8d338d0c00084989e4358ba436307ee4f92b2653 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 22 Oct 2021 08:27:44 +0200 Subject: [PATCH] MOBILE-3828 notifications: Display HTML of notifications --- .../list/list.scss => notifications.scss} | 16 ++++++++++++---- src/addons/notifications/pages/list/list.html | 2 +- src/addons/notifications/pages/list/list.ts | 2 +- .../pages/notification/notification.ts | 1 + .../services/notifications-helper.ts | 17 ----------------- .../notifications/services/notifications.ts | 10 ++-------- src/core/directives/format-text.ts | 4 ++-- 7 files changed, 19 insertions(+), 33 deletions(-) rename src/addons/notifications/{pages/list/list.scss => notifications.scss} (76%) diff --git a/src/addons/notifications/pages/list/list.scss b/src/addons/notifications/notifications.scss similarity index 76% rename from src/addons/notifications/pages/list/list.scss rename to src/addons/notifications/notifications.scss index be91e7a5c..98b92c030 100644 --- a/src/addons/notifications/pages/list/list.scss +++ b/src/addons/notifications/notifications.scss @@ -1,3 +1,5 @@ +@import "~theme/globals"; + :host { .core-notification-icon { width: 34px; @@ -17,11 +19,17 @@ .header { background-color: var(--gray-lighter); - } - .picture { - width: auto; - text-align: center; + .picture { + width: 48px; + text-align: center; + @include padding-horizontal(4px, 0px); + padding-top: 8px; + + img { + width: 44px !important; + } + } } .subject { diff --git a/src/addons/notifications/pages/list/list.html b/src/addons/notifications/pages/list/list.html index aa11a1300..3aba09f1e 100644 --- a/src/addons/notifications/pages/list/list.html +++ b/src/addons/notifications/pages/list/list.html @@ -48,7 +48,7 @@ + [contextInstanceId]="0" [maxHeight]="120"> diff --git a/src/addons/notifications/pages/list/list.ts b/src/addons/notifications/pages/list/list.ts index 23d0bc820..5968a852e 100644 --- a/src/addons/notifications/pages/list/list.ts +++ b/src/addons/notifications/pages/list/list.ts @@ -36,7 +36,7 @@ import { @Component({ selector: 'page-addon-notifications-list', templateUrl: 'list.html', - styleUrls: ['list.scss'], + styleUrls: ['../../notifications.scss'], }) export class AddonNotificationsListPage implements OnInit, OnDestroy { diff --git a/src/addons/notifications/pages/notification/notification.ts b/src/addons/notifications/pages/notification/notification.ts index 6b400b795..f2594a9e4 100644 --- a/src/addons/notifications/pages/notification/notification.ts +++ b/src/addons/notifications/pages/notification/notification.ts @@ -29,6 +29,7 @@ import { CoreUtils } from '@services/utils/utils'; @Component({ selector: 'page-addon-notifications-notification', templateUrl: 'notification.html', + styleUrls: ['../../notifications.scss'], }) export class AddonNotificationsNotificationPage implements OnInit { diff --git a/src/addons/notifications/services/notifications-helper.ts b/src/addons/notifications/services/notifications-helper.ts index 43b538796..ec2758f5b 100644 --- a/src/addons/notifications/services/notifications-helper.ts +++ b/src/addons/notifications/services/notifications-helper.ts @@ -25,7 +25,6 @@ import { AddonNotificationsPreferencesNotificationProcessor, AddonNotificationsPreferencesProcessor, } from './notifications'; -import { CoreTextUtils } from '@services/utils/text'; /** * Service that provides some helper functions for notifications. @@ -42,13 +41,8 @@ export class AddonNotificationsHelperProvider { notification: AddonNotificationsNotificationMessageFormatted, ): AddonNotificationsNotificationToRender { const formattedNotification: AddonNotificationsNotificationToRender = notification; - formattedNotification.displayfullhtml = this.shouldDisplayFullHtml(notification); formattedNotification.iconurl = formattedNotification.iconurl || undefined; // Make sure the property exists. - formattedNotification.mobiletext = formattedNotification.displayfullhtml ? - notification.fullmessagehtml : - CoreTextUtils.replaceNewLines((formattedNotification.mobiletext || '').replace(/-{4,}/ig, ''), '
'); - return formattedNotification; } @@ -140,16 +134,6 @@ export class AddonNotificationsHelperProvider { return result; } - /** - * Check whether we should display full HTML of the notification. - * - * @param notification Notification. - * @return Whether to display full HTML. - */ - protected shouldDisplayFullHtml(notification: AddonNotificationsNotificationToRender): boolean { - return notification.component == 'mod_forum' && notification.eventtype == 'digests'; - } - } export const AddonNotificationsHelper = makeSingleton(AddonNotificationsHelperProvider); @@ -187,6 +171,5 @@ export type AddonNotificationsPreferencesProcessorFormatted = AddonNotifications * Notification with some calculated data to render it. */ export type AddonNotificationsNotificationToRender = AddonNotificationsNotificationMessageFormatted & { - displayfullhtml?: boolean; // Whether to display the full HTML of the notification. iconurl?: string; }; diff --git a/src/addons/notifications/services/notifications.ts b/src/addons/notifications/services/notifications.ts index 4678f9393..3a28a19dc 100644 --- a/src/addons/notifications/services/notifications.ts +++ b/src/addons/notifications/services/notifications.ts @@ -56,13 +56,7 @@ export class AddonNotificationsProvider { const promises = notifications.map(async (notificationRaw) => { const notification = notificationRaw; - // Set message to show. - if (notification.component && notification.component == 'mod_forum') { - notification.mobiletext = notification.smallmessage; - } else { - notification.mobiletext = notification.fullmessage; - } - + notification.mobiletext = notification.fullmessagehtml || notification.fullmessage || notification.smallmessage; notification.moodlecomponent = notification.component; notification.notification = 1; notification.notif = 1; @@ -171,7 +165,7 @@ export class AddonNotificationsProvider { // Request 1 more notification so we can know if there are more notifications. const originalLimit = options.limit; - options.limit + 1; + options.limit = options.limit + 1; const site = await CoreSites.getSite(options.siteId); diff --git a/src/core/directives/format-text.ts b/src/core/directives/format-text.ts index 4869c50b8..ea1ed3e5e 100644 --- a/src/core/directives/format-text.ts +++ b/src/core/directives/format-text.ts @@ -166,8 +166,8 @@ export class CoreFormatTextDirective implements OnChanges { const originalWidth = img.attributes.getNamedItem('width'); const forcedWidth = Number(originalWidth?.value); - if (!isNaN(forcedWidth)) { - if (originalWidth!.value.indexOf('%') < 0) { + if (originalWidth && !isNaN(forcedWidth)) { + if (originalWidth.value.indexOf('%') < 0) { img.style.width = forcedWidth + 'px'; } else { img.style.width = forcedWidth + '%';