From d6f1c10b1bae6b0059bbe5827e3b7424fd692d6b Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 24 Nov 2010 02:31:55 +0300 Subject: [PATCH] messageTray: fix handling of markup vs non-markup notifications NotificationDaemon-based notifications have markup in the banner/body, but Telepathy-based notifications don't. (Eg, an XMPP message containing "foo" should show up angle brackets and all, not as bold.) Fix MessageTray.Notification to allow explicitly specifying where there should and shouldn't be markup, and use that appropriately. https://bugzilla.gnome.org/show_bug.cgi?id=610219 --- js/ui/messageTray.js | 59 ++++++++++++++++++++++++------------- js/ui/notificationDaemon.js | 7 +++-- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 2b6226a78..05335b550 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -38,21 +38,27 @@ const State = { HIDING: 3 }; -function _cleanMarkup(text) { - // Support &, ", ', < and >, escape all other - // occurrences of '&'. - let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&'); - // Support , , and , escape anything else - // so it displays as raw markup. - return _text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, '<$1'); +function _fixMarkup(text, allowMarkup) { + if (allowMarkup) { + // Support &, ", ', < and >, escape all other + // occurrences of '&'. + let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&'); + // Support , , and , escape anything else + // so it displays as raw markup. + return _text.replace(/<(\/?[^biu]>|[^>\/][^>])/g, '<$1'); + } else { + // Escape everything + let _text = text.replace(/&/g, '&'); + return _text.replace(/' + title + ''); // Unless the notification has custom content, we save this._bannerBodyText @@ -328,10 +345,11 @@ Notification.prototype = { // expandable due to other elements in its content area or due to the banner // not fitting fully in the single-line mode. this._bannerBodyText = this._customContent ? null : banner; + this._bannerBodyMarkup = params.bannerMarkup; banner = banner ? banner.replace(/\n/g, ' ') : ''; - this._bannerUrlHighlighter.setMarkup(banner); + this._bannerUrlHighlighter.setMarkup(banner, params.bannerMarkup); this._bannerLabel.queue_relayout(); // Add the bannerBody now if we know for sure we'll need it @@ -339,7 +357,7 @@ Notification.prototype = { this._addBannerBody(); if (params.body) - this.addBody(params.body); + this.addBody(params.body, params.bodyMarkup); this._updated(); }, @@ -370,12 +388,13 @@ Notification.prototype = { // addBody: // @text: the text + // @markup: %true if @text contains pango markup // // Adds a multi-line label containing @text to the notification. // // Return value: the newly-added label - addBody: function(text) { - let label = new URLHighlighter(text, true); + addBody: function(text, markup) { + let label = new URLHighlighter(text, true, markup); this.addActor(label.actor); return label.actor; @@ -385,7 +404,7 @@ Notification.prototype = { if (this._bannerBodyText) { let text = this._bannerBodyText; this._bannerBodyText = null; - this.addBody(text); + this.addBody(text, this._bannerBodyMarkup); } }, diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index c62cb4c20..dc5053738 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -205,8 +205,6 @@ NotificationDaemon.prototype = { return id; } - summary = GLib.markup_escape_text(summary, -1); - let rewrites = rewriteRules[appName]; if (rewrites) { for (let i = 0; i < rewrites.length; i++) { @@ -281,7 +279,9 @@ NotificationDaemon.prototype = { let iconActor = this._iconForNotificationData(icon, hints, source.ICON_SIZE); if (notification == null) { - notification = new MessageTray.Notification(source, summary, body, { icon: iconActor }); + notification = new MessageTray.Notification(source, summary, body, + { icon: iconActor, + bannerMarkup: true }); ndata.notification = notification; notification.connect('clicked', Lang.bind(this, function(n) { @@ -294,6 +294,7 @@ NotificationDaemon.prototype = { notification.connect('action-invoked', Lang.bind(this, this._actionInvoked, source, id)); } else { notification.update(summary, body, { icon: iconActor, + bannerMarkup: true, clear: true }); }