aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-12-21 03:27:22 +0000
committerMatthew Wild <mwild1@gmail.com>2010-12-21 03:27:22 +0000
commitd12133b6149d70fa19a95fc257f799fc5b8193d1 (patch)
tree9bc47775dcd8d5cfe2b56fb042a2096e89a423a5
parent16874d84de0d933a11a5f14d71f6326bff0df543 (diff)
downloadprosody-d12133b6149d70fa19a95fc257f799fc5b8193d1.tar.gz
prosody-d12133b6149d70fa19a95fc257f799fc5b8193d1.zip
mod_pubsub: Update for latest util.pubsub and fix some bugs. New config options autocreate_on_publish, autocreate_on_subscribe and default_admin_affiliation.
-rw-r--r--plugins/mod_pubsub.lua81
1 files changed, 75 insertions, 6 deletions
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua
index 32c75c4d..b7c04163 100644
--- a/plugins/mod_pubsub.lua
+++ b/plugins/mod_pubsub.lua
@@ -44,8 +44,14 @@ function handlers.get_items(origin, stanza, items)
local node = items.attr.node;
local item = items:get_child("item");
local id = item and item.attr.id;
+
+ local ok, results = service:get_items(node, stanza.attr.from, id);
+ if not ok then
+ return origin.send(pubsub_error_reply(stanza, results));
+ end
+
local data = st.stanza("items", { node = node });
- for _, entry in pairs(service:get(node, stanza.attr.from, id)) do
+ for _, entry in pairs(results) do
data:add_child(entry);
end
if data then
@@ -72,10 +78,14 @@ function handlers.set_create(origin, stanza, create)
repeat
node = uuid_generate();
ok, ret = service:create(node, stanza.attr.from);
- until ok;
- reply = st.reply(stanza)
- :tag("pubsub", { xmlns = xmlns_pubsub })
- :tag("create", { node = node });
+ until ok or ret ~= "conflict";
+ if ok then
+ reply = st.reply(stanza)
+ :tag("pubsub", { xmlns = xmlns_pubsub })
+ :tag("create", { node = node });
+ else
+ reply = pubsub_error_reply(stanza, ret);
+ end
end
return origin.send(reply);
end
@@ -191,8 +201,67 @@ module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function
return true;
end);
+local admin_aff = module:get_option_string("default_admin_affiliation", "owner");
+local function get_affiliation(jid)
+ if usermanager.is_admin(jid, module.host) then
+ return admin_aff;
+ end
+end
+
service = pubsub.new({
- broadcaster = simple_broadcast
+ capabilities = {
+ none = {
+ create = false;
+ publish = false;
+ retract = false;
+ get_nodes = true;
+
+ subscribe = true;
+ unsubscribe = true;
+ get_subscription = true;
+ --get_items = true;
+
+ subscribe_other = false;
+ unsubscribe_other = false;
+ get_subscription_other = false;
+
+ be_subscribed = true;
+ be_unsubscribed = true;
+
+ set_affiliation = false;
+ };
+ owner = {
+ create = true;
+ publish = true;
+ retract = true;
+ get_nodes = true;
+
+ subscribe = true;
+ unsubscribe = true;
+ get_subscription = true;
+ --get_items = true;
+
+
+ subscribe_other = true;
+ unsubscribe_other = true;
+ get_subscription_other = true;
+
+ be_subscribed = true;
+ be_unsubscribed = true;
+
+ set_affiliation = true;
+ };
+ admin = { get_items = true };
+ };
+
+ autocreate_on_publish = module:get_option_boolean("autocreate_on_publish");
+ autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe");
+
+ broadcaster = simple_broadcast;
+ get_affiliation = get_affiliation;
+ jids_equal = function (jid1, jid2)
+ return jid_bare(jid1) == jid_bare(jid2);
+ end;
});
module.environment.service = service;