Add api.chatviews.get method

This commit is contained in:
JC Brand 2018-03-14 13:03:26 +00:00
parent 044907e4fa
commit 2045741fbe
2 changed files with 46 additions and 0 deletions

View File

@ -864,6 +864,31 @@ To return an array of chatboxes, provide an array of JIDs:
| url | The URL of the chatbox heading. |
+-------------+-----------------------------------------------------+
The **chatviews** grouping
----------------------
.. note:: This is only for private chats.
get
~~~
Returns a `Backbone.View <http://backbonejs.org/#View>`_ of type _converse.ChatBoxView.
The chat should already be open, otherwise `undefined` will be returned.
To return a single view, provide the JID of the contact:
.. code-block:: javascript
_converse.api.chatviews.get('buddy@example.com')
To return an array of views, provide an array of JIDs:
.. code-block:: javascript
_converse.api.chatviews.get(['buddy1@example.com', 'buddy2@example.com'])
.. _`listen-grouping`:
The **listen** grouping

View File

@ -1186,6 +1186,27 @@
// Advertise that we support XEP-0382 Message Spoilers
_converse.connection.disco.addFeature(Strophe.NS.SPOILER);
});
/************************ BEGIN API ************************/
_.extend(_converse.api, {
'chatviews': {
'get' (jids) {
if (_.isUndefined(jids)) {
_converse.log(
"chats.create: You need to provide at least one JID",
Strophe.LogLevel.ERROR
);
return null;
}
if (_.isString(jids)) {
return _converse.chatboxviews.get(jids);
}
return _.map(jids, (jid) => _converse.chatboxviews.get(jids));
}
}
});
/************************ END API ************************/
}
});