diff --git a/openwisp_notifications/api/serializers.py b/openwisp_notifications/api/serializers.py index c5060a42..2f843a2d 100644 --- a/openwisp_notifications/api/serializers.py +++ b/openwisp_notifications/api/serializers.py @@ -59,7 +59,7 @@ class Meta(NotificationSerializer.Meta): fields = [ 'id', 'message', - 'description', + 'get_description', 'unread', 'target_url', 'email_subject', diff --git a/openwisp_notifications/base/models.py b/openwisp_notifications/base/models.py index 8b5fb871..82e346a8 100644 --- a/openwisp_notifications/base/models.py +++ b/openwisp_notifications/base/models.py @@ -105,6 +105,10 @@ def target_url(self): def message(self): return self.get_message() + @cached_property + def get_description(self): + return mark_safe(markdown(self.description)) + @property def email_message(self): return self.get_message(email_message=True) diff --git a/openwisp_notifications/static/openwisp-notifications/js/notifications.js b/openwisp_notifications/static/openwisp-notifications/js/notifications.js index 0c5e05d4..515ca078 100644 --- a/openwisp_notifications/static/openwisp-notifications/js/notifications.js +++ b/openwisp_notifications/static/openwisp-notifications/js/notifications.js @@ -233,7 +233,7 @@ function notificationWidget($) {
${datetime}
- ${elem.description ? elem.message.replace(/]*>([^<]*)<\/a>/g, '$1') : convertMessageWithRelativeURL(elem.message)} + ${elem.get_description ? elem.message.replace(/]*>([^<]*)<\/a>/g, '$1') : convertMessageWithRelativeURL(elem.message)} `; } @@ -326,7 +326,7 @@ function notificationWidget($) { } var notification = fetchedPages.flat().find((notification) => notification.id == elem.get(0).id.replace('ow-', '')); - if (notification.description) { + if (notification.get_description) { const datetime = dateTimeStampToDateTimeLocaleString(new Date(notification.timestamp)); document.querySelector('.ow-dialog-notification-level-wrapper').innerHTML = `
@@ -336,7 +336,7 @@ function notificationWidget($) {
${datetime}
`; document.querySelector('.ow-message-title').innerHTML = convertMessageWithRelativeURL(notification.message); - document.querySelector('.ow-message-description').innerHTML = notification.description; + document.querySelector('.ow-message-description').innerHTML = notification.get_description; $('.ow-dialog-overlay').removeClass('ow-hide'); if (notification.target_url) { var target_url = new URL(notification.target_url, window.location.href);