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-channel-toggle-view.js
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

63 lines
1.6 KiB
JavaScript

import Component from "@ember/component";
import { htmlSafe } from "@ember/template";
import { CHANNEL_STATUSES } from "discourse/plugins/chat/discourse/models/chat-channel";
import I18n from "I18n";
import { action, computed } from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { inject as service } from "@ember/service";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default class ChatChannelToggleView extends Component {
@service chat;
@service router;
tagName = "";
channel = null;
onStatusChange = null;
@computed("channel.isClosed")
get buttonLabel() {
if (this.channel.isClosed) {
return "chat.channel_settings.open_channel";
} else {
return "chat.channel_settings.close_channel";
}
}
@computed("channel.isClosed")
get instructions() {
if (this.channel.isClosed) {
return htmlSafe(I18n.t("chat.channel_open.instructions"));
} else {
return htmlSafe(I18n.t("chat.channel_close.instructions"));
}
}
@computed("channel.isClosed")
get modalTitle() {
if (this.channel.isClosed) {
return "chat.channel_open.title";
} else {
return "chat.channel_close.title";
}
}
@action
changeChannelStatus() {
const status = this.channel.isClosed
? CHANNEL_STATUSES.open
: CHANNEL_STATUSES.closed;
return ajax(`/chat/chat_channels/${this.channel.id}/change_status.json`, {
method: "PUT",
data: { status },
})
.then(() => {
this.channel.set("status", status);
})
.catch(popupAjaxError)
.finally(() => {
this.onStatusChange?.(this.channel);
});
}
}