Diff

core/moduleapi.lua @ 6651:deaa3d66dc2c

moduleapi: Add module:broadcast() to send a stanza to a list of JIDs
author Matthew Wild <mwild1@gmail.com>
date Wed, 06 May 2015 18:37:46 +0100
parent 6640:859e9af53aa1
child 6652:06116b2789f0
line wrap: on
line diff
--- a/core/moduleapi.lua	Tue Apr 28 14:19:28 2015 +0100
+++ b/core/moduleapi.lua	Wed May 06 18:37:46 2015 +0100
@@ -10,6 +10,7 @@
 local modulemanager; -- This gets set from modulemanager
 local array = require "util.array";
 local set = require "util.set";
+local it = require "util.iterators";
 local logger = require "util.logger";
 local pluginloader = require "util.pluginloader";
 local timer = require "util.timer";
@@ -362,6 +363,14 @@
 	return core_post_stanza(hosts[self.host], stanza);
 end
 
+function api:broadcast(jids, stanza, iter)
+	for jid in (iter or it.values)(jids) do
+		local new_stanza = st.clone(stanza);
+		new_stanza.attr.to = jid;
+		core_post_stanza(hosts[self.host], new_stanza);
+	end
+end
+
 function api:add_timer(delay, callback)
 	return timer.add_task(delay, function (t)
 		if self.loaded == false then return; end