New API method _converse.disco.supports
to check whether a certain service discovery feature is supported by an entity.
This commit is contained in:
parent
305f8d2499
commit
042a26d05d
|
@ -22,6 +22,10 @@
|
||||||
builds. Instead the `converse.js` build is now used with `view_mode` set to
|
builds. Instead the `converse.js` build is now used with `view_mode` set to
|
||||||
`fullscreen` and `mobile` respectively.
|
`fullscreen` and `mobile` respectively.
|
||||||
|
|
||||||
|
### API changes
|
||||||
|
- New API method `_converse.disco.supports` to check whether a certain
|
||||||
|
service discovery feature is supported by an entity.
|
||||||
|
|
||||||
### UX/UI changes
|
### UX/UI changes
|
||||||
- Use CSS3 fade transitions to render various elements.
|
- Use CSS3 fade transitions to render various elements.
|
||||||
- Remove `Login` and `Registration` tabs and consolidate into one panel.
|
- Remove `Login` and `Registration` tabs and consolidate into one panel.
|
||||||
|
|
|
@ -431,6 +431,43 @@ disconnect
|
||||||
Terminates the connection.
|
Terminates the connection.
|
||||||
|
|
||||||
|
|
||||||
|
The **disco** grouping
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
This grouping collects API functions related to `service discovery
|
||||||
|
<https://xmpp.org/extensions/xep-0030.html>`_.
|
||||||
|
|
||||||
|
supports
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Used to determine whether an entity supports a given feature.
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
converse.plugins.add('myplugin', {
|
||||||
|
initialize: function () {
|
||||||
|
|
||||||
|
_converse.api.disco.supports(_converse.bare_jid, Strophe.NS.MAM).then(
|
||||||
|
function (supported) {
|
||||||
|
if (supported) {
|
||||||
|
// The feature is supported
|
||||||
|
} else {
|
||||||
|
// The feature is not supported
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function () { // Error
|
||||||
|
_converse.log(
|
||||||
|
"Error or timeout while checking for feature support",
|
||||||
|
Strophe.LogLevel.ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
).catch((msg) => {
|
||||||
|
_converse.log(msg, Strophe.LogLevel.FATAL);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
The **user** grouping
|
The **user** grouping
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@
|
||||||
|
|
||||||
_converse.DiscoEntity = Backbone.Model.extend({
|
_converse.DiscoEntity = Backbone.Model.extend({
|
||||||
/* A Disco Entity is a JID addressable entity that can be queried
|
/* A Disco Entity is a JID addressable entity that can be queried
|
||||||
* for features.
|
* for features.
|
||||||
*
|
*
|
||||||
* See XEP-0030: https://xmpp.org/extensions/xep-0030.html
|
* See XEP-0030: https://xmpp.org/extensions/xep-0030.html
|
||||||
*/
|
*/
|
||||||
idAttribute: 'jid',
|
idAttribute: 'jid',
|
||||||
|
|
||||||
initialize () {
|
initialize () {
|
||||||
|
@ -178,6 +178,43 @@
|
||||||
_converse.disco_entities.browserStorage._clear();
|
_converse.disco_entities.browserStorage._clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* We extend the default converse.js API to add methods specific to service discovery */
|
||||||
|
_.extend(_converse.api, {
|
||||||
|
'disco': {
|
||||||
|
'supports' (entity_jid, feature) {
|
||||||
|
/* Returns a Promise which returns a boolean indicating
|
||||||
|
* whether the feature is supported or by the given
|
||||||
|
* entity or not.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* (String) entity_jid - The JID of the entity which might support the feature.
|
||||||
|
* (String) feature - The feature that might be
|
||||||
|
* supported. In the XML stanza, this is the `var`
|
||||||
|
* attribute of the `<feature>` element. For
|
||||||
|
* example: 'http://jabber.org/protocol/muc'
|
||||||
|
*/
|
||||||
|
return _converse.api.waitUntil('discoInitialized').then(() =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
function fulfillPromise (entity) {
|
||||||
|
if (entity.features.findWhere({'var': feature})) {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let entity = _converse.disco_entities.get(entity_jid);
|
||||||
|
if (_.isUndefined(entity)) {
|
||||||
|
entity = _converse.disco_entities.create({'jid': entity_jid});
|
||||||
|
entity.on('featuresDiscovered', _.partial(fulfillPromise, entity));
|
||||||
|
} else {
|
||||||
|
fulfillPromise(entity);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -24,32 +24,6 @@
|
||||||
// XEP-0313 Message Archive Management
|
// XEP-0313 Message Archive Management
|
||||||
const MAM_ATTRIBUTES = ['with', 'start', 'end'];
|
const MAM_ATTRIBUTES = ['with', 'start', 'end'];
|
||||||
|
|
||||||
function checkMAMSupport (_converse) {
|
|
||||||
/* Returns a promise which resolves when MAM is supported
|
|
||||||
* for this user, or which rejects if not.
|
|
||||||
*/
|
|
||||||
return _converse.api.waitUntil('discoInitialized').then(() =>
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
|
|
||||||
function fulfillPromise (entity) {
|
|
||||||
if (entity.features.findWhere({'var': Strophe.NS.MAM})) {
|
|
||||||
resolve(true);
|
|
||||||
} else {
|
|
||||||
resolve(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let entity = _converse.disco_entities.get(_converse.bare_jid);
|
|
||||||
if (_.isUndefined(entity)) {
|
|
||||||
entity = _converse.disco_entities.create({'jid': _converse.bare_jid});
|
|
||||||
entity.on('featuresDiscovered', _.partial(fulfillPromise, entity));
|
|
||||||
} else {
|
|
||||||
fulfillPromise(entity);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
converse.plugins.add('converse-mam', {
|
converse.plugins.add('converse-mam', {
|
||||||
|
|
||||||
overrides: {
|
overrides: {
|
||||||
|
@ -83,7 +57,7 @@
|
||||||
const { _converse } = this.__super__;
|
const { _converse } = this.__super__;
|
||||||
this.addSpinner();
|
this.addSpinner();
|
||||||
|
|
||||||
checkMAMSupport(_converse).then(
|
_converse.api.disco.supports(_converse.bare_jid, Strophe.NS.MAM).then(
|
||||||
(supported) => { // Success
|
(supported) => { // Success
|
||||||
if (supported) {
|
if (supported) {
|
||||||
this.fetchArchivedMessages();
|
this.fetchArchivedMessages();
|
||||||
|
@ -329,19 +303,6 @@
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
_.extend(_converse.api, {
|
|
||||||
/* Extend default converse.js API to add methods specific to MAM
|
|
||||||
*/
|
|
||||||
'archive': {
|
|
||||||
'query': function () {
|
|
||||||
if (!_converse.api.connection.connected()) {
|
|
||||||
throw new Error('Can\'t call `api.archive.query` before having established an XMPP session');
|
|
||||||
}
|
|
||||||
return _converse.queryForArchivedMessages.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_converse.onMAMError = function (iq) {
|
_converse.onMAMError = function (iq) {
|
||||||
if ($(iq).find('feature-not-implemented').length) {
|
if ($(iq).find('feature-not-implemented').length) {
|
||||||
_converse.log(
|
_converse.log(
|
||||||
|
@ -409,6 +370,19 @@
|
||||||
_converse.on('afterMessagesFetched', (chatboxview) => {
|
_converse.on('afterMessagesFetched', (chatboxview) => {
|
||||||
chatboxview.fetchArchivedMessagesIfNecessary();
|
chatboxview.fetchArchivedMessagesIfNecessary();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_.extend(_converse.api, {
|
||||||
|
/* Extend default converse.js API to add methods specific to MAM
|
||||||
|
*/
|
||||||
|
'archive': {
|
||||||
|
'query': function () {
|
||||||
|
if (!_converse.api.connection.connected()) {
|
||||||
|
throw new Error('Can\'t call `api.archive.query` before having established an XMPP session');
|
||||||
|
}
|
||||||
|
return _converse.queryForArchivedMessages.apply(this, arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user