Comparison

plugins/vcard_update.lua @ 395:e86144a4eaa1

plugins: Cleanup [luacheck]
author Kim Alvefur <zash@zash.se>
date Thu, 03 Sep 2015 22:41:27 +0200
parent 392:cdea6a28369e
child 490:6b2f31da9610
comparison
equal deleted inserted replaced
394:c2e959b60c13 395:e86144a4eaa1
1 local verse = require "verse"; 1 local verse = require "verse";
2 2
3 local xmlns_vcard, xmlns_vcard_update = "vcard-temp", "vcard-temp:x:update"; 3 -- local xmlns_vcard = "vcard-temp";
4 local xmlns_vcard_update = "vcard-temp:x:update";
4 5
5 local sha1 = require("util.hashes").sha1; 6 local sha1 = require("util.hashes").sha1;
6 7
7 local ok, fun = pcall(function() 8 local ok, fun = pcall(function()
8 local unb64 = require("util.encodings").base64.decode; 9 local unb64 = require("util.encodings").base64.decode;
22 stream:add_plugin("presence"); 23 stream:add_plugin("presence");
23 24
24 25
25 local x_vcard_update; 26 local x_vcard_update;
26 27
27 function update_vcard_photo(vCard) 28 local function update_vcard_photo(vCard)
28 local data; 29 local data;
29 for i=1,#vCard do 30 for i=1,#vCard do
30 if vCard[i].name == "PHOTO" then 31 if vCard[i].name == "PHOTO" then
31 data = vCard[i][1]; 32 data = vCard[i][1];
32 break 33 break
41 else 42 else
42 x_vcard_update = nil; 43 x_vcard_update = nil;
43 end 44 end
44 end 45 end
45 46
46 local _set_vcard = stream.set_vcard;
47 47
48 --[[ TODO Complete this, it's probably broken. 48 --[[ TODO Complete this, it's probably broken.
49 -- Maybe better to hook outgoing stanza? 49 -- Maybe better to hook outgoing stanza?
50 local _set_vcard = stream.set_vcard;
50 function stream:set_vcard(vCard, callback) 51 function stream:set_vcard(vCard, callback)
51 _set_vcard(vCard, function(event, ...) 52 _set_vcard(vCard, function(event, ...)
52 if event.attr.type == "result" then 53 if event.attr.type == "result" then
53 local vCard_ = response:get_child("vCard", xmlns_vcard); 54 local vCard_ = response:get_child("vCard", xmlns_vcard);
54 if vCard_ then 55 if vCard_ then
61 end); 62 end);
62 end 63 end
63 --]] 64 --]]
64 65
65 local initial_vcard_fetch_started; 66 local initial_vcard_fetch_started;
66 stream:hook("ready", function(event) 67 stream:hook("ready", function()
67 if initial_vcard_fetch_started then return; end 68 if initial_vcard_fetch_started then return; end
68 initial_vcard_fetch_started = true; 69 initial_vcard_fetch_started = true;
69 -- if stream:jid_supports(nil, xmlns_vcard) then TODO this, correctly 70 -- if stream:jid_supports(nil, xmlns_vcard) then TODO this, correctly
70 stream:get_vcard(nil, function(response) 71 stream:get_vcard(nil, function(response)
71 if response then 72 if response then