Converse converse.js

Source: headless/plugins/chatboxes/index.js

  1. /**
  2. * @copyright 2022, the Converse.js contributors
  3. * @license Mozilla Public License (MPLv2)
  4. */
  5. import "../emoji/index.js";
  6. import ChatBoxes from './chatboxes.js';
  7. import chatboxes_api from './api.js';
  8. import { _converse, api, converse } from "../../core.js";
  9. const { Strophe } = converse.env;
  10. converse.plugins.add('converse-chatboxes', {
  11. dependencies: ["converse-emoji", "converse-roster", "converse-vcard"],
  12. initialize () {
  13. api.promises.add([
  14. 'chatBoxesFetched',
  15. 'chatBoxesInitialized',
  16. 'privateChatsAutoJoined'
  17. ]);
  18. Object.assign(api, { 'chatboxes': chatboxes_api});
  19. _converse.ChatBoxes = ChatBoxes;
  20. api.listen.on('addClientFeatures', () => {
  21. api.disco.own.features.add(Strophe.NS.MESSAGE_CORRECT);
  22. api.disco.own.features.add(Strophe.NS.HTTPUPLOAD);
  23. api.disco.own.features.add(Strophe.NS.OUTOFBAND);
  24. });
  25. api.listen.on('pluginsInitialized', () => {
  26. _converse.chatboxes = new _converse.ChatBoxes();
  27. /**
  28. * Triggered once the _converse.ChatBoxes collection has been initialized.
  29. * @event _converse#chatBoxesInitialized
  30. * @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
  31. * @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
  32. */
  33. api.trigger('chatBoxesInitialized');
  34. });
  35. api.listen.on('presencesInitialized', (reconnecting) => _converse.chatboxes.onConnected(reconnecting));
  36. api.listen.on('reconnected', () => _converse.chatboxes.forEach(m => m.onReconnection()));
  37. }
  38. });