X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_pubsub.lua;h=40b119ccb234bca979761a9bcd18ea01cc6e591c;hb=99b003b1917a8ab0b561f7fb98d28d1fad8f8dc8;hp=465bcb00007f6c07b06cd8c6b1c2d5e540dfae01;hpb=c66cc52a698c80e695669910c338fca24a15fd28;p=prosody.git diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua index 465bcb00..40b119cc 100644 --- a/plugins/mod_pubsub.lua +++ b/plugins/mod_pubsub.lua @@ -9,6 +9,8 @@ local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event"; local autocreate_on_publish = module:get_option_boolean("autocreate_on_publish", false); local autocreate_on_subscribe = module:get_option_boolean("autocreate_on_subscribe", false); +local pubsub_disco_name = module:get_option("name"); +if type(pubsub_disco_name) ~= "string" then pubsub_disco_name = "Prosody PubSub Service"; end local service; @@ -55,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 }) @@ -108,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) @@ -117,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) @@ -181,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 @@ -217,7 +237,7 @@ end local function build_disco_info(service) local disco_info = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" }) - :tag("identity", { category = "pubsub", type = "service" }):up() + :tag("identity", { category = "pubsub", type = "service", name = pubsub_disco_name }):up() :tag("feature", { var = "http://jabber.org/protocol/pubsub" }):up(); add_disco_features_from_service(disco_info, service); return disco_info; @@ -327,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;