2021-02-11 22:32:55 +01:00
|
|
|
import UserDetailsModal from 'modals/user-details.js';
|
2021-03-24 10:43:42 +01:00
|
|
|
import tpl_chatbox_head from './templates/chat-head.js';
|
2021-06-15 10:53:53 +02:00
|
|
|
import { CustomElement } from 'shared/components/element.js';
|
2021-02-11 22:32:55 +01:00
|
|
|
import { __ } from 'i18n';
|
|
|
|
import { _converse, api } from "@converse/headless/core";
|
|
|
|
|
2021-07-27 12:01:12 +02:00
|
|
|
import './styles/chat-head.scss';
|
2021-04-29 15:18:17 +02:00
|
|
|
|
2021-02-11 22:32:55 +01:00
|
|
|
|
2021-06-15 10:53:53 +02:00
|
|
|
export default class ChatHeading extends CustomElement {
|
2021-06-15 10:33:33 +02:00
|
|
|
|
2021-06-15 10:53:53 +02:00
|
|
|
initialize () {
|
2021-02-11 22:32:55 +01:00
|
|
|
this.model = _converse.chatboxes.get(this.getAttribute('jid'));
|
2021-06-15 10:53:53 +02:00
|
|
|
this.listenTo(this.model, 'change:status', this.requestUpdate);
|
2021-11-19 11:04:42 +01:00
|
|
|
this.listenTo(this.model, 'vcard:add', this.requestUpdate);
|
2021-06-15 10:53:53 +02:00
|
|
|
this.listenTo(this.model, 'vcard:change', this.requestUpdate);
|
2021-02-11 22:32:55 +01:00
|
|
|
if (this.model.contact) {
|
2021-06-15 10:53:53 +02:00
|
|
|
this.listenTo(this.model.contact, 'destroy', this.requestUpdate);
|
2021-02-11 22:32:55 +01:00
|
|
|
}
|
|
|
|
this.model.rosterContactAdded?.then(() => {
|
2021-06-15 10:53:53 +02:00
|
|
|
this.listenTo(this.model.contact, 'change:nickname', this.requestUpdate);
|
|
|
|
this.requestUpdate();
|
2021-02-11 22:32:55 +01:00
|
|
|
});
|
2021-06-15 10:53:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return tpl_chatbox_head(Object.assign(this.model.toJSON(), {
|
|
|
|
'heading_buttons_promise': this.getHeadingButtons(),
|
|
|
|
'model': this.model,
|
|
|
|
'showUserDetailsModal': ev => this.showUserDetailsModal(ev),
|
|
|
|
}));
|
2021-02-11 22:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
showUserDetailsModal (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
api.modal.show(UserDetailsModal, { model: this.model }, ev);
|
|
|
|
}
|
|
|
|
|
2021-06-15 09:26:06 +02:00
|
|
|
close (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
this.model.close();
|
2021-02-11 22:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of objects which represent buttons for the chat's header.
|
|
|
|
* @async
|
|
|
|
* @emits _converse#getHeadingButtons
|
|
|
|
*/
|
|
|
|
getHeadingButtons () {
|
|
|
|
const buttons = [
|
2022-04-25 09:58:27 +02:00
|
|
|
/**
|
|
|
|
* @typedef { Object } HeadingButtonAttributes
|
|
|
|
* An object representing a chat heading button
|
|
|
|
* @property { Boolean } standalone
|
|
|
|
* True if shown on its own, false if it must be in the dropdown menu.
|
|
|
|
* @property { Function } handler
|
|
|
|
* A handler function to be called when the button is clicked.
|
|
|
|
* @property { String } a_class - HTML classes to show on the button
|
|
|
|
* @property { String } i18n_text - The user-visiible name of the button
|
|
|
|
* @property { String } i18n_title - The tooltip text for this button
|
|
|
|
* @property { String } icon_class - What kind of CSS class to use for the icon
|
|
|
|
* @property { String } name - The internal name of the button
|
|
|
|
*/
|
2021-02-11 22:32:55 +01:00
|
|
|
{
|
|
|
|
'a_class': 'show-user-details-modal',
|
|
|
|
'handler': ev => this.showUserDetailsModal(ev),
|
|
|
|
'i18n_text': __('Details'),
|
|
|
|
'i18n_title': __('See more information about this person'),
|
|
|
|
'icon_class': 'fa-id-card',
|
|
|
|
'name': 'details',
|
|
|
|
'standalone': api.settings.get('view_mode') === 'overlayed'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
if (!api.settings.get('singleton')) {
|
|
|
|
buttons.push({
|
|
|
|
'a_class': 'close-chatbox-button',
|
|
|
|
'handler': ev => this.close(ev),
|
|
|
|
'i18n_text': __('Close'),
|
|
|
|
'i18n_title': __('Close and end this conversation'),
|
|
|
|
'icon_class': 'fa-times',
|
|
|
|
'name': 'close',
|
|
|
|
'standalone': api.settings.get('view_mode') === 'overlayed'
|
|
|
|
});
|
|
|
|
}
|
2022-04-25 09:58:27 +02:00
|
|
|
const el = _converse.chatboxviews.get(this.getAttribute('jid'));
|
|
|
|
if (el) {
|
|
|
|
/**
|
|
|
|
* *Hook* which allows plugins to add more buttons to a chat's heading.
|
|
|
|
*
|
|
|
|
* Note: This hook is fired for both 1 on 1 chats and groupchats.
|
|
|
|
* If you only care about one, you need to add a check in your code.
|
|
|
|
*
|
|
|
|
* @event _converse#getHeadingButtons
|
|
|
|
* @param { HTMLElement } el
|
|
|
|
* The `converse-chat` (or `converse-muc`) DOM element that represents the chat
|
|
|
|
* @param { Array.<HeadingButtonAttributes> }
|
|
|
|
* An array of the existing buttons. New buttons may be added,
|
|
|
|
* and existing ones removed or modified.
|
|
|
|
* @example
|
|
|
|
* api.listen.on('getHeadingButtons', (el, buttons) => {
|
|
|
|
* buttons.push({
|
|
|
|
* 'i18n_title': __('Foo'),
|
|
|
|
* 'i18n_text': __('Foo Bar'),
|
|
|
|
* 'handler': ev => alert('Foo!'),
|
|
|
|
* 'a_class': 'toggle-foo',
|
|
|
|
* 'icon_class': 'fa-foo',
|
|
|
|
* 'name': 'foo'
|
|
|
|
* });
|
|
|
|
* return buttons;
|
|
|
|
* });
|
|
|
|
*/
|
|
|
|
return _converse.api.hook('getHeadingButtons', el, buttons);
|
2021-02-11 22:32:55 +01:00
|
|
|
} else {
|
|
|
|
return buttons; // Happens during tests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
api.elements.define('converse-chat-heading', ChatHeading);
|