index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @copyright 2022, the Converse.js contributors
  3. * @license Mozilla Public License (MPLv2)
  4. */
  5. import ChatBox from './model.js';
  6. import MessageMixin from './message.js';
  7. import ModelWithContact from './model-with-contact.js';
  8. import chat_api from './api.js';
  9. import { Collection } from "@converse/skeletor/src/collection";
  10. import { _converse, api, converse } from '../../core.js';
  11. import { autoJoinChats, handleMessageStanza, onClearSession, openChat, registerMessageHandlers } from './utils.js';
  12. converse.plugins.add('converse-chat', {
  13. /* Optional dependencies are other plugins which might be
  14. * overridden or relied upon, and therefore need to be loaded before
  15. * this plugin. They are called "optional" because they might not be
  16. * available, in which case any overrides applicable to them will be
  17. * ignored.
  18. *
  19. * It's possible however to make optional dependencies non-optional.
  20. * If the setting "strict_plugin_dependencies" is set to true,
  21. * an error will be raised if the plugin is not found.
  22. *
  23. * NB: These plugins need to have already been loaded via require.js.
  24. */
  25. dependencies: ['converse-chatboxes', 'converse-disco'],
  26. initialize () {
  27. // Configuration values for this plugin
  28. // ====================================
  29. // Refer to docs/source/configuration.rst for explanations of these
  30. // configuration settings.
  31. api.settings.extend({
  32. 'allow_message_corrections': 'all',
  33. 'allow_message_retraction': 'all',
  34. 'allow_message_styling': true,
  35. 'auto_join_private_chats': [],
  36. 'clear_messages_on_reconnection': false,
  37. 'filter_by_resource': false,
  38. 'prune_messages_above': undefined,
  39. 'pruning_behavior': 'unscrolled',
  40. 'send_chat_markers': ["received", "displayed", "acknowledged"],
  41. 'send_chat_state_notifications': true,
  42. });
  43. _converse.Message = ModelWithContact.extend(MessageMixin);
  44. _converse.Messages = Collection.extend({
  45. model: _converse.Message,
  46. comparator: 'time'
  47. });
  48. Object.assign(_converse, { ChatBox, handleMessageStanza });
  49. Object.assign(api, chat_api);
  50. _converse.router.route('converse/chat?jid=:jid', openChat);
  51. api.listen.on('chatBoxesFetched', autoJoinChats);
  52. api.listen.on('presencesInitialized', registerMessageHandlers);
  53. api.listen.on('clearSession', onClearSession);
  54. }
  55. });