diff --git a/app/assets/javascripts/discourse/widgets/concerns/notification-types.js.es6.erb b/app/assets/javascripts/discourse/widgets/concerns/notification-types.js.es6.erb deleted file mode 100644 index 476ea707de1..00000000000 --- a/app/assets/javascripts/discourse/widgets/concerns/notification-types.js.es6.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% Notification.types.each do |key, value| %> -export const <%= key.upcase %>_TYPE = <%= value %>; -<% end %> diff --git a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 b/app/assets/javascripts/discourse/widgets/notification-item.js.es6 index 117cb94b2b8..e89eeb210a0 100644 --- a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 +++ b/app/assets/javascripts/discourse/widgets/notification-item.js.es6 @@ -13,13 +13,6 @@ import { setTransientHeader } from "discourse/lib/ajax"; import { userPath } from "discourse/lib/url"; import { iconNode } from "discourse-common/lib/icon-library"; -import { - LIKED_TYPE, - INVITEE_ACCEPTED_TYPE, - GROUP_MESSAGE_SUMMARY_TYPE, - LIKED_CONSOLIDATED_TYPE -} from "discourse/widgets/concerns/notification-types"; - createWidget("notification-item", { tagName: "li", @@ -37,6 +30,7 @@ createWidget("notification-item", { url() { const attrs = this.attrs; const data = attrs.data; + const notificationTypes = this.site.get("notification_types"); const badgeId = data.badge_id; if (badgeId) { @@ -60,11 +54,11 @@ createWidget("notification-item", { return postUrl(attrs.slug, topicId, attrs.post_number); } - if (attrs.notification_type === INVITEE_ACCEPTED_TYPE) { + if (attrs.notification_type === notificationTypes.invitee_accepted) { return userPath(data.display_username); } - if (attrs.notification_type === LIKED_CONSOLIDATED_TYPE) { + if (attrs.notification_type === notificationTypes.liked_consolidated) { return userPath( `${this.attrs.username || this.currentUser @@ -97,7 +91,10 @@ createWidget("notification-item", { let title; - if (this.attrs.notification_type === LIKED_CONSOLIDATED_TYPE) { + if ( + this.attrs.notification_type === + this.site.get("notification_types").liked_consolidated + ) { title = I18n.t("notifications.liked_consolidated_description", { count: parseInt(data.count) }); @@ -114,7 +111,9 @@ createWidget("notification-item", { const scope = notName === "custom" ? data.message : `notifications.${notName}`; - if (notificationType === GROUP_MESSAGE_SUMMARY_TYPE) { + const notificationTypes = this.site.get("notification_types"); + + if (notificationType === notificationTypes.group_message_summary) { const count = data.inbox_count; const group_name = data.group_name; return I18n.t(scope, { count, group_name }); @@ -123,7 +122,7 @@ createWidget("notification-item", { const username = formatUsername(data.display_username); const description = this.description(); - if (notificationType === LIKED_TYPE && data.count > 1) { + if (notificationType === notificationTypes.liked && data.count > 1) { const count = data.count - 2; const username2 = formatUsername(data.username2); diff --git a/test/javascripts/fixtures/concerns/notification-types.js.es6.erb b/test/javascripts/fixtures/concerns/notification-types.js.es6.erb new file mode 100644 index 00000000000..d7a4023b4d2 --- /dev/null +++ b/test/javascripts/fixtures/concerns/notification-types.js.es6.erb @@ -0,0 +1 @@ +export const NOTIFICATION_TYPES = <%= Notification.types.to_json %>; diff --git a/test/javascripts/fixtures/notification_fixtures.js.es6 b/test/javascripts/fixtures/notification_fixtures.js.es6 index bcfbadf4a95..071df77a0d0 100644 --- a/test/javascripts/fixtures/notification_fixtures.js.es6 +++ b/test/javascripts/fixtures/notification_fixtures.js.es6 @@ -1,15 +1,12 @@ /*jshint maxlen:10000000 */ -import { - LIKED_CONSOLIDATED_TYPE, - REPLIED_TYPE -} from "discourse/widgets/concerns/notification-types"; +import { NOTIFICATION_TYPES } from "fixtures/concerns/notification-types"; export default { "/notifications": { notifications: [ { id: 123, - notification_type: REPLIED_TYPE, + notification_type: NOTIFICATION_TYPES.replied, read: false, post_number: 2, topic_id: 1234, @@ -18,7 +15,7 @@ export default { }, { id: 456, - notification_type: LIKED_CONSOLIDATED_TYPE, + notification_type: NOTIFICATION_TYPES.liked_consolidated, read: false, data: { display_username: "aquaman", count: "5" } } diff --git a/test/javascripts/fixtures/site-fixtures.js.es6 b/test/javascripts/fixtures/site-fixtures.js.es6 index 15f136b450e..5dbd4805d49 100644 --- a/test/javascripts/fixtures/site-fixtures.js.es6 +++ b/test/javascripts/fixtures/site-fixtures.js.es6 @@ -1,4 +1,4 @@ -import { LIKED_CONSOLIDATED_TYPE } from "discourse/widgets/concerns/notification-types"; +import { NOTIFICATION_TYPES } from "fixtures/concerns/notification-types"; export default { "site.json": { @@ -6,21 +6,7 @@ export default { default_archetype: "regular", disabled_plugins: [], shared_drafts_category_id: 24, - notification_types: { - mentioned: 1, - replied: 2, - quoted: 3, - edited: 4, - liked: 5, - private_message: 6, - invited_to_private_message: 7, - invitee_accepted: 8, - posted: 9, - moved_post: 10, - linked: 11, - granted_badge: 12, - liked_consolidated: LIKED_CONSOLIDATED_TYPE - }, + notification_types: NOTIFICATION_TYPES, post_types: { regular: 1, moderator_action: 2,