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 new file mode 100644 index 00000000000..476ea707de1 --- /dev/null +++ b/app/assets/javascripts/discourse/widgets/concerns/notification-types.js.es6.erb @@ -0,0 +1,3 @@ +<% 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 a0d01f3f05c..57a695d1207 100644 --- a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 +++ b/app/assets/javascripts/discourse/widgets/notification-item.js.es6 @@ -13,10 +13,12 @@ import { setTransientHeader } from "discourse/lib/ajax"; import { userPath } from "discourse/lib/url"; import { iconNode } from "discourse-common/lib/icon-library"; -const LIKED_TYPE = 5; -const INVITED_TYPE = 8; -const GROUP_SUMMARY_TYPE = 16; -export const LIKED_CONSOLIDATED_TYPE = 19; +import { + LIKED_TYPE, + INVITEE_ACCEPTED_TYPE, + GROUP_MESSAGE_SUMMARY_TYPE, + LIKED_CONSOLIDATED_TYPE +} from "discourse/widgets/concerns/notification-types"; createWidget("notification-item", { tagName: "li", @@ -58,7 +60,7 @@ createWidget("notification-item", { return postUrl(attrs.slug, topicId, attrs.post_number); } - if (attrs.notification_type === INVITED_TYPE) { + if (attrs.notification_type === INVITEE_ACCEPTED_TYPE) { return userPath(data.display_username); } @@ -112,7 +114,7 @@ createWidget("notification-item", { const scope = notName === "custom" ? data.message : `notifications.${notName}`; - if (notificationType === GROUP_SUMMARY_TYPE) { + if (notificationType === GROUP_MESSAGE_SUMMARY_TYPE) { const count = data.inbox_count; const group_name = data.group_name; return I18n.t(scope, { count, group_name }); diff --git a/test/javascripts/fixtures/notification_fixtures.js.es6 b/test/javascripts/fixtures/notification_fixtures.js.es6 index 0ebf8bd6784..bcfbadf4a95 100644 --- a/test/javascripts/fixtures/notification_fixtures.js.es6 +++ b/test/javascripts/fixtures/notification_fixtures.js.es6 @@ -1,12 +1,15 @@ /*jshint maxlen:10000000 */ -import { LIKED_CONSOLIDATED_TYPE } from "discourse/widgets/notification-item"; +import { + LIKED_CONSOLIDATED_TYPE, + REPLIED_TYPE +} from "discourse/widgets/concerns/notification-types"; export default { "/notifications": { notifications: [ { id: 123, - notification_type: 2, + notification_type: REPLIED_TYPE, read: false, post_number: 2, topic_id: 1234, diff --git a/test/javascripts/fixtures/site-fixtures.js.es6 b/test/javascripts/fixtures/site-fixtures.js.es6 index 25d1dc32c01..15f136b450e 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/notification-item"; +import { LIKED_CONSOLIDATED_TYPE } from "discourse/widgets/concerns/notification-types"; export default { "site.json": {