diff --git a/app/assets/javascripts/discourse-common/lib/icon-library.js.es6 b/app/assets/javascripts/discourse-common/lib/icon-library.js.es6 index 5bf0d55a1b0..da6ac057d31 100644 --- a/app/assets/javascripts/discourse-common/lib/icon-library.js.es6 +++ b/app/assets/javascripts/discourse-common/lib/icon-library.js.es6 @@ -30,6 +30,9 @@ const REPLACEMENTS = { 'notification.group_message_summary': "group" }; +export function replaceIcon(source, destination) { + REPLACEMENTS[source] = destination; +} export function renderIcon(renderType, id, params) { for (let i=0; i<_renderers.length; i++) { diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index fe5c67d43ba..abecedf4704 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -19,12 +19,12 @@ import { addUserMenuGlyph } from 'discourse/widgets/user-menu'; import { addPostClassesCallback } from 'discourse/widgets/post'; import { addPostTransformCallback } from 'discourse/widgets/post-stream'; import { attachAdditionalPanel } from 'discourse/widgets/header'; -import { registerIconRenderer } from 'discourse-common/lib/icon-library'; +import { registerIconRenderer, replaceIcon } from 'discourse-common/lib/icon-library'; import { addNavItem } from 'discourse/models/nav-item'; // If you add any methods to the API ensure you bump up this number -const PLUGIN_API_VERSION = '0.8.9'; +const PLUGIN_API_VERSION = '0.8.10'; class PluginApi { constructor(version, container) { @@ -90,6 +90,18 @@ class PluginApi { registerIconRenderer(fn); } + /** + * Replace all ocurrences of one icon with another without having to + * resort to a custom IconRenderer. If you want to do something more + * complicated than a simple replacement then create a new icon renderer. + * + * api.replaceIcon('d-tracking', 'smile-o'); + * + **/ + replaceIcon(source, destination) { + replaceIcon(source, destination); + } + /** * Used for decorating the `cooked` content of a post after it is rendered using * jQuery. diff --git a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 b/app/assets/javascripts/discourse/widgets/notification-item.js.es6 index cb12ed45d74..f2878b5f126 100644 --- a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 +++ b/app/assets/javascripts/discourse/widgets/notification-item.js.es6 @@ -99,8 +99,11 @@ createWidget('notification-item', { const lookup = this.site.get('notificationLookup'); const notName = lookup[notificationType]; - let title = I18n.t(`notifications.alt.${notName}`); - let icon = iconNode(`notification.${notName}`, { title }); + let { data } = attrs; + let infoKey = notName === 'custom' ? data.message : notName; + let title = I18n.t(`notifications.alt.${infoKey}`); + let icon = iconNode(`notification.${infoKey}`, { title }); + let text = emojiUnescape(this.text(notificationType, notName)); // We can use a `
` tag here once other languages have fixed their HTML