This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/components/chat-draft-channel-screen.js
Joffrey JAFFEUX f12724b5a5
DEV: routable chat part 2 (#20232)
This commit is expanding on previous work making everything chat working through an URL.

Improves drawer templates to be all URLs
Implements some kind of router for the drawer
Removes few remaining actions for opening channels
2023-02-14 11:27:07 +01:00

52 lines
1.3 KiB
JavaScript

import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
import { inject as service } from "@ember/service";
import Component from "@ember/component";
import { action } from "@ember/object";
import { cloneJSON } from "discourse-common/lib/object";
export default class ChatDraftChannelScreen extends Component {
@service chat;
@service router;
tagName = "";
@action
onCancelChatDraft() {
return this.router.transitionTo("chat.index");
}
@action
onChangeSelectedUsers(users) {
this._fetchPreviewedChannel(users);
}
@action
onSwitchFromDraftChannel(channel) {
channel.set("isDraft", false);
}
_fetchPreviewedChannel(users) {
this.set("previewedChannel", null);
return this.chat
.getDmChannelForUsernames(users.mapBy("username"))
.then((response) => {
this.set(
"previewedChannel",
ChatChannel.create(
Object.assign({}, response.channel, { isDraft: true })
)
);
})
.catch((error) => {
if (error?.jqXHR?.status === 404) {
this.set(
"previewedChannel",
ChatChannel.create({
chatable: { users: cloneJSON(users) },
isDraft: true,
})
);
}
});
}
}