# HG changeset patch # User Kim Alvefur # Date 1373092711 -7200 # Node ID 48cc6cad9bd65299bed25f2bb2dac7f4cb5a95c6 # Parent f7854dd16ed36654a99923667087104fa6090f48 plugins.pubsub: Keep track of wrapped callbacks diff -r f7854dd16ed3 -r 48cc6cad9bd6 plugins/pubsub.lua --- a/plugins/pubsub.lua Sat Jul 06 08:35:37 2013 +0200 +++ b/plugins/pubsub.lua Sat Jul 06 08:38:31 2013 +0200 @@ -140,6 +140,7 @@ end function pubsub_node:hook(callback, prio) + self._hooks = self._hooks or setmetatable({}, { __mode = 'kv' }); local function hook(event) -- FIXME service == nil would mean anyone, -- publishing would be go to your bare jid. @@ -149,12 +150,20 @@ return callback(event) end end + self._hooks[callback] = hook; self.stream:hook("pubsub/event", hook, prio); return hook; end function pubsub_node:unhook(callback) - self.stream:unhook("pubsub/event", callback); + if callback then + local hook = self._hooks[callback]; + self.stream:unhook("pubsub/event", hook); + elseif self._hooks then + for hook in pairs(self._hooks) do + self.stream:unhook("pubsub/event", hook); + end + end end function pubsub_node:create(config, callback)