clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)

Thu, 07 Jan 2010 22:25:28 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 07 Jan 2010 22:25:28 +0000
changeset 25
db6e92989c41
parent 24
8e157125957d
child 26
028c5ffc6d7c

clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)

clix/bounce.lua file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clix/bounce.lua	Thu Jan 07 22:25:28 2010 +0000
@@ -0,0 +1,32 @@
+short_opts.h = "history";
+
+return function (opts, arg)
+	local function on_connect(conn)
+		-- Allow selective bouncing
+		local only_node, only_server, only_resource;
+		if opts.only_from then
+			only_node, only_server, only_resource = jid.split(opts.only_from);
+		end
+		local function should_bounce(stanza)
+			local node, server, resource = jid.split(stanza.attr.from);
+			if only_node and (node ~= only_node)
+				or only_server and (server ~= only_server)
+				or only_resource and (resource ~= only_resource) then
+				return false;
+			end
+			return true;
+		end
+		local function on_message(message)
+			local delay = message:get_child("delay", "urn:xmpp:delay");
+			if (delay and not opts.history) or not should_bounce(message) then
+				return;
+			end
+			message.attr.from = nil;
+			message.attr.to = opts.to;
+			message.attr.type = opts.type or (opts.chatroom and "groupchat") or "chat";
+			conn:send(message);
+		end
+		conn:hook("message", on_message);
+	end
+	return clix_connect(opts, on_connect);
+end

mercurial