plugins.carbons: Update to XEP v0.6. Check that messages are from your bare jid.

Tue, 10 Jan 2012 21:08:19 +0100

author
Kim Alvefur <zash@zash.se>
date
Tue, 10 Jan 2012 21:08:19 +0100
changeset 274
a228f3c7808a
parent 273
c5b7a4c717a6
child 275
c077b20ad59f

plugins.carbons: Update to XEP v0.6. Check that messages are from your bare jid.

plugins/carbons.lua file | annotate | diff | comparison | revisions
--- a/plugins/carbons.lua	Fri Jan 06 16:54:10 2012 +0100
+++ b/plugins/carbons.lua	Tue Jan 10 21:08:19 2012 +0100
@@ -4,6 +4,7 @@
 local xmlns_forward = "urn:xmpp:forward:0";
 local os_date = os.date;
 local datetime = function(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end
+local bare_jid = require "util.jid".bare;
 
 -- TODO Check disco for support
 
@@ -40,15 +41,18 @@
 		end or nil);
 	end
 
+	local my_bare;
+	stream:hook("bind-success", function()
+		my_bare = bare_jid(stream.jid);
+	end);
+
 	stream:hook("message", function(stanza)
-		stream:debug(stanza);
-		local fwd = stanza:get_child("forwarded", xmlns_forward);
-		if fwd then
-			local carbon_dir = fwd:get_child(nil, xmlns_carbons);
+		local carbon_dir = fwd:get_child(nil, xmlns_carbons);
+		if stanza.attr.from == my_bare and carbon_dir then
 			carbon_dir = carbon_dir and carbon_dir.name;
-			if carbon_dir then
-				local fwd_stanza = fwd:get_child("message", "jabber:client");
-				assert(fwd_stanza, "No stanza included.\n"..tostring(stanza).."\n--\n"..tostring(fwd_stanza));
+			local fwd = stanza:get_child("forwarded", xmlns_forward);
+			local fwd_stanza = fwd and fwd:get_child("message", "jabber:client");
+			if fwd_stanza then
 				return stream:event("carbon", {
 					dir = carbon_dir,
 					stanza = fwd_stanza,

mercurial