Skip to content

A platform for community discussion. Free, open, simple.

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

Krzysztof Kotlareka0f59a55ccc7
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb
index 1037c3ff00e..0e36834ac88 100644
--- a/app/models/post_mover.rb
+++ b/app/models/post_mover.rb
@@ -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,
diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb
index d198e2d33cd..aebfefe12d0 100644
--- a/spec/models/post_mover_spec.rb
+++ b/spec/models/post_mover_spec.rb
@@ -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