diff options
-rw-r--r-- | plugins/mod_pubsub.lua | 18 | ||||
-rw-r--r-- | util/pubsub.lua | 15 |
2 files changed, 31 insertions, 2 deletions
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua index cb0eff7a..da2070f3 100644 --- a/plugins/mod_pubsub.lua +++ b/plugins/mod_pubsub.lua @@ -37,6 +37,24 @@ function pubsub_error_reply(stanza, error) return reply; end +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 data = st.stanza("items", { node = node }); + for _, entry in pairs(service:get(node, stanza.attr.from, id)) do + data:add_child(entry); + end + if data then + reply = st.reply(stanza) + :tag("pubsub", { xmlns = xmlns_pubsub }) + :add_child(data); + else + reply = st.error_reply(stanza, "cancel", "item-not-found", "Item could not be found in this node"); + end + return origin.send(reply); +end + function handlers.set_subscribe(origin, stanza, subscribe) local node, jid = subscribe.attr.node, subscribe.attr.jid; if jid_bare(jid) ~= jid_bare(stanza.attr.from) then diff --git a/util/pubsub.lua b/util/pubsub.lua index 22a29c18..da90fdcc 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -31,12 +31,23 @@ end function service:publish(node, actor, id, item) local node_obj = self.nodes[node]; if not node_obj then - node_obj = { name = node, subscribers = {}, config = {} }; + node_obj = { name = node, subscribers = {}, config = {}, data = {} }; self.nodes[node] = node_obj; end - node_obj.data = item; + node_obj.data[id] = item; self.cb.broadcaster(node, node_obj.subscribers, item); return true; end +function service:get(node, actor, id) + local node_obj = self.nodes[node]; + if node_obj then + if id then + return { node_obj.data[id] }; + else + return node_obj.data; + end + end +end + return _M; |