Converse converse.js

Source: plugins/chatview/chat.js

  1. import 'plugins/chatview/heading.js';
  2. import 'plugins/chatview/bottom-panel.js';
  3. import BaseChatView from 'shared/chat/baseview.js';
  4. import tplChat from './templates/chat.js';
  5. import { __ } from 'i18n';
  6. import { _converse, api } from '@converse/headless/core';
  7. /**
  8. * The view of an open/ongoing chat conversation.
  9. * @class
  10. * @namespace _converse.ChatBoxView
  11. * @memberOf _converse
  12. */
  13. export default class ChatView extends BaseChatView {
  14. length = 200
  15. async initialize () {
  16. _converse.chatboxviews.add(this.jid, this);
  17. this.model = _converse.chatboxes.get(this.jid);
  18. this.listenTo(_converse, 'windowStateChanged', this.onWindowStateChanged);
  19. this.listenTo(this.model, 'change:hidden', () => !this.model.get('hidden') && this.afterShown());
  20. this.listenTo(this.model, 'change:show_help_messages', () => this.requestUpdate());
  21. await this.model.messages.fetched;
  22. !this.model.get('hidden') && this.afterShown()
  23. /**
  24. * Triggered once the {@link _converse.ChatBoxView} has been initialized
  25. * @event _converse#chatBoxViewInitialized
  26. * @type { _converse.ChatBoxView }
  27. * @example _converse.api.listen.on('chatBoxViewInitialized', view => { ... });
  28. */
  29. api.trigger('chatBoxViewInitialized', this);
  30. }
  31. render () {
  32. return tplChat(Object.assign({
  33. 'model': this.model,
  34. 'help_messages': this.getHelpMessages(),
  35. 'show_help_messages': this.model.get('show_help_messages'),
  36. }, this.model.toJSON()));
  37. }
  38. getHelpMessages () { // eslint-disable-line class-methods-use-this
  39. return [
  40. `<strong>/clear</strong>: ${__('Remove messages')}`,
  41. `<strong>/close</strong>: ${__('Close this chat')}`,
  42. `<strong>/me</strong>: ${__('Write in the third person')}`,
  43. `<strong>/help</strong>: ${__('Show this menu')}`
  44. ];
  45. }
  46. afterShown () {
  47. this.model.setChatState(_converse.ACTIVE);
  48. this.model.clearUnreadMsgCounter();
  49. this.maybeFocus();
  50. }
  51. }
  52. api.elements.define('converse-chat', ChatView);