diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 index 005e068..4351966 100644 --- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 +++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 @@ -506,6 +506,26 @@ function initialize(api) { }, }); + api.modifyClass("component:topic-notifications-button", { + pluginId: PLUGIN_ID, + + @discourseComputed( + "topic", + "topic.details.{notification_level,notifications_reason_id}" + ) + notificationReasonText(topic) { + if ( + this.currentUser.never_auto_track_topics && + topic.assigned_to_user && + topic.assigned_to_user.username === this.currentUser.username + ) { + return I18n.t("notification_reason.user"); + } + + return this._super(...arguments); + }, + }); + api.addPostSmallActionIcon("assigned", "user-plus"); api.addPostSmallActionIcon("assigned_to_post", "user-plus"); api.addPostSmallActionIcon("assigned_group", "group-plus"); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index bae1a43..543e07f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -119,3 +119,5 @@ en: label: Assigned Topic ID in_working_hours: label: Users in working hours + notification_reason: + user: "You will see a count of new replies because this topic was assigned to you." diff --git a/plugin.rb b/plugin.rb index 1f74e03..7d5313a 100644 --- a/plugin.rb +++ b/plugin.rb @@ -133,6 +133,10 @@ after_initialize do @can_assign == :true end + add_to_serializer(:current_user, :never_auto_track_topics) do + user.user_option.auto_track_topics_after_msecs < 0 + end + add_to_class(:group, :can_show_assigned_tab?) do allowed_group_ids = SiteSetting.assign_allowed_on_groups.split("|") diff --git a/test/javascripts/acceptance/never-track-assign-reason-test.js.es6 b/test/javascripts/acceptance/never-track-assign-reason-test.js.es6 new file mode 100644 index 0000000..c55326a --- /dev/null +++ b/test/javascripts/acceptance/never-track-assign-reason-test.js.es6 @@ -0,0 +1,70 @@ +import { test } from "qunit"; +import { + acceptance, + query, + updateCurrentUser, +} from "discourse/tests/helpers/qunit-helpers"; +import { visit } from "@ember/test-helpers"; +import { cloneJSON } from "discourse-common/lib/object"; +import topicFixtures from "discourse/tests/fixtures/topic"; + +acceptance( + "Discourse Assign | Never track topics assign reason", + function (needs) { + needs.user(); + needs.settings({ + assign_enabled: true, + assigns_user_url_path: "/", + }); + + needs.pretender((server, helper) => { + server.get("/t/44.json", () => { + let topic = cloneJSON(topicFixtures["/t/130.json"]); + topic.details.notifications_reason_id = 3; + return helper.response(topic); + }); + server.get("/t/45.json", () => { + let topic = cloneJSON(topicFixtures["/t/28830/1.json"]); + topic["assigned_to_user"] = { + username: "eviltrout", + name: "Robin Ward", + avatar_template: + "/letter_avatar/eviltrout/{size}/3_f9720745f5ce6dfc2b5641fca999d934.png", + }; + return helper.response(topic); + }); + server.get("/t/46.json", () => { + let topic = cloneJSON(topicFixtures["/t/28830/1.json"]); + topic["assigned_to_group"] = { + id: 47, + name: "discourse", + }; + return helper.response(topic); + }); + }); + + test("Show default assign reason when user tracks topics", async (assert) => { + updateCurrentUser({ never_auto_track_topics: false }); + + await visit("/t/assignment-topic/44"); + + assert.strictEqual( + query(".topic-notifications-button .reason span.text").innerText, + "You will receive notifications because you are watching this topic." + ); + }); + + test("Show user assign reason when user never tracks topics", async (assert) => { + updateCurrentUser({ + never_auto_track_topics: true, + }); + + await visit("/t/assignment-topic/45"); + + assert.strictEqual( + query(".topic-notifications-button .reason span.text").innerText, + "You will see a count of new replies because this topic was assigned to you." + ); + }); + } +);