FIX: correct notification when tag or category is added (#8801)

Regression was created here:
https://github.com/discourse/discourse/pull/8750

When tag or category is added and the user is watching that category/tag
we changed notification type to `edited` instead of `new post`.

However, the logic here should be a little bit more sophisticated.

If the user has already seen the post, notification should be `edited`.

However, when user hasn't yet seen post, notification should be "new
reply". The case for that is when for example topic is under private
category and set for publishing later. In that case, we modify an
existing topic, however, for a user, it is like a new post.

Discussion on meta:
https://meta.discourse.org/t/publication-of-timed-topics-dont-trigger-new-topic-notifications/139335/13
This commit is contained in:
Krzysztof Kotlarek
2020-01-29 11:03:47 +11:00
committed by GitHub
parent 9621af2214
commit 20e7fb1c95
5 changed files with 27 additions and 5 deletions

View File

@ -1400,6 +1400,27 @@ describe Topic do
topic.change_category_to_id(new_category.id)
end.to change { Notification.count }.by(2)
expect(Notification.where(
user_id: user.id,
topic_id: topic.id,
post_number: 1,
notification_type: Notification.types[:posted]
).exists?).to eq(true)
expect(Notification.where(
user_id: another_user.id,
topic_id: topic.id,
post_number: 1,
notification_type: Notification.types[:watching_first_post]
).exists?).to eq(true)
end
it 'should generate the modified notification for the topic if already seen' do
TopicUser.create!(topic_id: topic.id, highest_seen_post_number: topic.posts.first.post_number, user_id: user.id)
expect do
topic.change_category_to_id(new_category.id)
end.to change { Notification.count }.by(2)
expect(Notification.where(
user_id: user.id,
topic_id: topic.id,