diff util.js @ 3:5aa1bf7154b0

Add a simple PEP node viewer and editor.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 22 Dec 2018 02:23:38 +0100
parents d6df73b466f6
children 5e97e1808a35
line wrap: on
line diff
--- a/util.js
+++ b/util.js
@@ -1,11 +1,17 @@
+const NS = {
+    xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
+    disco_items: 'http://jabber.org/protocol/disco#items',
+    disco_info: 'http://jabber.org/protocol/disco#info',
+    dataforms: 'jabber:x:data',
+    pubsub: 'http://jabber.org/protocol/pubsub',
+    pubsub_owner: 'http://jabber.org/protocol/pubsub#owner',
+    avatar_metadata: 'urn:xmpp:avatar:metadata',
+    avatar_data: 'urn:xmpp:avatar:data',
+    nickname: 'http://jabber.org/protocol/nick',
+};
+
 function nsResolver(prefix) {
-    return {
-        xrd: 'http://docs.oasis-open.org/ns/xri/xrd-1.0',
-        pubsub: 'http://jabber.org/protocol/pubsub',
-        avatar_metadata: 'urn:xmpp:avatar:metadata',
-        avatar_data: 'urn:xmpp:avatar:data',
-        nickname: 'http://jabber.org/protocol/nick',
-    }[prefix] || null;
+    return NS[prefix] || null;
 }
 
 function parseXPath(elem, xpath, result)
@@ -17,3 +23,20 @@ function parseXPath(elem, xpath, result)
         return value.singleNodeValue;
     return value;
 }
+
+function configurePEPField(node, key, value, cb, err_cb) {
+    return $iq({type: 'set'})
+        .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub#owner'})
+            .c('configure', {node: node})
+                .c('x', {xmlns: 'jabber:x:data', type: 'submit'})
+                    .c('field', {'var': 'FORM_TYPE', type: 'hidden'})
+                        .c('value')
+                            .t('http://jabber.org/protocol/pubsub#node_config')
+                            .up()
+                        .up()
+                    .c('field', {'var': key})
+                        .c('value')
+                            .t(value)
+                            .up()
+                        .up();
+}