FIX: Emoji not shown in notifications.

Fixes: https://meta.discourse.org/t/topic-title-emoji-not-supported-in-notifications/30670/2.
This commit is contained in:
Guo Xiang Tan 2015-07-02 23:30:26 +08:00
parent 0c403272e2
commit 210f1ab424
5 changed files with 16 additions and 13 deletions

View File

@ -53,7 +53,7 @@ export default Ember.Component.extend({
const notification = this.get('notification'); const notification = this.get('notification');
const description = this.get('description'); const description = this.get('description');
const username = notification.get('data.display_username'); 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'); const url = this.get('url');
if (url) { if (url) {

View File

@ -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 ? "<img src='" + url + "' title='" + emoji + "' alt='" + emoji + "' class='emoji'>" : m;
});
}
return string;
}
Discourse.Emoji.urlFor = urlFor = function(code) { Discourse.Emoji.urlFor = urlFor = function(code) {
var url, set = Discourse.SiteSettings.emoji_set; var url, set = Discourse.SiteSettings.emoji_set;

View File

@ -6,17 +6,7 @@ const Topic = RestModel.extend({
errorLoading: false, errorLoading: false,
fancyTitle: function() { fancyTitle: function() {
let title = this.get("fancy_title"); return Discourse.Emoji.unescape(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 ? "<img src='" + url + "' title='" + emoji + "' alt='" + emoji + "' class='emoji'>" : m;
});
}
return title;
}.property("fancy_title"), }.property("fancy_title"),
// returns createdAt if there's no bumped date // returns createdAt if there's no bumped date

View File

@ -68,6 +68,7 @@ export default RestModel.extend({
if (result && result.user_actions) { if (result && result.user_actions) {
const copy = Em.A(); const copy = Em.A();
result.user_actions.forEach(function(action) { result.user_actions.forEach(function(action) {
action.title = Discourse.Emoji.unescape(action.title);
copy.pushObject(Discourse.UserAction.create(action)); copy.pushObject(Discourse.UserAction.create(action));
}); });

View File

@ -5,7 +5,7 @@
<span class='time'>{{format-date item.created_at}}</span> <span class='time'>{{format-date item.created_at}}</span>
{{topic-status topic=item disableActions=true}} {{topic-status topic=item disableActions=true}}
<span class="title"> <span class="title">
<a href="{{unbound item.postUrl}}">{{unbound item.title}}</a> <a href="{{unbound item.postUrl}}">{{{unbound item.title}}}</a>
</span> </span>
<div class="category">{{category-link item.category}}</div> <div class="category">{{category-link item.category}}</div>
</div> </div>