Software /
code /
verse
Comparison
plugins/vcard_update.lua @ 229:279c0e89c3b3
plugins.vcard_update: Update for util.vcard changes.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Nov 2011 20:38:15 +0100 |
parent | 196:eb9d69d3f0b5 |
child | 244:6dbd61ecd5d0 |
comparison
equal
deleted
inserted
replaced
228:c5a4f82e2fd6 | 229:279c0e89c3b3 |
---|---|
29 | 29 |
30 | 30 |
31 local x_vcard_update; | 31 local x_vcard_update; |
32 | 32 |
33 function update_vcard_photo(vCard) | 33 function update_vcard_photo(vCard) |
34 local photo = vCard and vCard:get_child("PHOTO"); | 34 local data; |
35 local binval = photo and photo:get_child("BINVAL"); | 35 for i=1,#vCard do |
36 local data = binval and binval:get_text(); | 36 if vCard[i].name == "PHOTO" then |
37 data = vCard[i][1]; | |
38 break | |
39 end | |
40 end | |
37 if data then | 41 if data then |
38 local hash = sha1(unb64(data), true); | 42 local hash = sha1(unb64(data), true); |
39 x_vcard_update = verse.stanza("x", { xmlns = xmlns_vcard_update }) | 43 x_vcard_update = verse.stanza("x", { xmlns = xmlns_vcard_update }) |
40 :tag("photo"):text(hash); | 44 :tag("photo"):text(hash); |
41 | 45 |
42 stream:resend_presence() | 46 stream:resend_presence() |
43 else | 47 else |
44 x_vcard_update = nil; | 48 x_vcard_update = nil; |
45 end | 49 end |
68 stream:hook("ready", function(event) | 72 stream:hook("ready", function(event) |
69 if initial_vcard_fetch_started then return; end | 73 if initial_vcard_fetch_started then return; end |
70 initial_vcard_fetch_started = true; | 74 initial_vcard_fetch_started = true; |
71 -- if stream:jid_supports(nil, xmlns_vcard) then TODO this, correctly | 75 -- if stream:jid_supports(nil, xmlns_vcard) then TODO this, correctly |
72 stream:get_vcard(nil, function(response) | 76 stream:get_vcard(nil, function(response) |
73 -- FIXME Picking out the vCard element should be done in get_vcard() | 77 if response then |
74 if response.attr.type == "result" then | 78 update_vcard_photo(response) |
75 local vCard = response:get_child("vCard", xmlns_vcard); | |
76 if vCard then | |
77 update_vcard_photo(vCard); | |
78 end | |
79 end | 79 end |
80 stream:event("ready"); | 80 stream:event("ready"); |
81 end); | 81 end); |
82 return true; | 82 return true; |
83 end, 3); | 83 end, 3); |