A platform for community discussion. Free, open, simple.
FIX: correctly pass topic/posts context (#26882)
Joffrey JAFFEUX00d88766b263
diff --git a/plugins/chat/assets/javascripts/discourse/lib/extract-current-topic-info.js b/plugins/chat/assets/javascripts/discourse/lib/extract-current-topic-info.jsindex 92c9e75350e..f8b57e5c27e 100644--- a/plugins/chat/assets/javascripts/discourse/lib/extract-current-topic-info.js+++ b/plugins/chat/assets/javascripts/discourse/lib/extract-current-topic-info.js@@ -7,7 +7,7 @@ export function extractCurrentTopicInfo(context) {return;}- const info = { topic_id: topic.id };+ const info = { context_topic_id: topic.id };const currentPostNumber = parseInt(topic.current_post_number, 10);const posts = topic.postStream.posts;@@ -23,7 +23,11 @@ export function extractCurrentTopicInfo(context) {!post.hidden && !post.deleted_at && post.post_number > currentPostNumber);- info.post_ids = [previousPost?.id, currentPost?.id, nextPost?.id];+ info.context_post_ids = [+ previousPost?.id,+ currentPost?.id,+ nextPost?.id,+ ].filter(Boolean);return info;}diff --git a/plugins/chat/spec/system/send_message_spec.rb b/plugins/chat/spec/system/send_message_spec.rbindex 52064499169..f85c94d28a8 100644--- a/plugins/chat/spec/system/send_message_spec.rb+++ b/plugins/chat/spec/system/send_message_spec.rb@@ -104,4 +104,39 @@ RSpec.describe "Send message", type: :system doendendend++ context "when sending message from drawer" do+ let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }+ let(:topic_page) { PageObjects::Pages::Topic.new }++ fab!(:post_1) { Fabricate(:post) }+ fab!(:post_2) { Fabricate(:post, topic: post_1.topic) }+ fab!(:channel_1) { Fabricate(:chat_channel) }++ before do+ sign_in(user_1)+ channel_1.add(user_1)+ Jobs.run_immediately!+ end++ it "has topic context" do+ tested_context = {}+ blk = Proc.new { |message, channel, user, context| tested_context = context }++ begin+ DiscourseEvent.on(:chat_message_created, &blk)+ topic_page.visit_topic(post_1.topic)+ chat_page.open_from_header+ drawer_page.open_channel(channel_1)+ channel_page.send_message++ try_until_success do+ expect(tested_context.dig(:context, :post_ids)).to eq([post_1.id, post_2.id])+ expect(tested_context.dig(:context, :topic_id)).to eq(post_1.topic_id)+ end+ ensure+ DiscourseEvent.off(:chat_message_created, &blk)+ end+ end+ endend