FIX: when a post is moved copy notifications level (#9311)

This is a revert of 2c011252f1

More information on meta: https://meta.discourse.org/t/when-a-reply-is-moved-to-a-new-topic-the-followers-of-the-previous-topic-are-automatically-follower-of-the-new-topic-as-well/130025
This commit is contained in:
Krzysztof Kotlarek 2020-03-31 16:19:47 +11:00 committed by GitHub
parent 6d3d9ecf6c
commit a0f59a55cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -332,8 +332,7 @@ class PostMover
old_topic_id: original_topic.id,
new_topic_id: destination_topic.id,
old_highest_post_number: destination_topic.highest_post_number,
old_highest_staff_post_number: destination_topic.highest_staff_post_number,
default_notification_level: NotificationLevels.topic_levels[:regular]
old_highest_staff_post_number: destination_topic.highest_staff_post_number
}
DB.exec(<<~SQL, params)
@ -342,9 +341,13 @@ class PostMover
notifications_changed_at, notifications_reason_id)
SELECT tu.user_id,
:new_topic_id AS topic_id,
CASE
WHEN p.user_id IS NULL THEN FALSE
ELSE TRUE END AS posted,
EXISTS(
SELECT 1
FROM posts p
WHERE p.topic_id = :new_topic_id
AND p.user_id = tu.user_id
LIMIT 1
) AS posted,
(
SELECT MAX(lr.new_post_number)
FROM moved_posts lr
@ -365,19 +368,11 @@ class PostMover
) AS last_emailed_post_number,
GREATEST(tu.first_visited_at, t.created_at) AS first_visited_at,
GREATEST(tu.last_visited_at, t.created_at) AS last_visited_at,
CASE
WHEN p.user_id IS NOT NULL THEN tu.notification_level
ELSE :default_notification_level END AS notification_level,
tu.notification_level,
tu.notifications_changed_at,
tu.notifications_reason_id
FROM topic_users tu
JOIN topics t ON (t.id = :new_topic_id)
LEFT OUTER JOIN
(
SELECT DISTINCT user_id
FROM posts
WHERE topic_id = :new_topic_id
) p ON (p.user_id = tu.user_id)
WHERE tu.topic_id = :old_topic_id
AND GREATEST(
tu.last_read_post_number,

View File

@ -470,7 +470,7 @@ describe PostMover do
last_read_post_number: 2,
highest_seen_post_number: 2,
last_emailed_post_number: 2,
notification_level: TopicUser.notification_levels[:regular],
notification_level: TopicUser.notification_levels[:tracking],
posted: false
)
expect(TopicUser.find_by(topic: new_topic, user: user2))
@ -486,7 +486,7 @@ describe PostMover do
last_read_post_number: 1,
highest_seen_post_number: 2,
last_emailed_post_number: 2,
notification_level: TopicUser.notification_levels[:regular],
notification_level: TopicUser.notification_levels[:watching],
posted: false
)
end