mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 00:00:46 +08:00
DEV: allows a context when creating a message (#25647)
The service `Chat::CreateMessage` will now accept `context_post_ids` and `context_topic_id` as params. These values represent the topic which might be visible when sending a message (for now, this is only possible when using the drawer). The `DiscourseEvent` `chat_message_created` will now have the following signature: ```ruby on(:chat_message_created) do | message, channel, user, meta| p meta[:context][:post_ids] end ```
This commit is contained in:
@ -151,4 +151,56 @@ RSpec.describe "Drawer", type: :system do
|
||||
expect(drawer_page).to have_open_channel(channel)
|
||||
end
|
||||
end
|
||||
|
||||
context "when sending a message from topic" do
|
||||
fab!(:topic)
|
||||
fab!(:posts) { Fabricate.times(5, :post, topic: topic) }
|
||||
fab!(:channel) { Fabricate(:chat_channel) }
|
||||
fab!(:membership) do
|
||||
Fabricate(:user_chat_channel_membership, user: current_user, chat_channel: channel)
|
||||
end
|
||||
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
|
||||
context "when on a channel" do
|
||||
it "has context" do
|
||||
::Chat::CreateMessage
|
||||
.expects(:call)
|
||||
.with do |value|
|
||||
value["topic_id"] === topic.id.to_s &&
|
||||
value["post_ids"] === [posts[1].id.to_s, posts[2].id.to_s, posts[3].id.to_s]
|
||||
end
|
||||
|
||||
topic_page.visit_topic(topic, post_number: 3)
|
||||
chat_page.open_from_header
|
||||
drawer_page.open_channel(channel)
|
||||
channel_page.send_message
|
||||
end
|
||||
end
|
||||
|
||||
context "when on a thread" do
|
||||
before { channel.update!(threading_enabled: true) }
|
||||
|
||||
fab!(:thread_1) { Fabricate(:chat_thread, channel: channel) }
|
||||
|
||||
let(:thread_list_page) { PageObjects::Components::Chat::ThreadList.new }
|
||||
let(:thread_page) { PageObjects::Pages::ChatThread.new }
|
||||
|
||||
it "has context" do
|
||||
::Chat::CreateMessage
|
||||
.expects(:call)
|
||||
.with do |value|
|
||||
value["topic_id"] === topic.id.to_s &&
|
||||
value["post_ids"] === [posts[1].id.to_s, posts[2].id.to_s, posts[3].id.to_s]
|
||||
end
|
||||
|
||||
topic_page.visit_topic(topic, post_number: 3)
|
||||
chat_page.open_from_header
|
||||
drawer_page.open_channel(channel)
|
||||
drawer_page.open_thread_list
|
||||
thread_list_page.open_thread(thread_1)
|
||||
thread_page.send_message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user