Rename push_services to push_app_servers to avoid confusion

This commit is contained in:
JC Brand 2018-06-11 14:17:34 +02:00
parent 907775d784
commit 7b19483271
4 changed files with 57 additions and 57 deletions

50
dist/converse.js vendored
View File

@ -73353,64 +73353,64 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
__ = _converse.__; __ = _converse.__;
_converse.api.settings.update({ _converse.api.settings.update({
'push_services': [] 'push_app_servers': []
}); });
function disablePushService(push_service) { function disablePushAppServer(push_app_server) {
if (!push_service.jid) { if (!push_app_server.jid) {
return; return;
} }
Promise.all([_converse.api.disco.supports(Strophe.NS.PUSH, _converse.bare_jid)]).then(result => { Promise.all([_converse.api.disco.supports(Strophe.NS.PUSH, _converse.bare_jid)]).then(result => {
if (!result[0].length && !result[1].length) { if (!result[0].length && !result[1].length) {
return _converse.log(`Not disabling push service "${push_service.jid}", no disco support from your server.`, Strophe.LogLevel.WARN); return _converse.log(`Not disabling push app server "${push_app_server.jid}", no disco support from your server.`, Strophe.LogLevel.WARN);
} }
const stanza = $iq({ const stanza = $iq({
'type': 'set' 'type': 'set'
}).c('disable', { }).c('disable', {
'xmlns': Strophe.NS.PUSH, 'xmlns': Strophe.NS.PUSH,
'jid': push_service.jid 'jid': push_app_server.jid
}); });
if (push_service.node) { if (push_app_server.node) {
stanza.attrs({ stanza.attrs({
'node': push_service.node 'node': push_app_server.node
}); });
} }
_converse.api.sendIQ(stanza).then(() => _converse.session.set('push_enabled', true)).catch(e => { _converse.api.sendIQ(stanza).then(() => _converse.session.set('push_enabled', true)).catch(e => {
_converse.log(`Could not enable push service for ${push_service.jid}`, Strophe.LogLevel.ERROR); _converse.log(`Could not enable push app server for ${push_app_server.jid}`, Strophe.LogLevel.ERROR);
_converse.log(e, Strophe.LogLevel.ERROR); _converse.log(e, Strophe.LogLevel.ERROR);
}); });
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
} }
function enablePushService(push_service) { function enablePushAppServer(push_app_server) {
if (!push_service.jid || !push_service.node) { if (!push_app_server.jid || !push_app_server.node) {
return; return;
} }
_converse.api.disco.getIdentity('pubsub', 'push', push_service.jid).then(identity => { _converse.api.disco.getIdentity('pubsub', 'push', push_app_server.jid).then(identity => {
if (!identity) { if (!identity) {
return _converse.log(`Not enabling push the service "${push_service.jid}", it doesn't have the right disco identtiy.`, Strophe.LogLevel.WARN); return _converse.log(`Not enabling push the service "${push_app_server.jid}", it doesn't have the right disco identtiy.`, Strophe.LogLevel.WARN);
} }
return Promise.all([_converse.api.disco.supports(Strophe.NS.PUSH, push_service.jid), _converse.api.disco.supports(Strophe.NS.PUSH, _converse.bare_jid)]).then(result => { return Promise.all([_converse.api.disco.supports(Strophe.NS.PUSH, push_app_server.jid), _converse.api.disco.supports(Strophe.NS.PUSH, _converse.bare_jid)]).then(result => {
if (!result[0].length && !result[1].length) { if (!result[0].length && !result[1].length) {
return _converse.log(`Not enabling push service "${push_service.jid}", no disco support from your server.`, Strophe.LogLevel.WARN); return _converse.log(`Not enabling push app server "${push_app_server.jid}", no disco support from your server.`, Strophe.LogLevel.WARN);
} }
const stanza = $iq({ const stanza = $iq({
'type': 'set' 'type': 'set'
}).c('enable', { }).c('enable', {
'xmlns': Strophe.NS.PUSH, 'xmlns': Strophe.NS.PUSH,
'jid': push_service.jid, 'jid': push_app_server.jid,
'node': push_service.node 'node': push_app_server.node
}); });
if (push_service.secret) { if (push_app_server.secret) {
stanza.c('x', { stanza.c('x', {
'xmlns': Strophe.NS.XFORM, 'xmlns': Strophe.NS.XFORM,
'type': 'submit' 'type': 'submit'
@ -73418,11 +73418,11 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'var': 'FORM_TYPE' 'var': 'FORM_TYPE'
}).c('value').t(`${Strophe.NS.PUBSUB}#publish-options`).up().up().c('field', { }).c('value').t(`${Strophe.NS.PUBSUB}#publish-options`).up().up().c('field', {
'var': 'secret' 'var': 'secret'
}).c('value').t(push_service.secret); }).c('value').t(push_app_server.secret);
} }
_converse.api.sendIQ(stanza).then(() => _converse.session.set('push_enabled', true)).catch(e => { _converse.api.sendIQ(stanza).then(() => _converse.session.set('push_enabled', true)).catch(e => {
_converse.log(`Could not enable push service for ${push_service.jid}`, Strophe.LogLevel.ERROR); _converse.log(`Could not enable push app server for ${push_app_server.jid}`, Strophe.LogLevel.ERROR);
_converse.log(e, Strophe.LogLevel.ERROR); _converse.log(e, Strophe.LogLevel.ERROR);
}); });
@ -73433,20 +73433,20 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
function enablePush() { function enablePush() {
if (_converse.session.get('push_enabled')) { if (_converse.session.get('push_enabled')) {
// XXX: this code is still a bit naive. We set push_enabled // XXX: this code is still a bit naive. We set push_enabled
// to true as soon as the first push service has been set. // to true as soon as the first push app server has been set.
// //
// When enabling or disabling multiple push services, // When enabling or disabling multiple push app servers,
// we won't wait until we have confirmation that all have been set. // we won't wait until we have confirmation that all have been set.
return; return;
} }
const enabled_services = _.reject(_converse.push_services, 'disable'); const enabled_services = _.reject(_converse.push_app_servers, 'disable');
_.each(enabled_services, enablePushService); _.each(enabled_services, enablePushAppServer);
const disabled_services = _.filter(_converse.push_services, 'disable'); const disabled_services = _.filter(_converse.push_app_servers, 'disable');
_.each(disabled_services, disablePushService); _.each(disabled_services, disablePushAppServer);
} }
_converse.api.listen.on('statusInitialized', enablePush); _converse.api.listen.on('statusInitialized', enablePush);

View File

@ -1068,7 +1068,7 @@ providers_link
The hyperlink on the registration form which points to a directory of public The hyperlink on the registration form which points to a directory of public
XMPP servers. XMPP servers.
push_services push_app_servers
------------- -------------
* Default: ``[]`` * Default: ``[]``
@ -1091,7 +1091,7 @@ For example:
.. code-block:: javascript .. code-block:: javascript
converse.initialize({ converse.initialize({
'push_services': [{ 'push_app_servers': [{
'jid': 'push-4@client.example', 'jid': 'push-4@client.example',
'node': 'yxs32uqsflafdk3iuqo', 'node': 'yxs32uqsflafdk3iuqo',
'disable': true 'disable': true

View File

@ -11,7 +11,7 @@
it("can be enabled", it("can be enabled",
mock.initConverseWithPromises(null, mock.initConverseWithPromises(null,
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {
'push_services': [{ 'push_app_servers': [{
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
'node': 'yxs32uqsflafdk3iuqo' 'node': 'yxs32uqsflafdk3iuqo'
}] }]
@ -23,7 +23,7 @@
expect(_converse.session.get('push_enabled')).toBeFalsy(); expect(_converse.session.get('push_enabled')).toBeFalsy();
test_utils.waitUntilDiscoConfirmed( test_utils.waitUntilDiscoConfirmed(
_converse, _converse.push_services[0].jid, _converse, _converse.push_app_servers[0].jid,
[{'category': 'pubsub', 'type':'push'}], [{'category': 'pubsub', 'type':'push'}],
['urn:xmpp:push:0'], [], 'info') ['urn:xmpp:push:0'], [], 'info')
.then(() => test_utils.waitUntilDiscoConfirmed( .then(() => test_utils.waitUntilDiscoConfirmed(
@ -61,7 +61,7 @@
it("can be disabled", it("can be disabled",
mock.initConverseWithPromises(null, mock.initConverseWithPromises(null,
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {
'push_services': [{ 'push_app_servers': [{
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
'node': 'yxs32uqsflafdk3iuqo', 'node': 'yxs32uqsflafdk3iuqo',
'disable': true 'disable': true
@ -109,7 +109,7 @@
it("can require a secret token to be included", it("can require a secret token to be included",
mock.initConverseWithPromises(null, mock.initConverseWithPromises(null,
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {
'push_services': [{ 'push_app_servers': [{
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
'node': 'yxs32uqsflafdk3iuqo', 'node': 'yxs32uqsflafdk3iuqo',
'secret': 'eruio234vzxc2kla-91' 'secret': 'eruio234vzxc2kla-91'
@ -121,7 +121,7 @@
expect(_converse.session.get('push_enabled')).toBeFalsy(); expect(_converse.session.get('push_enabled')).toBeFalsy();
test_utils.waitUntilDiscoConfirmed( test_utils.waitUntilDiscoConfirmed(
_converse, _converse.push_services[0].jid, _converse, _converse.push_app_servers[0].jid,
[{'category': 'pubsub', 'type':'push'}], [{'category': 'pubsub', 'type':'push'}],
['urn:xmpp:push:0'], [], 'info') ['urn:xmpp:push:0'], [], 'info')
.then(() => test_utils.waitUntilDiscoConfirmed( .then(() => test_utils.waitUntilDiscoConfirmed(

View File

@ -27,11 +27,11 @@
{ __ } = _converse; { __ } = _converse;
_converse.api.settings.update({ _converse.api.settings.update({
'push_services': [], 'push_app_servers': [],
}); });
function disablePushService (push_service) { function disablePushAppServer (push_app_server) {
if (!push_service.jid) { if (!push_app_server.jid) {
return; return;
} }
Promise.all([ Promise.all([
@ -39,67 +39,67 @@
]).then((result) => { ]).then((result) => {
if (!result[0].length && !result[1].length) { if (!result[0].length && !result[1].length) {
return _converse.log( return _converse.log(
`Not disabling push service "${push_service.jid}", no disco support from your server.`, `Not disabling push app server "${push_app_server.jid}", no disco support from your server.`,
Strophe.LogLevel.WARN Strophe.LogLevel.WARN
); );
} }
const stanza = $iq({'type': 'set'}) const stanza = $iq({'type': 'set'})
.c('disable', { .c('disable', {
'xmlns': Strophe.NS.PUSH, 'xmlns': Strophe.NS.PUSH,
'jid': push_service.jid, 'jid': push_app_server.jid,
}); });
if (push_service.node) { if (push_app_server.node) {
stanza.attrs({'node': push_service.node}); stanza.attrs({'node': push_app_server.node});
} }
_converse.api.sendIQ(stanza) _converse.api.sendIQ(stanza)
.then(() => _converse.session.set('push_enabled', true)) .then(() => _converse.session.set('push_enabled', true))
.catch((e) => { .catch((e) => {
_converse.log(`Could not enable push service for ${push_service.jid}`, Strophe.LogLevel.ERROR); _converse.log(`Could not enable push app server for ${push_app_server.jid}`, Strophe.LogLevel.ERROR);
_converse.log(e, Strophe.LogLevel.ERROR); _converse.log(e, Strophe.LogLevel.ERROR);
}); });
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
} }
function enablePushService (push_service) { function enablePushAppServer (push_app_server) {
if (!push_service.jid || !push_service.node) { if (!push_app_server.jid || !push_app_server.node) {
return; return;
} }
_converse.api.disco.getIdentity('pubsub', 'push', push_service.jid) _converse.api.disco.getIdentity('pubsub', 'push', push_app_server.jid)
.then((identity) => { .then((identity) => {
if (!identity) { if (!identity) {
return _converse.log( return _converse.log(
`Not enabling push the service "${push_service.jid}", it doesn't have the right disco identtiy.`, `Not enabling push the service "${push_app_server.jid}", it doesn't have the right disco identtiy.`,
Strophe.LogLevel.WARN Strophe.LogLevel.WARN
); );
} }
return Promise.all([ return Promise.all([
_converse.api.disco.supports(Strophe.NS.PUSH, push_service.jid), _converse.api.disco.supports(Strophe.NS.PUSH, push_app_server.jid),
_converse.api.disco.supports(Strophe.NS.PUSH, _converse.bare_jid) _converse.api.disco.supports(Strophe.NS.PUSH, _converse.bare_jid)
]).then((result) => { ]).then((result) => {
if (!result[0].length && !result[1].length) { if (!result[0].length && !result[1].length) {
return _converse.log( return _converse.log(
`Not enabling push service "${push_service.jid}", no disco support from your server.`, `Not enabling push app server "${push_app_server.jid}", no disco support from your server.`,
Strophe.LogLevel.WARN Strophe.LogLevel.WARN
); );
} }
const stanza = $iq({'type': 'set'}) const stanza = $iq({'type': 'set'})
.c('enable', { .c('enable', {
'xmlns': Strophe.NS.PUSH, 'xmlns': Strophe.NS.PUSH,
'jid': push_service.jid, 'jid': push_app_server.jid,
'node': push_service.node 'node': push_app_server.node
}); });
if (push_service.secret) { if (push_app_server.secret) {
stanza.c('x', {'xmlns': Strophe.NS.XFORM, 'type': 'submit'}) stanza.c('x', {'xmlns': Strophe.NS.XFORM, 'type': 'submit'})
.c('field', {'var': 'FORM_TYPE'}) .c('field', {'var': 'FORM_TYPE'})
.c('value').t(`${Strophe.NS.PUBSUB}#publish-options`).up().up() .c('value').t(`${Strophe.NS.PUBSUB}#publish-options`).up().up()
.c('field', {'var': 'secret'}) .c('field', {'var': 'secret'})
.c('value').t(push_service.secret); .c('value').t(push_app_server.secret);
} }
_converse.api.sendIQ(stanza) _converse.api.sendIQ(stanza)
.then(() => _converse.session.set('push_enabled', true)) .then(() => _converse.session.set('push_enabled', true))
.catch((e) => { .catch((e) => {
_converse.log(`Could not enable push service for ${push_service.jid}`, Strophe.LogLevel.ERROR); _converse.log(`Could not enable push app server for ${push_app_server.jid}`, Strophe.LogLevel.ERROR);
_converse.log(e, Strophe.LogLevel.ERROR); _converse.log(e, Strophe.LogLevel.ERROR);
}); });
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
@ -109,17 +109,17 @@
function enablePush () { function enablePush () {
if (_converse.session.get('push_enabled')) { if (_converse.session.get('push_enabled')) {
// XXX: this code is still a bit naive. We set push_enabled // XXX: this code is still a bit naive. We set push_enabled
// to true as soon as the first push service has been set. // to true as soon as the first push app server has been set.
// //
// When enabling or disabling multiple push services, // When enabling or disabling multiple push app servers,
// we won't wait until we have confirmation that all have been set. // we won't wait until we have confirmation that all have been set.
return; return;
} }
const enabled_services = _.reject(_converse.push_services, 'disable'); const enabled_services = _.reject(_converse.push_app_servers, 'disable');
_.each(enabled_services, enablePushService); _.each(enabled_services, enablePushAppServer);
const disabled_services = _.filter(_converse.push_services, 'disable'); const disabled_services = _.filter(_converse.push_app_servers, 'disable');
_.each(disabled_services, disablePushService); _.each(disabled_services, disablePushAppServer);
} }
_converse.api.listen.on('statusInitialized', enablePush); _converse.api.listen.on('statusInitialized', enablePush);
} }