mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
PERF: sends publish_new_channel only when not followed (#21755)
This commit is contained in:
@ -125,13 +125,14 @@ module Chat
|
|||||||
user_ids_allowing_communication =
|
user_ids_allowing_communication =
|
||||||
UserCommScreener.new(
|
UserCommScreener.new(
|
||||||
acting_user: current_user,
|
acting_user: current_user,
|
||||||
target_user_ids: @chat_channel.user_chat_channel_memberships.pluck(:user_id),
|
target_user_ids:
|
||||||
|
@chat_channel.user_chat_channel_memberships.where(following: false).pluck(:user_id),
|
||||||
).allowing_actor_communication
|
).allowing_actor_communication
|
||||||
|
|
||||||
if user_ids_allowing_communication.any?
|
if user_ids_allowing_communication.any?
|
||||||
Chat::Publisher.publish_new_channel(
|
Chat::Publisher.publish_new_channel(
|
||||||
@chat_channel,
|
@chat_channel,
|
||||||
@chat_channel.chatable.users.where(id: user_ids_allowing_communication),
|
User.where(id: user_ids_allowing_communication),
|
||||||
)
|
)
|
||||||
|
|
||||||
@chat_channel
|
@chat_channel
|
||||||
|
@ -514,6 +514,14 @@ RSpec.describe Chat::ChatController do
|
|||||||
expect(Chat::UserChatChannelMembership.find_by(user_id: user2.id).following).to be true
|
expect(Chat::UserChatChannelMembership.find_by(user_id: user2.id).following).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "doesn’t call publish new channel when already following" do
|
||||||
|
Chat::Publisher.expects(:publish_new_channel).never
|
||||||
|
|
||||||
|
sign_in(user1)
|
||||||
|
|
||||||
|
post "/chat/#{direct_message_channel.id}.json", params: { message: message }
|
||||||
|
end
|
||||||
|
|
||||||
it "errors when the user is not part of the direct message channel" do
|
it "errors when the user is not part of the direct message channel" do
|
||||||
Chat::DirectMessageUser.find_by(user: user1, direct_message: chatable).destroy!
|
Chat::DirectMessageUser.find_by(user: user1, direct_message: chatable).destroy!
|
||||||
sign_in(user1)
|
sign_in(user1)
|
||||||
|
@ -6,7 +6,7 @@ RSpec.describe "Unfollow dm channel", type: :system, js: true do
|
|||||||
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, other_user]) }
|
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user, other_user]) }
|
||||||
|
|
||||||
let!(:chat_page) { PageObjects::Pages::Chat.new }
|
let!(:chat_page) { PageObjects::Pages::Chat.new }
|
||||||
let!(:chat_channel_page) { PageObjects::Pages::ChatChannel.new }
|
let!(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
SiteSetting.navigation_menu = "sidebar"
|
SiteSetting.navigation_menu = "sidebar"
|
||||||
@ -26,8 +26,8 @@ RSpec.describe "Unfollow dm channel", type: :system, js: true do
|
|||||||
text = "this is fine"
|
text = "this is fine"
|
||||||
sign_in(other_user)
|
sign_in(other_user)
|
||||||
chat_page.visit_channel(dm_channel_1)
|
chat_page.visit_channel(dm_channel_1)
|
||||||
chat_channel_page.send_message(text)
|
channel_page.send_message(text)
|
||||||
expect(chat_channel_page).to have_message(text: text)
|
expect(channel_page).to have_message(text: text)
|
||||||
session.quit
|
session.quit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user