Commit 1c242a58 authored by Pierre de Lacroix's avatar Pierre de Lacroix

mod_happydev_vcard: Fix JSON parsing

parent 321a693f
......@@ -24,45 +24,42 @@ local function nilnull(v)
return v;
end
local function convert_ld_to_vcard(ld_data, avatar)
local function convert_ld_to_vcard(user, avatar)
local vcard = st.stanza("vCard", { xmlns = "vcard-temp" });
local user = ld_data.user;
if user then
vcard:tag("FN"):text(user.first_name.." "..user.last_name):up();
vcard:tag("N")
:tag("FAMILY"):text(user.last_name):up()
:tag("GIVEN"):text(user.first_name):up()
:tag("MIDDLE"):up()
:up();
vcard:tag("NICKNAME"):text(user.username):up();
vcard:tag("EMAIL"):tag("USERID"):text(user.email):up():up();
if nilnull(user.member.chatProfile) and type(user.member.chatProfile.jabberID) == "string" then
vcard:tag("JABBERID"):text(user.member.chatProfile.jabberID):up();
end
if user.member.bio and user.member.bio ~= json.null then
vcard:tag("DESC"):text(user.member.bio):up();
end
if user.member.website and user.member.website ~= json.null then
vcard:tag("URL"):text(user.member.website):up();
end
vcard:tag("FN"):text(user.first_name.." "..user.last_name):up();
vcard:tag("N")
:tag("FAMILY"):text(user.last_name):up()
:tag("GIVEN"):text(user.first_name):up()
:tag("MIDDLE"):up()
:up();
vcard:tag("NICKNAME"):text(user.username):up();
vcard:tag("EMAIL"):tag("USERID"):text(user.email):up():up();
if nilnull(user.chatProfile) and type(user.chatProfile.jabberID) == "string" then
vcard:tag("JABBERID"):text(user.chatProfile.jabberID):up();
end
if user.profile.bio and user.profile.bio ~= json.null then
vcard:tag("DESC"):text(user.profile.bio):up();
end
if user.profile.website and user.profile.website ~= json.null then
vcard:tag("URL"):text(user.profile.website):up();
end
local roles = {};
if ld_data.roles and ld_data.roles ~= json.null then
for _, role_info in ipairs(ld_data.roles["ldp:contains"]) do
if role_info.name and role_info.name ~= json.null then
table.insert(roles, role_info.name);
end
local roles = {};
if ld_data.roles and ld_data.roles ~= json.null then
for _, role_info in ipairs(ld_data.roles["ldp:contains"]) do
if role_info.name and role_info.name ~= json.null then
table.insert(roles, role_info.name);
end
end
vcard:tag("ROLE"):text(table.concat(roles, ", ")):up();
vcard:tag("UID"):text(ld_data["@id"]):up();
if avatar then
vcard:tag("PHOTO")
:tag("TYPE"):text(avatar.type or "application/octet-stream"):up()
:tag("BINVAL"):text(b64.encode(avatar.data)):up()
:up();
end
end
vcard:tag("ROLE"):text(table.concat(roles, ", ")):up();
vcard:tag("UID"):text(ld_data["@id"]):up();
if avatar then
vcard:tag("PHOTO")
:tag("TYPE"):text(avatar.type or "application/octet-stream"):up()
:tag("BINVAL"):text(b64.encode(avatar.data)):up()
:up();
end
return vcard;
end
......@@ -78,7 +75,7 @@ function get_xmpp_vcard(url, cb)
cb(nil, "failed to parse JSON");
return;
end
local avatar_url = ld_data.avatar;
local avatar_url = ld_data.account.picture;
local function on_avatar_available(avatar)
local ok, vcard = pcall(convert_ld_to_vcard, ld_data, avatar);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment