UX: update topic small action post to add link for new linked topic URL (#11132)

https://meta.discourse.org/t/linked-topics-splitting-and-managing-megatopics/168992/4?u=techapj
This commit is contained in:
Arpit Jalan 2020-11-05 22:39:21 +05:30 committed by GitHub
parent 707ed01f33
commit 436bd48512
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View File

@ -75,8 +75,12 @@ module Jobs
ON CONFLICT (topic_id, user_id) DO NOTHING
SQL
# add moderator post to old topic
parent_topic.add_moderator_post(system_user, I18n.t('create_linked_topic.moderator_post_raw', new_url: new_topic.url))
# update small action post on old topic to add new topic link
small_action_post = Post.where(topic_id: parent_topic_id, post_type: Post.types[:small_action], action_code: "closed.enabled").last
if small_action_post.present?
small_action_post.raw = "#{small_action_post.raw} #{I18n.t('create_linked_topic.small_action_post_raw', new_title: "[#{new_topic_title}](#{new_topic.url})")}"
small_action_post.save!
end
end
@post_creator.enqueue_jobs if @post_creator
end

View File

@ -4945,4 +4945,4 @@ en:
one: "%{topic_title} (Part %{count})"
other: "%{topic_title} (Part %{count})"
post_raw: "Continuing the discussion from %{parent_url}.\n\nPrevious discussions:\n\n%{previous_topics}"
moderator_post_raw: "Continue discussion here: %{new_url}"
small_action_post_raw: "Continue discussion at %{new_title}."

View File

@ -37,6 +37,7 @@ describe Jobs::CreateLinkedTopic do
end
it 'creates a linked topic' do
small_action_post = Fabricate(:post, topic: topic, post_type: Post.types[:small_action], action_code: "closed.enabled")
Jobs::CreateLinkedTopic.new.execute(post_id: post.id)
raw_title = topic.title
@ -44,7 +45,7 @@ describe Jobs::CreateLinkedTopic do
new_topic = Topic.last
linked_topic = new_topic.linked_topic
expect(topic.title).to include(I18n.t("create_linked_topic.topic_title_with_sequence", topic_title: raw_title, count: 1))
expect(topic.posts.last.raw).to eq(I18n.t('create_linked_topic.moderator_post_raw', new_url: new_topic.url))
expect(topic.posts.last.raw).to include(I18n.t('create_linked_topic.small_action_post_raw', new_title: "[#{new_topic.title}](#{new_topic.url})"))
expect(new_topic.title).to include(I18n.t("create_linked_topic.topic_title_with_sequence", topic_title: raw_title, count: 2))
expect(new_topic.first_post.raw).to include(topic.url)
expect(new_topic.topic_users.count).to eq(3)