From 210f1ab424ee0ee9e900cfa196541a810c2f28ac Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 2 Jul 2015 23:30:26 +0800 Subject: [PATCH] FIX: Emoji not shown in notifications. Fixes: https://meta.discourse.org/t/topic-title-emoji-not-supported-in-notifications/30670/2. --- .../discourse/components/notification-item.js.es6 | 2 +- .../javascripts/discourse/lib/emoji/emoji.js.erb | 12 ++++++++++++ app/assets/javascripts/discourse/models/topic.js.es6 | 12 +----------- .../javascripts/discourse/models/user-stream.js.es6 | 1 + .../javascripts/discourse/templates/user/stream.hbs | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/components/notification-item.js.es6 b/app/assets/javascripts/discourse/components/notification-item.js.es6 index a13cd0d5d6c..d4692458cba 100644 --- a/app/assets/javascripts/discourse/components/notification-item.js.es6 +++ b/app/assets/javascripts/discourse/components/notification-item.js.es6 @@ -53,7 +53,7 @@ export default Ember.Component.extend({ const notification = this.get('notification'); const description = this.get('description'); const username = notification.get('data.display_username'); - const text = I18n.t(this.get('scope'), {description, username}); + const text = Discourse.Emoji.unescape(I18n.t(this.get('scope'), {description, username})); const url = this.get('url'); if (url) { diff --git a/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb b/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb index 1441f0cdcef..1c32cb054c7 100644 --- a/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb +++ b/app/assets/javascripts/discourse/lib/emoji/emoji.js.erb @@ -29,6 +29,18 @@ for (var name in aliases) { }); } +Discourse.Emoji.unescape = function(string) { + if (Discourse.SiteSettings.enable_emoji && string.indexOf(":") >= 0) { + string = string.replace(/:[^\s:]+:?/g, function(m) { + const emoji = Discourse.Emoji.translations[m] ? Discourse.Emoji.translations[m] : m.slice(1, m.length - 1), + url = Discourse.Emoji.urlFor(emoji); + return url ? "" + emoji + "" : m; + }); + } + + return string; +} + Discourse.Emoji.urlFor = urlFor = function(code) { var url, set = Discourse.SiteSettings.emoji_set; diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index 798053e3c25..486129f4f9f 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -6,17 +6,7 @@ const Topic = RestModel.extend({ errorLoading: false, fancyTitle: function() { - let title = this.get("fancy_title"); - - if (Discourse.SiteSettings.enable_emoji && title.indexOf(":") >= 0) { - title = title.replace(/:[^\s:]+:?/g, function(m) { - const emoji = Discourse.Emoji.translations[m] ? Discourse.Emoji.translations[m] : m.slice(1, m.length - 1), - url = Discourse.Emoji.urlFor(emoji); - return url ? "" + emoji + "" : m; - }); - } - - return title; + return Discourse.Emoji.unescape(this.get('fancy_title')); }.property("fancy_title"), // returns createdAt if there's no bumped date diff --git a/app/assets/javascripts/discourse/models/user-stream.js.es6 b/app/assets/javascripts/discourse/models/user-stream.js.es6 index 635b349dbfd..ac3883ba388 100644 --- a/app/assets/javascripts/discourse/models/user-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/user-stream.js.es6 @@ -68,6 +68,7 @@ export default RestModel.extend({ if (result && result.user_actions) { const copy = Em.A(); result.user_actions.forEach(function(action) { + action.title = Discourse.Emoji.unescape(action.title); copy.pushObject(Discourse.UserAction.create(action)); }); diff --git a/app/assets/javascripts/discourse/templates/user/stream.hbs b/app/assets/javascripts/discourse/templates/user/stream.hbs index 0637feec4b3..96e96c83768 100644 --- a/app/assets/javascripts/discourse/templates/user/stream.hbs +++ b/app/assets/javascripts/discourse/templates/user/stream.hbs @@ -5,7 +5,7 @@ {{format-date item.created_at}} {{topic-status topic=item disableActions=true}} - {{unbound item.title}} + {{{unbound item.title}}}
{{category-link item.category}}