Converse converse.js

Source: plugins/chatboxviews/view.js

  1. import tplBackgroundLogo from '../../templates/background_logo.js';
  2. import tplChats from './templates/chats.js';
  3. import { CustomElement } from 'shared/components/element.js';
  4. import { api, _converse } from '@converse/headless/core';
  5. import { getAppSettings } from '@converse/headless/shared/settings/utils.js';
  6. import { render } from 'lit';
  7. class ConverseChats extends CustomElement {
  8. initialize () {
  9. this.model = _converse.chatboxes;
  10. this.listenTo(this.model, 'add', () => this.requestUpdate());
  11. this.listenTo(this.model, 'change:closed', () => this.requestUpdate());
  12. this.listenTo(this.model, 'change:hidden', () => this.requestUpdate());
  13. this.listenTo(this.model, 'change:jid', () => this.requestUpdate());
  14. this.listenTo(this.model, 'change:minimized', () => this.requestUpdate());
  15. this.listenTo(this.model, 'destroy', () => this.requestUpdate());
  16. // Use listenTo instead of api.listen.to so that event handlers
  17. // automatically get deregistered when the component is dismounted
  18. this.listenTo(_converse, 'connected', () => this.requestUpdate());
  19. this.listenTo(_converse, 'reconnected', () => this.requestUpdate());
  20. this.listenTo(_converse, 'disconnected', () => this.requestUpdate());
  21. const settings = getAppSettings();
  22. this.listenTo(settings, 'change:view_mode', () => this.requestUpdate())
  23. this.listenTo(settings, 'change:singleton', () => this.requestUpdate())
  24. const bg = document.getElementById('conversejs-bg');
  25. if (bg && !bg.innerHTML.trim()) {
  26. render(tplBackgroundLogo(), bg);
  27. }
  28. const body = document.querySelector('body');
  29. body.classList.add(`converse-${api.settings.get('view_mode')}`);
  30. /**
  31. * Triggered once the _converse.ChatBoxViews view-colleciton has been initialized
  32. * @event _converse#chatBoxViewsInitialized
  33. * @example _converse.api.listen.on('chatBoxViewsInitialized', () => { ... });
  34. */
  35. api.trigger('chatBoxViewsInitialized');
  36. }
  37. render () { // eslint-disable-line class-methods-use-this
  38. return tplChats();
  39. }
  40. }
  41. api.elements.define('converse-chats', ConverseChats);