Comparison

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
comparison
equal deleted inserted replaced
6641:b44ebfe81c73 6651:deaa3d66dc2c
8 8
9 local config = require "core.configmanager"; 9 local config = require "core.configmanager";
10 local modulemanager; -- This gets set from modulemanager 10 local modulemanager; -- This gets set from modulemanager
11 local array = require "util.array"; 11 local array = require "util.array";
12 local set = require "util.set"; 12 local set = require "util.set";
13 local it = require "util.iterators";
13 local logger = require "util.logger"; 14 local logger = require "util.logger";
14 local pluginloader = require "util.pluginloader"; 15 local pluginloader = require "util.pluginloader";
15 local timer = require "util.timer"; 16 local timer = require "util.timer";
16 local resolve_relative_path = require"util.paths".resolve_relative_path; 17 local resolve_relative_path = require"util.paths".resolve_relative_path;
17 local measure = require "core.statsmanager".measure; 18 local measure = require "core.statsmanager".measure;
360 361
361 function api:send(stanza) 362 function api:send(stanza)
362 return core_post_stanza(hosts[self.host], stanza); 363 return core_post_stanza(hosts[self.host], stanza);
363 end 364 end
364 365
366 function api:broadcast(jids, stanza, iter)
367 for jid in (iter or it.values)(jids) do
368 local new_stanza = st.clone(stanza);
369 new_stanza.attr.to = jid;
370 core_post_stanza(hosts[self.host], new_stanza);
371 end
372 end
373
365 function api:add_timer(delay, callback) 374 function api:add_timer(delay, callback)
366 return timer.add_task(delay, function (t) 375 return timer.add_task(delay, function (t)
367 if self.loaded == false then return; end 376 if self.loaded == false then return; end
368 return callback(t); 377 return callback(t);
369 end); 378 end);