Commit 0b258003 authored by JC Brand's avatar JC Brand

Add converse-pubsub.js

parent 9c05ca9a
......@@ -4,6 +4,8 @@
- Bugfix: MUC commands were being ignored
- UI: Always show the OMEMO lock icon (grayed out if not available).
- Use `publish-options` with `pubsub#access_model` set to `open` when publishing OMEMO public keys and devices
- Add a new `converse-pubsub` plugin, for generic PubSub operations
- #1353 Message Delivery Receipts not working because of the message "type" attribute
- #1374 Can't load embedded chat when changing `view_mode` between page reloads
- #1376 Fixed some alignment issues in the sidebar
......
This diff is collapsed.
......@@ -2,6 +2,10 @@
* --------------------
* Any of the following components may be removed if they're not needed.
*/
import "@converse/headless/converse-mam"; // XEP-0313 Message Archive Management
import "@converse/headless/converse-ping"; // XEP-0199 XMPP Ping
import "@converse/headless/converse-pubsub"; // XEP-0060 PubSub
import "@converse/headless/converse-vcard"; // XEP-0054 VCard-temp
import "converse-autocomplete";
import "converse-bookmarks"; // XEP-0048 Bookmarks
import "converse-caps"; // XEP-0115 Entity Capabilities
......@@ -10,18 +14,15 @@ import "converse-controlbox"; // The control box
import "converse-dragresize"; // Allows chat boxes to be resized by dragging them
import "converse-embedded";
import "converse-fullscreen";
import "converse-push"; // XEP-0357 Push Notifications
import "converse-headline"; // Support for headline messages
import "@converse/headless/converse-mam"; // XEP-0313 Message Archive Management
import "converse-minimize"; // Allows chat boxes to be minimized
import "converse-muc-views"; // Views related to MUC
import "converse-notification"; // HTML5 Notifications
import "converse-omemo";
import "@converse/headless/converse-ping"; // XEP-0199 XMPP Ping
import "converse-push"; // XEP-0357 Push Notifications
import "converse-register"; // XEP-0077 In-band registration
import "converse-roomslist"; // Show currently open chat rooms
import "converse-rosterview";
import "@converse/headless/converse-vcard"; // XEP-0054 VCard-temp
/* END: Removable components */
import converse from "@converse/headless/converse-core";
......
......@@ -89,6 +89,7 @@ _converse.core_plugins = [
'converse-mam',
'converse-muc',
'converse-ping',
'converse-pubsub',
'converse-roster',
'converse-vcard'
];
......
// Converse.js
// http://conversejs.org
//
// Copyright (c) 2018, the Converse.js developers
// Licensed under the Mozilla Public License (MPLv2)
import "./converse-disco";
import converse from "./converse-core";
const { Strophe, Backbone, Promise, $iq, $build, $msg, $pres, b64_sha1, f, moment, _ } = converse.env;
Strophe.addNamespace('PUBSUB_ERROR', Strophe.NS.PUBSUB+"#errors");
converse.plugins.add('converse-pubsub', {
dependencies: ["converse-disco"],
initialize () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this,
{ __ } = _converse;
/************************ BEGIN API ************************/
// We extend the default converse.js API to add methods specific to MUC groupchats.
_.extend(_converse.api, {
/**
* The "pubsub" namespace groups methods relevant to PubSub
*
* @namespace _converse.api.pubsub
* @memberOf _converse.api
*/
'pubsub': {
/**
* Publshes an item to a PubSub node
*
* @method _converse.api.pubsub.publish
* @param {string} jid The JID of the pubsub service where the node resides.
* @param {string} node The node being published to
* @param {Strophe.Builder} item The Strophe.Builder representation of the XML element being published
* @param {object} options An object representing the publisher options
* (see https://xmpp.org/extensions/xep-0060.html#publisher-publish-options)
*/
async 'publish' (jid, node, item, options) {
const stanza = $iq({
'from': _converse.bare_jid,
'type': 'set',
'to': jid
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('publish', {'node': node})
.cnode(item.tree()).up().up();
if (options) {
jid = jid || _converse.bare_jid;
const result = await _converse.api.disco.supports(Strophe.NS.PUBSUB + '#publish-options', jid);
if (result.length) {
stanza.c('publish-options')
.c('x', {'xmlns': Strophe.NS.XFORM, 'type': 'submit'})
.c('field', {'var': 'FORM_TYPE', 'type': 'hidden'})
.c('value').t('http://jabber.org/protocol/pubsub#publish-options').up().up()
Object.keys(options).forEach(k => stanza.c('field', {'var': k}).c('value').t(options[k]).up().up());
} else {
_converse.log(`_converse.api.publish: ${jid} does not support #publish-options, `+
`so we didn't set them even though they were provided.`)
}
}
return _converse.api.sendIQ(stanza);
}
}
});
/************************ END API ************************/
}
});
......@@ -2,6 +2,7 @@
* --------------------
* Any of the following components may be removed if they're not needed.
*/
import "./converse-pubsub"; // XEP-0199 XMPP Ping
import "./converse-chatboxes"; // Backbone Collection and Models for chat boxes
import "./converse-disco"; // Service discovery plugin
import "./converse-mam"; // XEP-0313 Message Archive Management
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment