mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08: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:
@ -181,9 +181,9 @@ export default Component.extend({
|
||||
|
||||
@action
|
||||
fetchOrCreateChannelForUser(user) {
|
||||
return ajax("/chat/direct_messages/create.json", {
|
||||
return ajax("/chat/api/direct-message-channels.json", {
|
||||
method: "POST",
|
||||
data: { usernames: [user.username] },
|
||||
data: { target_usernames: [user.username] },
|
||||
}).catch(popupAjaxError);
|
||||
},
|
||||
|
||||
|
@ -380,9 +380,9 @@ export default class Chat extends Service {
|
||||
// channel for. The current user will automatically be included in the channel
|
||||
// when it is created.
|
||||
upsertDmChannelForUsernames(usernames) {
|
||||
return ajax("/chat/direct_messages/create.json", {
|
||||
return ajax("/chat/api/direct-message-channels.json", {
|
||||
method: "POST",
|
||||
data: { usernames: usernames.uniq() },
|
||||
data: { target_usernames: usernames.uniq() },
|
||||
})
|
||||
.then((response) => {
|
||||
const channel = this.chatChannelsManager.store(response.channel);
|
||||
|
Reference in New Issue
Block a user