mod_bosh: Add support for stanza filters to BOSH sessions (needed by some plugins)
[prosody.git] / plugins / mod_pubsub.lua
index fd307583c94ca1ad077e22d9e6ce9bd1cf05fc84..40b119ccb234bca979761a9bcd18ea01cc6e591c 100644 (file)
@@ -57,6 +57,7 @@ function handlers.get_items(origin, stanza, items)
        for _, entry in pairs(results) do
                data:add_child(entry);
        end
+       local reply;
        if data then
                reply = st.reply(stanza)
                        :tag("pubsub", { xmlns = xmlns_pubsub })
@@ -110,7 +111,11 @@ end
 
 function handlers.set_subscribe(origin, stanza, subscribe)
        local node, jid = subscribe.attr.node, subscribe.attr.jid;
-       local ok, ret = service:add_subscription(node, stanza.attr.from, jid);
+       local options_tag, options = stanza.tags[1]:get_child("options"), nil;
+       if options_tag then
+               options = options_form:data(options_tag.tags[1]);
+       end
+       local ok, ret = service:add_subscription(node, stanza.attr.from, jid, options);
        local reply;
        if ok then
                reply = st.reply(stanza)
@@ -119,11 +124,24 @@ function handlers.set_subscribe(origin, stanza, subscribe)
                                        node = node,
                                        jid = jid,
                                        subscription = "subscribed"
-                               });
+                               }):up();
+               if options_tag then
+                       reply:add_child(options_tag);
+               end
        else
                reply = pubsub_error_reply(stanza, ret);
        end
-       return origin.send(reply);
+       origin.send(reply);
+       if ok then
+               -- Send all current items
+               local ok, items = service:get_items(node, stanza.attr.from);
+               if items then
+                       local jids = { [jid] = options or true };
+                       for id, item in pairs(items) do
+                               service.config.broadcaster(node, jids, item);
+                       end
+               end
+       end
 end
 
 function handlers.set_unsubscribe(origin, stanza, unsubscribe)
@@ -183,7 +201,7 @@ function simple_broadcast(node, jids, item)
        for jid in pairs(jids) do
                module:log("debug", "Sending notification to %s", jid);
                message.attr.to = jid;
-               core_post_stanza(hosts[module.host], message);
+               module:send(message);
        end
 end
 
@@ -329,6 +347,28 @@ set_service(pubsub.new({
                        
                        set_affiliation = false;
                };
+               publisher = {
+                       create = false;
+                       publish = true;
+                       retract = true;
+                       get_nodes = true;
+                       
+                       subscribe = true;
+                       unsubscribe = true;
+                       get_subscription = true;
+                       get_subscriptions = true;
+                       get_items = true;
+                       
+                       subscribe_other = false;
+                       unsubscribe_other = false;
+                       get_subscription_other = false;
+                       get_subscriptions_other = false;
+                       
+                       be_subscribed = true;
+                       be_unsubscribed = true;
+                       
+                       set_affiliation = false;
+               };
                owner = {
                        create = true;
                        publish = true;
@@ -361,4 +401,4 @@ set_service(pubsub.new({
        get_affiliation = get_affiliation;
        
        normalize_jid = jid_bare;
-}));
\ No newline at end of file
+}));