xmppcomponent_listener: Switch to util.xmppstream from xmlhandlers
[prosody.git] / plugins / mod_pep.lua
index 63063976c60654181f6c7b7a093aa40075867866..28c312944fbf0e268e8c3bf5c04d7ec3d714c4b6 100644 (file)
@@ -145,6 +145,16 @@ module:hook("presence/bare", function(event)
                end
        elseif t == "unavailable" then
                if recipients[user] then recipients[user][stanza.attr.from] = nil; end
+       elseif not self and t == "unsubscribe" then
+               local from = jid_bare(stanza.attr.from);
+               local subscriptions = recipients[user];
+               if subscriptions then
+                       for subscriber in pairs(subscriptions) do
+                               if jid_bare(subscriber) == from then
+                                       recipients[user][subscriber] = nil;
+                               end
+                       end
+               end
        end
 end, 10);
 
@@ -235,15 +245,15 @@ module:hook("iq-result/bare/disco", function(event)
                        end
                        hash_map[ver] = notify; -- update hash map
                        if self then
-                               for jid, item in pairs(origin.roster) do -- for all interested contacts
+                               for jid, item in pairs(session.roster) do -- for all interested contacts
                                        if item.subscription == "both" or item.subscription == "from" then
                                                if not recipients[jid] then recipients[jid] = {}; end
                                                recipients[jid][contact] = notify;
+                                               publish_all(jid, contact, session);
                                        end
                                end
-                       else
-                               recipients[user][contact] = notify; -- set recipient's data to calculated data
                        end
+                       recipients[user][contact] = notify; -- set recipient's data to calculated data
                        -- send messages to recipient
                        publish_all(user, contact, session);
                end