mod_adhoc: Scan through list of items on load, in case items have been added before we were loaded

Fri, 11 Jun 2010 13:23:10 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Fri, 11 Jun 2010 13:23:10 +0100
changeset 3231
ad3fbed1dda5
parent 3230
a5c3a82d677e
child 3232
c47bfd62701c

mod_adhoc: Scan through list of items on load, in case items have been added before we were loaded

plugins/adhoc/mod_adhoc.lua file | annotate | diff | comparison | revisions
--- a/plugins/adhoc/mod_adhoc.lua	Fri Jun 11 12:18:27 2010 +0100
+++ b/plugins/adhoc/mod_adhoc.lua	Fri Jun 11 13:23:10 2010 +0100
@@ -58,10 +58,19 @@
 	end
 end, 500);
 
+local function handle_item_added(item)
+	commands[item.node] = item;
+end
+
 module:hook("item-added/adhoc", function (event)
-	commands[event.item.node] = event.item;
+	return handle_item_added(event.item);
 end, 500);
 
 module:hook("item-removed/adhoc", function (event)
 	commands[event.item.node] = nil;
 end, 500);
+
+-- Pick up any items that are already added
+for _, item in ipairs(module:get_host_items("adhoc")) do
+	handle_item_added(item);
+end

mercurial