Software /
code /
prosody
Diff
plugins/mod_pubsub/pubsub.lib.lua @ 8337:dc4ea43ac463
mod_pubsub: Add support for Create and Configure
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 18 Oct 2017 09:08:16 +0200 |
parent | 8336:587305c0ff85 |
child | 8338:30d8157391e9 |
line wrap: on
line diff
--- a/plugins/mod_pubsub/pubsub.lib.lua Wed Oct 18 07:49:44 2017 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Wed Oct 18 09:08:16 2017 +0200 @@ -122,8 +122,26 @@ function handlers.set_create(origin, stanza, create, service) local node = create.attr.node; local ok, ret, reply; + local config; + local configure = stanza.tags[1]:get_child("configure"); + if configure then + local config_form = config:get_child("x", "jabber:x:data"); + if not config_form then + origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform")); + return true; + end + local form_data, err = node_config_form:data(config_form); + if not form_data then + origin.send(st.error_reply(stanza, "modify", "bad-request", err)); + return true; + end + config = { + ["max_items"] = tonumber(form_data["pubsub#max_items"]); + ["persist_items"] = form_data["pubsub#persist_items"]; + }; + end if node then - ok, ret = service:create(node, stanza.attr.from); + ok, ret = service:create(node, stanza.attr.from, config); if ok then reply = st.reply(stanza); else @@ -132,7 +150,7 @@ else repeat node = uuid_generate(); - ok, ret = service:create(node, stanza.attr.from); + ok, ret = service:create(node, stanza.attr.from, config); until ok or ret ~= "conflict"; if ok then reply = st.reply(stanza)