FIX: Changing the post owner didn't update the `reply_to_user_id` of replies (#13862)

FIX: Changing the post owner didn’t update the reply_to_user_id of replies (#13862)

diff --git a/app/services/post_owner_changer.rb b/app/services/post_owner_changer.rb
index 785c2cf..7b6929c 100644
--- a/app/services/post_owner_changer.rb
+++ b/app/services/post_owner_changer.rb
@@ -38,6 +38,9 @@ class PostOwnerChanger
         first_post_created_at: @new_owner.reload.posts.order('created_at ASC').first&.created_at
       )
 
+      Post.where(topic_id: @topic.id, reply_to_post_number: post.post_number)
+        .update_all(reply_to_user_id: @new_owner.id)
+
       @topic.save!(validate: false)
     end
   end
diff --git a/spec/services/post_owner_changer_spec.rb b/spec/services/post_owner_changer_spec.rb
index a6c4d3a..1b34f9b 100644
--- a/spec/services/post_owner_changer_spec.rb
+++ b/spec/services/post_owner_changer_spec.rb
@@ -235,6 +235,17 @@ describe PostOwnerChanger do
         expect(stats[1].action_type).to eq(UserAction::REPLY)
         expect(stats[1].count).to eq(1)
       end
+
+      it "updates reply_to_user_id" do
+        p4 = Fabricate(:post, topic: topic, reply_to_post_number: p1.post_number, reply_to_user_id: p1.user_id)
+        p5 = Fabricate(:post, topic: topic, reply_to_post_number: p2.post_number, reply_to_user_id: p2.user_id)
+
+        PostOwnerChanger.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner!
+        p4.reload; p5.reload
+
+        expect(p4.reply_to_user_id).to eq(user_a.id)
+        expect(p5.reply_to_user_id).to eq(p2.user_id)
+      end
     end
   end
 end

GitHub sha: 4a37612fd5a0432a33307332cf1c0b369ca80981

This commit appears in #13862 which was approved by eviltrout. It was merged by gschlager.