clix/bounce.lua

changeset 25
db6e92989c41
child 27
5b58c002d6ad
equal deleted inserted replaced
24:8e157125957d 25:db6e92989c41
1 short_opts.h = "history";
2
3 return function (opts, arg)
4 local function on_connect(conn)
5 -- Allow selective bouncing
6 local only_node, only_server, only_resource;
7 if opts.only_from then
8 only_node, only_server, only_resource = jid.split(opts.only_from);
9 end
10 local function should_bounce(stanza)
11 local node, server, resource = jid.split(stanza.attr.from);
12 if only_node and (node ~= only_node)
13 or only_server and (server ~= only_server)
14 or only_resource and (resource ~= only_resource) then
15 return false;
16 end
17 return true;
18 end
19 local function on_message(message)
20 local delay = message:get_child("delay", "urn:xmpp:delay");
21 if (delay and not opts.history) or not should_bounce(message) then
22 return;
23 end
24 message.attr.from = nil;
25 message.attr.to = opts.to;
26 message.attr.type = opts.type or (opts.chatroom and "groupchat") or "chat";
27 conn:send(message);
28 end
29 conn:hook("message", on_message);
30 end
31 return clix_connect(opts, on_connect);
32 end

mercurial