2020-12-10 11:08:17 +01:00
|
|
|
import 'shared/autocomplete/index.js';
|
2021-02-24 09:51:37 +01:00
|
|
|
import tpl_muc_sidebar from "./templates/muc-sidebar.js";
|
2021-03-24 11:59:09 +01:00
|
|
|
import { CustomElement } from 'shared/components/element.js';
|
2021-03-11 11:29:26 +01:00
|
|
|
import { _converse, api, converse } from "@converse/headless/core";
|
|
|
|
|
2021-11-19 13:43:14 +01:00
|
|
|
import 'shared/styles/status.scss';
|
2021-04-29 15:18:17 +02:00
|
|
|
import './styles/muc-occupants.scss';
|
|
|
|
|
2021-03-11 11:29:26 +01:00
|
|
|
const { u } = converse.env;
|
2020-10-23 20:49:10 +02:00
|
|
|
|
|
|
|
export default class MUCSidebar extends CustomElement {
|
|
|
|
|
|
|
|
static get properties () {
|
|
|
|
return {
|
2021-03-11 11:29:26 +01:00
|
|
|
jid: { type: String }
|
2020-10-23 20:49:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback () {
|
|
|
|
super.connectedCallback();
|
2021-03-11 11:29:26 +01:00
|
|
|
this.model = _converse.chatboxes.get(this.jid);
|
|
|
|
this.listenTo(this.model.occupants, 'add', this.requestUpdate);
|
|
|
|
this.listenTo(this.model.occupants, 'remove', this.requestUpdate);
|
|
|
|
this.listenTo(this.model.occupants, 'change', this.requestUpdate);
|
2021-11-19 13:43:14 +01:00
|
|
|
this.listenTo(this.model.occupants, 'vcard:change', this.requestUpdate);
|
|
|
|
this.listenTo(this.model.occupants, 'vcard:add', this.requestUpdate);
|
2021-03-11 11:29:26 +01:00
|
|
|
this.model.initialized.then(() => this.requestUpdate());
|
2020-10-23 20:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const tpl = tpl_muc_sidebar(Object.assign(
|
2021-03-11 11:29:26 +01:00
|
|
|
this.model.toJSON(), {
|
|
|
|
'occupants': [...this.model.occupants.models],
|
|
|
|
'closeSidebar': ev => this.closeSidebar(ev),
|
2021-03-17 12:12:16 +01:00
|
|
|
'onOccupantClicked': ev => this.onOccupantClicked(ev),
|
2021-03-11 11:29:26 +01:00
|
|
|
}
|
2020-10-23 20:49:10 +02:00
|
|
|
));
|
|
|
|
return tpl;
|
|
|
|
}
|
2021-03-11 11:29:26 +01:00
|
|
|
|
|
|
|
closeSidebar(ev) {
|
|
|
|
ev?.preventDefault?.();
|
|
|
|
ev?.stopPropagation?.();
|
|
|
|
u.safeSave(this.model, { 'hidden_occupants': true });
|
|
|
|
}
|
|
|
|
|
2021-03-17 12:12:16 +01:00
|
|
|
onOccupantClicked (ev) {
|
|
|
|
ev?.preventDefault?.();
|
2021-09-14 22:27:49 +02:00
|
|
|
const view = _converse.chatboxviews.get(this.getAttribute('jid'));
|
|
|
|
view?.getMessageForm().insertIntoTextArea(`@${ev.target.textContent}`);
|
2021-03-17 12:12:16 +01:00
|
|
|
}
|
2020-10-23 20:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
api.elements.define('converse-muc-sidebar', MUCSidebar);
|