|
@@ -2,6 +2,10 @@ import _converse from '../../shared/_converse.js';
|
|
|
import api from '../../shared/api/index.js';
|
|
|
import { createChatBox } from './utils.js';
|
|
|
|
|
|
+const _chatBoxTypes = {};
|
|
|
+
|
|
|
+/** @typedef {import('@converse/skeletor').Model} Model */
|
|
|
+
|
|
|
/**
|
|
|
* The "chatboxes" namespace.
|
|
|
*
|
|
@@ -10,10 +14,10 @@ import { createChatBox } from './utils.js';
|
|
|
*/
|
|
|
export default {
|
|
|
/**
|
|
|
- * @method api.chats.create
|
|
|
- * @param { String|String[] } jids - A JID or array of JIDs
|
|
|
- * @param { Object } [attrs] An object containing configuration attributes
|
|
|
- * @param { Model } model - The type of chatbox that should be created
|
|
|
+ * @method api.chatboxes.create
|
|
|
+ * @param {string|string[]} jids - A JID or array of JIDs
|
|
|
+ * @param {Object} attrs An object containing configuration attributes
|
|
|
+ * @param {Model} model - The type of chatbox that should be created
|
|
|
*/
|
|
|
async create (jids=[], attrs={}, model) {
|
|
|
await api.waitUntil('chatBoxesFetched');
|
|
@@ -25,8 +29,8 @@ export default {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
- * @method api.chats.get
|
|
|
- * @param { String|String[] } jids - A JID or array of JIDs
|
|
|
+ * @method api.chatboxes.get
|
|
|
+ * @param {string|string[]} jids - A JID or array of JIDs
|
|
|
*/
|
|
|
async get (jids) {
|
|
|
await api.waitUntil('chatBoxesFetched');
|
|
@@ -38,5 +42,36 @@ export default {
|
|
|
jids = jids.map(j => j.toLowerCase());
|
|
|
return _converse.chatboxes.models.filter(m => jids.includes(m.get('jid')));
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The "chatboxes" registry.
|
|
|
+ * Allows you to register more chatbox types that can be created via
|
|
|
+ * `api.chatboxes.create`.
|
|
|
+ * @namespace api.chatboxes.registry
|
|
|
+ * @memberOf api.chatboxes
|
|
|
+ */
|
|
|
+ registry: {
|
|
|
+ /**
|
|
|
+ * @method api.chatboxes.registry.add
|
|
|
+ * Add another type of chatbox that can be added to this collection.
|
|
|
+ * This is used in the `createModel` function to determine what type of
|
|
|
+ * chatbox class to instantiate (e.g. ChatBox, MUC, Feed etc.) based on the
|
|
|
+ * passed in attributes.
|
|
|
+ * @param {string} type - The type name
|
|
|
+ * @param {Model} model - The model which will be instantiated for the given type name.
|
|
|
+ */
|
|
|
+ add(type, model) {
|
|
|
+ _chatBoxTypes[type] = model;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @method api.chatboxes.registry.get
|
|
|
+ * @param {string} type - The type name
|
|
|
+ * @return {Model} model - The model which will be instantiated for the given type name.
|
|
|
+ */
|
|
|
+ get(type) {
|
|
|
+ return _chatBoxTypes[type];
|
|
|
+ }
|
|
|
}
|
|
|
}
|