X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_pubsub.lua;h=40b119ccb234bca979761a9bcd18ea01cc6e591c;hb=88b01c6a41f9899466f3faff8ef820dd6bbcbd51;hp=fd307583c94ca1ad077e22d9e6ce9bd1cf05fc84;hpb=3c397c79fbd40cea52add7a58d481296602a4755;p=prosody.git diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua index fd307583..40b119cc 100644 --- a/plugins/mod_pubsub.lua +++ b/plugins/mod_pubsub.lua @@ -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 +}));