mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 03:06:53 +08:00
FIX: After moving the posts topic timestamp should be updated with newest post
This commit is contained in:
@ -47,7 +47,7 @@ class PostMover
|
|||||||
notify_users_that_posts_have_moved
|
notify_users_that_posts_have_moved
|
||||||
update_statistics
|
update_statistics
|
||||||
update_user_actions
|
update_user_actions
|
||||||
set_last_post_user_id(destination_topic)
|
update_last_post_stats
|
||||||
|
|
||||||
if moving_all_posts
|
if moving_all_posts
|
||||||
@original_topic.update_status('closed', true, @user)
|
@original_topic.update_status('closed', true, @user)
|
||||||
@ -204,9 +204,15 @@ class PostMover
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_last_post_user_id(topic)
|
def update_last_post_stats
|
||||||
user_id = topic.posts.last.user_id rescue nil
|
post = destination_topic.posts.where.not(post_type: Post.types[:whisper]).last
|
||||||
return if user_id.nil?
|
if post && post_ids.include?(post.id)
|
||||||
topic.update_attribute :last_post_user_id, user_id
|
attrs = {}
|
||||||
|
attrs[:last_posted_at] = post.created_at
|
||||||
|
attrs[:last_post_user_id] = post.user_id
|
||||||
|
attrs[:bumped_at] = post.created_at unless post.no_bump
|
||||||
|
attrs[:updated_at] = 'now()'
|
||||||
|
destination_topic.update_columns(attrs)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -192,8 +192,11 @@ describe PostMover do
|
|||||||
new_topic.reload
|
new_topic.reload
|
||||||
expect(new_topic.posts_count).to eq(2)
|
expect(new_topic.posts_count).to eq(2)
|
||||||
expect(new_topic.highest_post_number).to eq(2)
|
expect(new_topic.highest_post_number).to eq(2)
|
||||||
expect(new_topic.last_post_user_id).to eq(new_topic.posts.last.user_id)
|
|
||||||
expect(new_topic.last_posted_at).to be_present
|
last_post = new_topic.posts.last
|
||||||
|
expect(new_topic.last_post_user_id).to eq(last_post.user_id)
|
||||||
|
expect(new_topic.last_posted_at).to eq(last_post.created_at)
|
||||||
|
expect(new_topic.bumped_at).to eq(last_post.created_at)
|
||||||
|
|
||||||
p2.reload
|
p2.reload
|
||||||
expect(p2.sort_order).to eq(1)
|
expect(p2.sort_order).to eq(1)
|
||||||
|
Reference in New Issue
Block a user