A platform for community discussion. Free, open, simple.
FEATURE: Differentiate notification type for directly vs indirectly watched topic (#19433)
Krzysztof Kotlarekaa3a9b6fea91
diff --git a/app/assets/javascripts/discourse-common/addon/lib/icon-library.js b/app/assets/javascripts/discourse-common/addon/lib/icon-library.jsindex 8882d7c8d60..34d6b6912c2 100644--- a/app/assets/javascripts/discourse-common/addon/lib/icon-library.js+++ b/app/assets/javascripts/discourse-common/addon/lib/icon-library.js@@ -28,6 +28,7 @@ const REPLACEMENTS = {"notification.quoted": "quote-right","notification.replied": "reply","notification.posted": "discourse-bell-exclamation",+ "notification.watching_category_or_tag": "discourse-bell-exclamation","notification.edited": "pencil-alt","notification.bookmark_reminder": "discourse-bookmark-clock","notification.liked": "heart",diff --git a/app/assets/javascripts/discourse/app/components/user-menu/menu.js b/app/assets/javascripts/discourse/app/components/user-menu/menu.jsindex fc963747a34..cd79a6c7b03 100644--- a/app/assets/javascripts/discourse/app/components/user-menu/menu.js+++ b/app/assets/javascripts/discourse/app/components/user-menu/menu.js@@ -49,19 +49,12 @@ const CORE_TOP_TABS = [this.getUnreadCountForType("mentioned") +this.getUnreadCountForType("posted") +this.getUnreadCountForType("quoted") +- this.getUnreadCountForType("replied") +- this.getUnreadCountForType("watching_first_post")+ this.getUnreadCountForType("replied"));}get notificationTypes() {- return [- "mentioned",- "posted",- "quoted",- "replied",- "watching_first_post",- ];+ return ["mentioned", "posted", "quoted", "replied"];}get linkWhenActive() {diff --git a/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-test.js b/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-test.jsindex 562784895f2..36026d25119 100644--- a/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-test.js+++ b/app/assets/javascripts/discourse/tests/integration/components/user-menu/menu-test.js@@ -222,8 +222,7 @@ module("Integration | Component | user-menu", function (hooks) {},];} else if (- queryParams.filter_by_types ===- "mentioned,posted,quoted,replied,watching_first_post"+ queryParams.filter_by_types === "mentioned,posted,quoted,replied") {data = [{@@ -281,8 +280,8 @@ module("Integration | Component | user-menu", function (hooks) {assert.ok(exists("#quick-access-replies.quick-access-panel"));assert.strictEqual(queryParams.filter_by_types,- "mentioned,posted,quoted,replied,watching_first_post",- "request params has filter_by_types set to `mentioned`, `posted`, `quoted`, `replied` and `watching_first_post`"+ "mentioned,posted,quoted,replied",+ "request params has filter_by_types set to `mentioned`, `posted`, `quoted` and `replied`");assert.strictEqual(queryParams.silent, "true");activeTabs = queryAll(".top-tabs .btn.active");diff --git a/app/models/notification.rb b/app/models/notification.rbindex b6e95aa2561..350de63720f 100644--- a/app/models/notification.rb+++ b/app/models/notification.rb@@ -138,6 +138,7 @@ class Notification < ActiveRecord::Basechat_quoted: 33,assigned: 34,question_answer_user_commented: 35, # Used by https://github.com/discourse/discourse-question-answer+ watching_category_or_tag: 36,)enddiff --git a/app/services/notification_emailer.rb b/app/services/notification_emailer.rbindex 05e7a8b435a..b768ae5b68b 100644--- a/app/services/notification_emailer.rb+++ b/app/services/notification_emailer.rb@@ -22,6 +22,10 @@ class NotificationEmailerenqueue :user_postedend+ def watching_category_or_tag+ enqueue :user_posted+ end+def quotedenqueue :user_quotedend@@ -134,7 +138,6 @@ class NotificationEmaileremail_user = EmailUser.new(notification, no_delay: no_delay)email_method = Notification.types[notification.notification_type]-email_user.public_send(email_method) if email_user.respond_to? email_methodenddiff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex c4c930b5cab..9b9545ea0c3 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -178,7 +178,8 @@ class PostAlerternotified += notify_pm_users(post, reply_to_user, quoted_users, notified)elsif notify_about_reply?(post)# posts- notified += notify_post_users(post, notified, new_record: new_record)+ notified += notify_post_users(post, notified, new_record: new_record, include_category_watchers: false, include_tag_watchers: false)+ notified += notify_post_users(post, notified, new_record: new_record, include_topic_watchers: false, notification_type: :watching_category_or_tag)endend@@ -400,6 +401,7 @@ class PostAlerterNotification.types[:replied],Notification.types[:posted],Notification.types[:private_message],+ Notification.types[:watching_category_or_tag],]def create_notification(user, type, post, opts = {})@@ -779,7 +781,7 @@ class PostAlerteremails_to_skip_send.uniqend- def notify_post_users(post, notified, group_ids: nil, include_topic_watchers: true, include_category_watchers: true, include_tag_watchers: true, new_record: false)+ def notify_post_users(post, notified, group_ids: nil, include_topic_watchers: true, include_category_watchers: true, include_tag_watchers: true, new_record: false, notification_type: nil)return [] unless post.topicwarn_if_not_sidekiq@@ -871,10 +873,17 @@ class PostAlerter)each_user_in_batches(notify) do |user|- notification_type = !new_record && already_seen_user_ids.include?(user.id) ? Notification.types[:edited] : Notification.types[:posted]+ calculated_type =+ if !new_record && already_seen_user_ids.include?(user.id)+ Notification.types[:edited]+ elsif notification_type+ Notification.types[notification_type]+ else+ Notification.types[:posted]+ endopts = {}- opts[:display_username] = post.last_editor.username if notification_type == Notification.types[:edited]- create_notification(user, notification_type, post, opts)+ opts[:display_username] = post.last_editor.username if calculated_type == Notification.types[:edited]+ create_notification(user, calculated_type, post, opts)endnotifydiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 5b2362e0bea..e0a97877dc2 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -2507,6 +2507,7 @@ en:bookmark_reminder: "<span>%{username}</span> %{description}"replied: "<span>%{username}</span> %{description}"posted: "<span>%{username}</span> %{description}"+ watching_category_or_tag: "<span>%{username}</span> %{description}"edited: "<span>%{username}</span> %{description}"liked: "<span>%{username}</span> %{description}"liked_2: "<span class='double-user'>%{username}, %{username2}</span> %{description}"@@ -2579,6 +2580,7 @@ en:invited_to_private_message: "invited to private message"invitee_accepted: "invite accepted"posted: "new post"+ watching_category_or_tag: "new post"moved_post: "post moved"linked: "linked"bookmark_reminder: "bookmark reminder"diff --git a/spec/requests/api/schemas/json/site_response.json b/spec/requests/api/schemas/json/site_response.jsonindex 16bc845a5d6..ebe85af1b0a 100644--- a/spec/requests/api/schemas/json/site_response.json+++ b/spec/requests/api/schemas/json/site_response.json@@ -35,6 +35,9 @@"posted": {"type": "integer"},+ "watching_category_or_tag": {+ "type": "integer"+ },"moved_post": {"type": "integer"},@@ -124,6 +127,7 @@"invited_to_private_message","invitee_accepted","posted",+ "watching_category_or_tag","moved_post","linked","granted_badge",diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex 4fb69e2a067..ca484b6efca 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -1395,10 +1395,10 @@ RSpec.describe PostAlerter dowhispered_post = Fabricate(:post, user: Fabricate(:admin), topic: topic, post_type: Post.types[:whisper])expect {PostAlerter.post_created(whispered_post)- }.to add_notification(admin, :posted)+ }.to add_notification(admin, :watching_category_or_tag)expect {PostAlerter.post_created(whispered_post)- }.not_to add_notification(user, :posted)+ }.not_to add_notification(user, :watching_category_or_tag)endit "notifies a staged user about a private post, but only if the user has access" do@@ -1424,8 +1424,8 @@ RSpec.describe PostAlerter doexpect {PostAlerter.post_created(post)- }.to add_notification(staged_member, :posted)- .and not_add_notification(staged_non_member, :posted)+ }.to add_notification(staged_member, :watching_category_or_tag)+ .and not_add_notification(staged_non_member, :watching_category_or_tag)endit "does not update existing unread notification" do@@ -1622,7 +1622,7 @@ RSpec.describe PostAlerter doendcontext "with :watching notification level" do- include_examples "tag user with notification level", :watching, :posted+ include_examples "tag user with notification level", :watching, :watching_category_or_tagendcontext "with :watching_first_post notification level" do@@ -2089,7 +2089,7 @@ RSpec.describe PostAlerter donotification = Notification.lastexpect(notification.user).to eq(user)- expect(notification.notification_type).to eq(Notification.types[:posted])+ expect(notification.notification_type).to eq(Notification.types[:watching_category_or_tag])expect(notification.topic).to eq(post.topic)expect(notification.post_number).to eq(1)end