|
@@ -5,7 +5,7 @@
|
|
import converse from '../../shared/api/public.js';
|
|
import converse from '../../shared/api/public.js';
|
|
import _converse from '../../shared/_converse.js';
|
|
import _converse from '../../shared/_converse.js';
|
|
import api from '../../shared/api/index.js';
|
|
import api from '../../shared/api/index.js';
|
|
-import log from "@converse/log";
|
|
|
|
|
|
+import log from '@converse/log';
|
|
import { parseErrorStanza } from '../../shared/parsers.js';
|
|
import { parseErrorStanza } from '../../shared/parsers.js';
|
|
import { parseStanzaForPubSubConfig } from './parsers.js';
|
|
import { parseStanzaForPubSubConfig } from './parsers.js';
|
|
|
|
|
|
@@ -176,7 +176,8 @@ export default {
|
|
const e = await parseErrorStanza(iq);
|
|
const e = await parseErrorStanza(iq);
|
|
if (
|
|
if (
|
|
e.name === 'conflict' &&
|
|
e.name === 'conflict' &&
|
|
- /** @type {import('shared/errors').StanzaError} */(e).extra[Strophe.NS.PUBSUB_ERROR] === 'precondition-not-met'
|
|
|
|
|
|
+ /** @type {import('shared/errors').StanzaError} */ (e).extra[Strophe.NS.PUBSUB_ERROR] ===
|
|
|
|
+ 'precondition-not-met'
|
|
) {
|
|
) {
|
|
// Manually configure the node if we can't set it via publish-options
|
|
// Manually configure the node if we can't set it via publish-options
|
|
await api.pubsub.config.set(entity_jid, node, options);
|
|
await api.pubsub.config.set(entity_jid, node, options);
|
|
@@ -198,5 +199,43 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ /**
|
|
|
|
+ * Subscribes the local user to a PubSub node.
|
|
|
|
+ *
|
|
|
|
+ * @method _converse.api.pubsub.subscribe
|
|
|
|
+ * @param {string} jid - PubSub service JID.
|
|
|
|
+ * @param {string} node - The node to subscribe to
|
|
|
|
+ * @returns {Promise<void>}
|
|
|
|
+ */
|
|
|
|
+ async subscribe(jid, node) {
|
|
|
|
+ const service = jid || (await api.disco.entities.find('http://jabber.org/protocol/pubsub'));
|
|
|
|
+ const own_jid = _converse.session.get('jid');
|
|
|
|
+ const iq = stx`
|
|
|
|
+ <iq type="set" from="${own_jid}" to="${service}" xmlns="jabber:client">
|
|
|
|
+ <pubsub xmlns="${Strophe.NS.PUBSUB}">
|
|
|
|
+ <subscribe node="${node}" jid="${own_jid}"/>
|
|
|
|
+ </pubsub>
|
|
|
|
+ </iq>`;
|
|
|
|
+ await api.sendIQ(iq);
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Unsubscribes the local user from a PubSub node.
|
|
|
|
+ *
|
|
|
|
+ * @method _converse.api.pubsub.unsubscribe
|
|
|
|
+ * @param {string} jid - The PubSub service JID
|
|
|
|
+ * @param {string} node - The node to unsubscribe from
|
|
|
|
+ * @returns {Promise<void>}
|
|
|
|
+ */
|
|
|
|
+ async unsubscribe(jid, node) {
|
|
|
|
+ const own_jid = _converse.session.get('jid');
|
|
|
|
+ const iq = stx`
|
|
|
|
+ <iq type="set" from="${own_jid}" to="${jid}" xmlns="jabber:client">
|
|
|
|
+ <pubsub xmlns="${Strophe.NS.PUBSUB}">
|
|
|
|
+ <unsubscribe node="${node}" jid="${own_jid}"/>
|
|
|
|
+ </pubsub>
|
|
|
|
+ </iq>`;
|
|
|
|
+ await api.sendIQ(iq);
|
|
|
|
+ },
|
|
},
|
|
},
|
|
};
|
|
};
|