From 2648f37aa0c3b57f5bd5319497a79b1486e710f6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 6 May 2015 18:37:46 +0100 Subject: moduleapi: Add module:broadcast() to send a stanza to a list of JIDs --- core/moduleapi.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'core/moduleapi.lua') diff --git a/core/moduleapi.lua b/core/moduleapi.lua index f3326295..c40363a1 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -10,6 +10,7 @@ local config = require "core.configmanager"; 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 @@ function api:send(stanza) 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 -- cgit v1.2.3