aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-17 05:47:06 +0200
committerKim Alvefur <zash@zash.se>2017-10-17 05:47:06 +0200
commit519220f836382fbb08420b6b78444853d7fe25e3 (patch)
treeff44d61173cd4224e2d7b774149d7428f23d95c1
parent8052c506f5e99bcd1ef0b1d68b6e568e33dbadb9 (diff)
downloadprosody-im-server-519220f836382fbb08420b6b78444853d7fe25e3.tar
prosody-im-server-519220f836382fbb08420b6b78444853d7fe25e3.zip
pubsub: Distinguish internal representation of node config from XEP-0060 form (util.pubsub should be protocol-agnostic)
-rw-r--r--plugins/mod_pep_plus.lua8
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua21
-rw-r--r--util/pubsub.lua5
3 files changed, 24 insertions, 10 deletions
diff --git a/plugins/mod_pep_plus.lua b/plugins/mod_pep_plus.lua
index 00d9ea3f..53efe53e 100644
--- a/plugins/mod_pep_plus.lua
+++ b/plugins/mod_pep_plus.lua
@@ -43,7 +43,7 @@ end
local function simple_itemstore(username)
return function (config, node)
- if config["pubsub#persist_items"] then
+ if config["persist_items"] then
module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
known_nodes_map:set(username, node, true);
local archive = module:open_store("pep_"..node, "archive");
@@ -51,7 +51,7 @@ local function simple_itemstore(username)
else
module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
known_nodes_map:set(username, node, nil);
- return cache.new(tonumber(config["pubsub#max_items"]));
+ return cache.new(tonumber(config["max_items"]));
end
end
end
@@ -179,8 +179,8 @@ function get_pep_service(username)
};
node_defaults = {
- ["pubsub#max_items"] = "1";
- ["pubsub#persist_items"] = true;
+ ["max_items"] = 1;
+ ["persist_items"] = true;
};
autocreate_on_publish = true;
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index 2f90d79e..829c4833 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -282,10 +282,15 @@ function handlers.get_configure(origin, stanza, config, service)
return true;
end
+ local node_config = node_obj.config;
+ local pubsub_form_data = {
+ ["pubsub#max_items"] = tostring(node_config["max_items"]);
+ ["pubsub#persist_items"] = node_config["persist_items"]
+ }
local reply = st.reply(stanza)
:tag("pubsub", { xmlns = xmlns_pubsub_owner })
:tag("configure", { node = node })
- :add_child(node_config_form:form(node_obj.config));
+ :add_child(node_config_form:form(pubsub_form_data));
origin.send(reply);
return true;
end
@@ -305,11 +310,15 @@ function handlers.set_configure(origin, stanza, config, service)
origin.send(st.error_reply(stanza, "modify", "bad-request", "Missing dataform"));
return true;
end
- local new_config, err = node_config_form:data(config_form);
- if not new_config then
+ 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
+ local new_config = {
+ ["max_items"] = tonumber(form_data["pubsub#max_items"]);
+ ["persist_items"] = form_data["pubsub#persist_items"];
+ };
local ok, err = service:set_node_config(node, stanza.attr.from, new_config);
if not ok then
origin.send(pubsub_error_reply(stanza, err));
@@ -320,10 +329,14 @@ function handlers.set_configure(origin, stanza, config, service)
end
function handlers.get_default(origin, stanza, default, service)
+ local pubsub_form_data = {
+ ["pubsub#max_items"] = tostring(service.node_defaults["max_items"]);
+ ["pubsub#persist_items"] = service.node_defaults["persist_items"]
+ }
local reply = st.reply(stanza)
:tag("pubsub", { xmlns = xmlns_pubsub_owner })
:tag("default")
- :add_child(node_config_form:form(service.node_defaults));
+ :add_child(node_config_form:form(pubsub_form_data));
origin.send(reply);
return true;
end
diff --git a/util/pubsub.lua b/util/pubsub.lua
index a10f9a84..9397484a 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -5,13 +5,14 @@ local service = {};
local service_mt = { __index = service };
local default_config = { __index = {
- itemstore = function (config, _) return cache.new(tonumber(config["pubsub#max_items"])) end;
+ itemstore = function (config, _) return cache.new(config["max_items"]) end;
broadcaster = function () end;
get_affiliation = function () end;
capabilities = {};
} };
local default_node_config = { __index = {
- ["pubsub#max_items"] = "20";
+ ["persist_items"] = false;
+ ["max_items"] = 20;
} };
local function new(config)