2021-02-11 22:32:55 +01:00
|
|
|
import 'plugins/chatview/heading.js';
|
2021-03-12 09:58:17 +01:00
|
|
|
import 'plugins/chatview/bottom-panel.js';
|
2021-02-11 15:05:04 +01:00
|
|
|
import BaseChatView from 'shared/chat/baseview.js';
|
2023-02-15 14:19:48 +01:00
|
|
|
import tplChat from './templates/chat.js';
|
2020-12-08 12:54:14 +01:00
|
|
|
import { __ } from 'i18n';
|
2021-06-04 13:36:29 +02:00
|
|
|
import { _converse, api } from '@converse/headless/core';
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2020-09-09 14:37:43 +02:00
|
|
|
/**
|
2021-06-04 15:21:39 +02:00
|
|
|
* The view of an open/ongoing chat conversation.
|
2020-09-09 14:37:43 +02:00
|
|
|
* @class
|
|
|
|
* @namespace _converse.ChatBoxView
|
|
|
|
* @memberOf _converse
|
|
|
|
*/
|
2020-12-08 12:54:14 +01:00
|
|
|
export default class ChatView extends BaseChatView {
|
|
|
|
length = 200
|
2020-09-09 14:37:43 +02:00
|
|
|
|
2022-07-14 08:47:39 +02:00
|
|
|
async initialize () {
|
2021-06-04 15:21:39 +02:00
|
|
|
_converse.chatboxviews.add(this.jid, this);
|
|
|
|
this.model = _converse.chatboxes.get(this.jid);
|
2021-02-10 11:44:04 +01:00
|
|
|
this.listenTo(_converse, 'windowStateChanged', this.onWindowStateChanged);
|
2021-01-29 15:27:54 +01:00
|
|
|
this.listenTo(this.model, 'change:hidden', () => !this.model.get('hidden') && this.afterShown());
|
2022-09-16 10:26:21 +02:00
|
|
|
this.listenTo(this.model, 'change:show_help_messages', () => this.requestUpdate());
|
2020-09-09 14:37:43 +02:00
|
|
|
|
2020-10-28 13:02:12 +01:00
|
|
|
await this.model.messages.fetched;
|
2021-01-28 22:50:53 +01:00
|
|
|
!this.model.get('hidden') && this.afterShown()
|
2020-09-09 14:37:43 +02:00
|
|
|
/**
|
|
|
|
* Triggered once the {@link _converse.ChatBoxView} has been initialized
|
|
|
|
* @event _converse#chatBoxViewInitialized
|
2022-05-08 20:05:30 +02:00
|
|
|
* @type { _converse.ChatBoxView }
|
2020-09-09 14:37:43 +02:00
|
|
|
* @example _converse.api.listen.on('chatBoxViewInitialized', view => { ... });
|
|
|
|
*/
|
|
|
|
api.trigger('chatBoxViewInitialized', this);
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-09-09 14:37:43 +02:00
|
|
|
|
2021-06-04 15:21:39 +02:00
|
|
|
render () {
|
2023-02-15 14:19:48 +01:00
|
|
|
return tplChat(Object.assign({
|
2021-06-04 13:36:29 +02:00
|
|
|
'model': this.model,
|
|
|
|
'help_messages': this.getHelpMessages(),
|
|
|
|
'show_help_messages': this.model.get('show_help_messages'),
|
|
|
|
}, this.model.toJSON()));
|
2021-03-10 12:17:23 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
getHelpMessages () { // eslint-disable-line class-methods-use-this
|
2020-09-09 14:37:43 +02:00
|
|
|
return [
|
|
|
|
`<strong>/clear</strong>: ${__('Remove messages')}`,
|
|
|
|
`<strong>/close</strong>: ${__('Close this chat')}`,
|
|
|
|
`<strong>/me</strong>: ${__('Write in the third person')}`,
|
|
|
|
`<strong>/help</strong>: ${__('Show this menu')}`
|
|
|
|
];
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-09-09 14:37:43 +02:00
|
|
|
|
|
|
|
afterShown () {
|
|
|
|
this.model.setChatState(_converse.ACTIVE);
|
2021-06-23 17:07:18 +02:00
|
|
|
this.model.clearUnreadMsgCounter();
|
2020-09-09 14:37:43 +02:00
|
|
|
this.maybeFocus();
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
|
|
|
}
|
2020-09-09 14:37:43 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
api.elements.define('converse-chat', ChatView);
|