Refactor converse-muc-sidebar

- To only take the MUC JID as attribute
- To be responsible for closing itself
This commit is contained in:
JC Brand 2021-03-11 11:29:26 +01:00
parent 349b6d616d
commit 2dbe50fc97
4 changed files with 27 additions and 29 deletions

View File

@ -30,7 +30,6 @@ export default class MUCView extends BaseChatView {
is_chatroom = true
events = {
'click .chatbox-navback': 'showControlBox',
'click .hide-occupants': 'hideOccupants',
'click .new-msgs-indicator': 'viewUnreadMessages',
// Arrow functions don't work here because you can't bind a different `this` param to them.
'click .occupant-nick': function (ev) {
@ -163,20 +162,6 @@ export default class MUCView extends BaseChatView {
return _converse.ChatBoxView.prototype.close.apply(this, arguments);
}
/**
* Hide the right sidebar containing the chat occupants.
* @private
* @method _converse.ChatRoomView#hideOccupants
*/
hideOccupants (ev) {
if (ev) {
ev.preventDefault();
ev.stopPropagation();
}
this.model.save({ 'hidden_occupants': true });
this.scrollDown();
}
getReason (args) { // eslint-disable-line class-methods-use-this
return args.includes(',') ? args.slice(args.indexOf(',') + 1).trim() : null;
}

View File

@ -1,32 +1,45 @@
import 'shared/autocomplete/index.js';
import tpl_muc_sidebar from "./templates/muc-sidebar.js";
import { CustomElement } from 'components/element.js';
import { api } from "@converse/headless/core";
import { _converse, api, converse } from "@converse/headless/core";
const { u } = converse.env;
export default class MUCSidebar extends CustomElement {
static get properties () {
return {
chatroom: { type: Object },
occupants: { type: Object}
jid: { type: String }
}
}
connectedCallback () {
super.connectedCallback();
this.listenTo(this.occupants, 'add', this.requestUpdate);
this.listenTo(this.occupants, 'remove', this.requestUpdate);
this.listenTo(this.occupants, 'change', this.requestUpdate);
this.chatroom.initialized.then(() => this.requestUpdate());
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);
this.model.initialized.then(() => this.requestUpdate());
}
render () {
const tpl = tpl_muc_sidebar(Object.assign(
this.chatroom.toJSON(),
{'occupants': [...this.occupants.models] }
this.model.toJSON(), {
'occupants': [...this.model.occupants.models],
'closeSidebar': ev => this.closeSidebar(ev),
}
));
return tpl;
}
closeSidebar(ev) {
ev?.preventDefault?.();
ev?.stopPropagation?.();
u.safeSave(this.model, { 'hidden_occupants': true });
// FIXME: do this declaratively
_converse.chatboxviews.get(this.jid)?.scrollDown();
}
}
api.elements.define('converse-muc-sidebar', MUCSidebar);

View File

@ -21,9 +21,9 @@ export default (o) => html`
<converse-muc-bottom-panel jid="${o.jid}" class="bottom-panel"></converse-muc-bottom-panel>
</div>
<div class="disconnect-container hidden"></div>
<converse-muc-sidebar class="occupants col-md-3 col-4 ${o.show_sidebar ? '' : 'hidden' }"
<converse-muc-sidebar
class="occupants col-md-3 col-4 ${o.show_sidebar ? '' : 'hidden' }"
style="flex: 0 0 ${o.occupants_width}px"
@mousedown=${o.onMousedown}
.occupants=${o.occupants}
.chatroom=${o.model}></converse-muc-sidebar>
jid=${o.jid}
@mousedown=${o.onMousedown}></converse-muc-sidebar>
`;

View File

@ -27,7 +27,7 @@ export default (o) => {
return html`
<div class="occupants-header">
<i class="hide-occupants fa fa-times"></i>
<i class="hide-occupants fa fa-times" @click=${o.closeSidebar}></i>
<div class="occupants-header--title">
<span class="occupants-heading">${i18n_participants}</span>
</div>