diff --git a/static/js/services/notification-service.js b/static/js/services/notification-service.js index 73d70d227..31b255ddb 100644 --- a/static/js/services/notification-service.js +++ b/static/js/services/notification-service.js @@ -3,9 +3,9 @@ * in the sidebar) and provides helper methods for working with them. */ angular.module('quay').factory('NotificationService', - ['$rootScope', '$interval', 'UserService', 'ApiService', 'StringBuilderService', 'PlanService', 'CookieService', 'Features', 'Config', '$location', 'VulnerabilityService', + ['$rootScope', '$interval', 'UserService', 'ApiService', 'StringBuilderService', 'PlanService', 'CookieService', 'Features', 'Config', '$location', 'VulnerabilityService', 'UtilService', -function($rootScope, $interval, UserService, ApiService, StringBuilderService, PlanService, CookieService, Features, Config, $location, VulnerabilityService) { +function($rootScope, $interval, UserService, ApiService, StringBuilderService, PlanService, CookieService, Features, Config, $location, VulnerabilityService, UtilService) { var notificationService = { 'user': null, 'notifications': [], @@ -229,6 +229,16 @@ function($rootScope, $interval, UserService, ApiService, StringBuilderService, P return StringBuilderService.buildTrustedString(kindInfo['message'], notification['metadata']); }; + notificationService.getBrowserNotificationMessage = function(notification) { + var kindInfo = notificationKinds[notification['kind']]; + if (!kindInfo) { + return '(Unknown notification kind: ' + notification['kind'] + ')'; + } + + const unsafeHtml = StringBuilderService.buildString(kindInfo['message'], notification['metadata']); + return UtilService.removeHtmlTags(unsafeHtml); + } + notificationService.getClass = function(notification) { var kindInfo = notificationKinds[notification['kind']]; if (!kindInfo) { @@ -294,7 +304,7 @@ function($rootScope, $interval, UserService, ApiService, StringBuilderService, P if (newNotifications.length > 0) { let message = 'You have unread notifications'; if (newNotifications.length === 1) { - message = notificationService.getMessage(newNotifications[0]); + message = notificationService.getBrowserNotificationMessage(newNotifications[0]); } new Notification(message, { diff --git a/static/js/services/util-service.js b/static/js/services/util-service.js index d6f08f2c3..2c7275da5 100644 --- a/static/js/services/util-service.js +++ b/static/js/services/util-service.js @@ -136,5 +136,14 @@ angular.module('quay').factory('UtilService', ['$sanitize', 'markdownConverter', utilService.UrlBuilder = UrlBuilder; + utilService.removeHtmlTags = function(text){ + try { + return new DOMParser().parseFromString(text, 'text/html').body.textContent || text; + } catch(e) { + return text; + } + + }; + return utilService; }]);