plugins.vcard_update: Update for util.vcard changes.

Sun, 06 Nov 2011 20:38:15 +0100

author
Kim Alvefur <zash@zash.se>
date
Sun, 06 Nov 2011 20:38:15 +0100
changeset 229
279c0e89c3b3
parent 228
c5a4f82e2fd6
child 230
44a6da432e7e

plugins.vcard_update: Update for util.vcard changes.

plugins/vcard_update.lua file | annotate | diff | comparison | revisions
--- a/plugins/vcard_update.lua	Sun Nov 06 20:04:19 2011 +0100
+++ b/plugins/vcard_update.lua	Sun Nov 06 20:38:15 2011 +0100
@@ -31,13 +31,17 @@
 	local x_vcard_update;
 
 	function update_vcard_photo(vCard) 
-		local photo = vCard and vCard:get_child("PHOTO");
-		local binval = photo and photo:get_child("BINVAL");
-		local data = binval and binval:get_text();
+		local data;
+		for i=1,#vCard do
+			if vCard[i].name == "PHOTO" then
+				data = vCard[i][1];
+				break
+			end
+		end
 		if data then
 			local hash = sha1(unb64(data), true);
 			x_vcard_update = verse.stanza("x", { xmlns = xmlns_vcard_update })
-				:tag("photo"):text(hash);
+			:tag("photo"):text(hash);
 
 			stream:resend_presence()
 		else
@@ -70,12 +74,8 @@
 		initial_vcard_fetch_started = true;
 		-- if stream:jid_supports(nil, xmlns_vcard) then TODO this, correctly
 		stream:get_vcard(nil, function(response)
-			-- FIXME Picking out the vCard element should be done in get_vcard()
-			if response.attr.type == "result" then
-				local vCard = response:get_child("vCard", xmlns_vcard);
-				if vCard then
-					update_vcard_photo(vCard);
-				end
+			if response then
+				update_vcard_photo(response)
 			end
 			stream:event("ready");
 		end);

mercurial