mod_pep: Fix undefined global access
[prosody.git] / plugins / mod_pep.lua
index 438b077d262cada51bcc90b31c5c3422da29f812..6895b561c2041aad42cb1bb32e38534201155614 100644 (file)
@@ -7,6 +7,8 @@ local user_exists = require "core.usermanager".user_exists;
 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
 local pairs, ipairs = pairs, ipairs;
 
+local data = {};
+
 local function publish(session, node, item)
        local stanza = st.message({from=session.full_jid, type='headline'})
                :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'})
@@ -15,8 +17,14 @@ local function publish(session, node, item)
                        :up()
                :up();
 
+       local bare = session.username..'@'..session.host;
+       -- store for the future
+       local user_data = data[bare];
+       if not user_data then user_data = {}; data[bare] = user_data; end
+       user_data[node] = stanza;
+       
        -- broadcast to resources
-       stanza.attr.to = session.username..'@'..session.host;
+       stanza.attr.to = bare;
        core_route_stanza(session, stanza);
 
        -- broadcast to contacts
@@ -43,6 +51,6 @@ module:add_iq_handler("c2s", "http://jabber.org/protocol/pubsub", function (sess
                        end -- TODO else error
                end
        end
-       origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
+       session.send(st.error_reply(stanza, "cancel", "service-unavailable"));
 end);