diff options
Diffstat (limited to 'plugins/mod_pep.lua')
-rw-r--r-- | plugins/mod_pep.lua | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index 1025be37..f0b5d7ef 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -18,6 +18,8 @@ local calculate_hash = require "util.caps".calculate_hash; local core_post_stanza = prosody.core_post_stanza; local bare_sessions = prosody.bare_sessions; +local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; + -- Used as canonical 'empty table' local NULL = {}; -- data[user_bare_jid][node] = item_stanza @@ -36,9 +38,6 @@ module.restore = function(state) hash_map = state.hash_map or {}; end -module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody")); -module:add_feature("http://jabber.org/protocol/pubsub#publish"); - local function subscription_presence(user_bare, recipient) local recipient_bare = jid_bare(recipient); if (recipient_bare == user_bare) then return true end @@ -118,7 +117,7 @@ local function get_caps_hash_from_presence(stanza, current) end module:hook("presence/bare", function(event) - -- inbound presence to bare JID recieved + -- inbound presence to bare JID received local origin, stanza = event.origin, event.stanza; local user = stanza.attr.to or (origin.username..'@'..origin.host); local t = stanza.attr.type; @@ -173,8 +172,8 @@ module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event) local payload = stanza.tags[1]; if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then - payload = payload.tags[1]; - if payload and (payload.name == 'publish' or payload.name == 'retract') and payload.attr.node then -- <publish node='http://jabber.org/protocol/tune'> + payload = payload.tags[1]; -- <publish node='http://jabber.org/protocol/tune'> + if payload and (payload.name == 'publish' or payload.name == 'retract') and payload.attr.node then local node = payload.attr.node; payload = payload.tags[1]; if payload and payload.name == "item" then -- <item> @@ -208,20 +207,20 @@ module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event) if node and user_data and user_data[node] then -- Send the last item local id, item = unpack(user_data[node]); if not requested_id or id == requested_id then - local stanza = st.reply(stanza) + local reply_stanza = st.reply(stanza) :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) :tag('items', {node=node}) :add_child(item) :up() :up(); - session.send(stanza); + session.send(reply_stanza); return true; else -- requested item doesn't exist - local stanza = st.reply(stanza) + local reply_stanza = st.reply(stanza) :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) :tag('items', {node=node}) :up(); - session.send(stanza); + session.send(reply_stanza); return true; end elseif node then -- node doesn't exist @@ -284,7 +283,23 @@ end); module:hook("account-disco-info", function(event) local reply = event.reply; reply:tag('identity', {category='pubsub', type='pep'}):up(); - reply:tag('feature', {var='http://jabber.org/protocol/pubsub#publish'}):up(); + reply:tag('feature', {var=xmlns_pubsub}):up(); + local features = { + "access-presence", + "auto-create", + "auto-subscribe", + "filtered-notifications", + "item-ids", + "last-published", + "presence-notifications", + "presence-subscribe", + "publish", + "retract-items", + "retrieve-items", + }; + for _, feature in ipairs(features) do + reply:tag('feature', {var=xmlns_pubsub.."#"..feature}):up(); + end end); module:hook("account-disco-items", function(event) @@ -300,7 +315,7 @@ module:hook("account-disco-items", function(event) end); module:hook("account-disco-info-node", function (event) - local session, stanza, node = event.origin, event.stanza, event.node; + local stanza, node = event.stanza, event.node; local user = stanza.attr.to; local user_data = data[user]; if user_data and user_data[node] then |