mirror of
https://github.com/discourse/discourse.git
synced 2026-08-19 01:14:56 -05:00
DEV: Refactor DM channel creation into new service pattern (#22144)
This will be used when we move the channel creation for DMs to happen when we first send a message in a DM channel to avoid a double-request. For now we can just have a new API endpoint for creating this that the existing frontend code can use, that uses the new service pattern. This also uses the new policy pattern for services where the policy can be defined in a class so a more dynamic reason for the policy failing can be sent to the controller. Co-authored-by: Loïc Guitaut <loic@discourse.org>
This commit is contained in:
co-authored by
Loïc Guitaut
parent
7de3cb9b02
commit
3f1024de76
@@ -15,8 +15,15 @@ describe Jobs::Chat::NotifyMentioned do
|
||||
user_2.reload
|
||||
|
||||
@chat_group = Fabricate(:group, users: [user_1, user_2])
|
||||
@personal_chat_channel =
|
||||
Chat::DirectMessageChannelCreator.create!(acting_user: user_1, target_users: [user_1, user_2])
|
||||
result =
|
||||
Chat::CreateDirectMessageChannel.call(
|
||||
guardian: user_1.guardian,
|
||||
target_usernames: [user_1.username, user_2.username],
|
||||
)
|
||||
|
||||
service_failed!(result) if result.failure?
|
||||
|
||||
@personal_chat_channel = result.channel
|
||||
|
||||
[user_1, user_2].each do |u|
|
||||
Fabricate(:user_chat_channel_membership, chat_channel: public_channel, user: u)
|
||||
|
||||
Reference in New Issue
Block a user