FIX: when tag or category is added notify users that topic was modified (#8750)
There is a feature, that when tag or category is added to the topic, customers who are watching that category or tag are notified. The problem is that it is using default notification type "new post" It would be better to use "new post" only when there really is a new post and "edited" when categories or tags were modified.
This commit is contained in:
parent
79f5d24571
commit
0420be88a6
|
@ -7,7 +7,7 @@ module Jobs
|
|||
|
||||
if post&.topic&.visible?
|
||||
post_alerter = PostAlerter.new
|
||||
post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]), include_tag_watchers: false)
|
||||
post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]), include_tag_watchers: false, new_record: false)
|
||||
post_alerter.notify_first_post_watchers(post, post_alerter.category_watchers(post.topic))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Jobs
|
|||
|
||||
if post&.topic&.visible?
|
||||
post_alerter = PostAlerter.new
|
||||
post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]), include_category_watchers: false)
|
||||
post_alerter.notify_post_users(post, User.where(id: args[:notified_user_ids]), include_category_watchers: false, new_record: false)
|
||||
post_alerter.notify_first_post_watchers(post, post_alerter.tag_watchers(post.topic))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -550,7 +550,7 @@ class PostAlerter
|
|||
end
|
||||
end
|
||||
|
||||
def notify_post_users(post, notified, include_category_watchers: true, include_tag_watchers: true)
|
||||
def notify_post_users(post, notified, include_category_watchers: true, include_tag_watchers: true, new_record: true)
|
||||
return unless post.topic
|
||||
|
||||
warn_if_not_sidekiq
|
||||
|
@ -607,9 +607,12 @@ class PostAlerter
|
|||
notify = notify.where("id NOT IN (?)", exclude_user_ids) if exclude_user_ids.present?
|
||||
|
||||
DiscourseEvent.trigger(:before_create_notifications_for_users, notify, post)
|
||||
|
||||
notification_type = new_record ? Notification.types[:posted] : Notification.types[:edited]
|
||||
|
||||
notify.pluck(:id).each do |user_id|
|
||||
user = User.find_by(id: user_id)
|
||||
create_notification(user, Notification.types[:posted], post)
|
||||
create_notification(user, notification_type, post)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ describe ::Jobs::NotifyTagChange do
|
|||
notification = Notification.last
|
||||
expect(notification.user_id).to eq(user.id)
|
||||
expect(notification.topic_id).to eq(post.topic_id)
|
||||
expect(notification.notification_type).to eq(Notification.types[:edited])
|
||||
end
|
||||
|
||||
it 'doesnt create notification for user watching category' do
|
||||
|
|
|
@ -1404,7 +1404,7 @@ describe Topic do
|
|||
user_id: user.id,
|
||||
topic_id: topic.id,
|
||||
post_number: 1,
|
||||
notification_type: Notification.types[:posted]
|
||||
notification_type: Notification.types[:edited]
|
||||
).exists?).to eq(true)
|
||||
|
||||
expect(Notification.where(
|
||||
|
|
Loading…
Reference in New Issue