2022-08-21 13:03:32 +02:00
|
|
|
import BaseModal from "plugins/modal/modal.js";
|
2023-02-15 14:19:48 +01:00
|
|
|
import tplOccupantModal from "./templates/occupant.js";
|
2020-12-03 13:40:30 +01:00
|
|
|
import { _converse, api } from "@converse/headless/core";
|
2022-10-29 20:39:58 +02:00
|
|
|
import { Model } from '@converse/skeletor/src/model.js';
|
2021-11-19 10:49:22 +01:00
|
|
|
|
2022-08-21 13:03:32 +02:00
|
|
|
export default class OccupantModal extends BaseModal {
|
2020-12-01 16:31:57 +01:00
|
|
|
|
|
|
|
initialize () {
|
2022-08-21 13:03:32 +02:00
|
|
|
super.initialize()
|
|
|
|
const model = this.model ?? this.message;
|
|
|
|
this.listenTo(model, 'change', () => this.render());
|
2020-12-01 16:31:57 +01:00
|
|
|
/**
|
2020-12-01 18:50:35 +01:00
|
|
|
* Triggered once the OccupantModal has been initialized
|
2021-11-19 10:49:22 +01:00
|
|
|
* @event _converse#occupantModalInitialized
|
|
|
|
* @type { Object }
|
|
|
|
* @example _converse.api.listen.on('occupantModalInitialized', data);
|
2020-12-01 18:50:35 +01:00
|
|
|
*/
|
2021-11-19 10:49:22 +01:00
|
|
|
api.trigger('occupantModalInitialized', { 'model': this.model, 'message': this.message });
|
2022-08-21 13:03:32 +02:00
|
|
|
}
|
2020-12-01 16:31:57 +01:00
|
|
|
|
2022-04-26 20:10:14 +02:00
|
|
|
getVcard () {
|
|
|
|
const model = this.model ?? this.message;
|
|
|
|
if (model.vcard) {
|
|
|
|
return model.vcard;
|
|
|
|
}
|
|
|
|
const jid = model?.get('jid') || model?.get('from');
|
|
|
|
return jid ? _converse.vcards.get(jid) : null;
|
2022-08-21 13:03:32 +02:00
|
|
|
}
|
2022-04-26 20:10:14 +02:00
|
|
|
|
2022-08-21 13:03:32 +02:00
|
|
|
renderModal () {
|
2023-02-15 14:19:48 +01:00
|
|
|
return tplOccupantModal(this);
|
2020-12-01 16:31:57 +01:00
|
|
|
}
|
|
|
|
|
2022-11-03 09:55:20 +01:00
|
|
|
getModalTitle () {
|
2022-08-21 13:03:32 +02:00
|
|
|
const model = this.model ?? this.message;
|
|
|
|
return model?.getDisplayName();
|
|
|
|
}
|
2022-10-29 20:39:58 +02:00
|
|
|
|
|
|
|
addToContacts () {
|
|
|
|
const model = this.model ?? this.message;
|
|
|
|
const jid = model.get('jid');
|
2023-02-17 12:14:48 +01:00
|
|
|
if (jid) api.modal.show('converse-add-contact-modal', {'model': new Model({ jid })});
|
2022-10-29 20:39:58 +02:00
|
|
|
}
|
2022-08-21 13:03:32 +02:00
|
|
|
}
|
2020-12-01 16:31:57 +01:00
|
|
|
|
2022-08-21 13:03:32 +02:00
|
|
|
api.elements.define('converse-muc-occupant-modal', OccupantModal);
|