comparison mod_default_vcard/mod_default_vcard.lua @ 936:7236cdec3ea1

mod_default_vcard: Guess FN from FIRST + LAST and vice versa
author Kim Alvefur <zash@zash.se>
date Mon, 25 Mar 2013 00:44:54 +0100
parents 52f2188ec47d
children
comparison
equal deleted inserted replaced
935:f66a08f208ad 936:7236cdec3ea1
7 local data = datamanager.load(username, host, "account_details"); 7 local data = datamanager.load(username, host, "account_details");
8 local vcard = datamanager.load(username, host, "vcard"); 8 local vcard = datamanager.load(username, host, "vcard");
9 --module:log("debug", "Has account details: %s", data and "yes" or "no"); 9 --module:log("debug", "Has account details: %s", data and "yes" or "no");
10 --module:log("debug", "Has vCard: %s", vcard and "yes" or "no"); 10 --module:log("debug", "Has vCard: %s", vcard and "yes" or "no");
11 if data and not vcard then 11 if data and not vcard then
12 -- MAYBE 12 local name, first, last = data.name, data.first, data.last;
13 -- first .. " " .. last 13 if not name and (first and last) then
14 -- first, last = name:match("^(%w+) (%w+)$") 14 name = first .. " " .. last;
15 elseif name and not (first and last) then
16 first, last = name:match("^(%w+)%s+(%w+)$")
17 end
15 local vcard = st.stanza("vCard", { xmlns = "vcard-temp" }) 18 local vcard = st.stanza("vCard", { xmlns = "vcard-temp" })
16 :tag("VERSION"):text("3.0"):up() 19 :tag("VERSION"):text("3.0"):up();
17 :tag("N") 20 if first or last then
18 :tag("FAMILY"):text(data.last or ""):up() 21 vcard:tag("N")
19 :tag("GIVEN"):text(data.first or ""):up() 22 :tag("FAMILY"):text(last or ""):up()
23 :tag("GIVEN"):text(first or ""):up()
20 :up() 24 :up()
21 :tag("FN"):text(data.name or ""):up() 25 end
22 :tag("NICKNAME"):text(data.nick or username):up(); 26 if name then
27 vcard:tag("FN"):text(name or ""):up()
28 end
29 vcard:tag("NICKNAME"):text(data.nick or username):up();
30 if data.email then
31 vcard:tag("EMAIL"):tag("USERID"):text(data.email):up():up();
32 end
23 local ok, err = datamanager.store(username, host, "vcard", st.preserialize(vcard)); 33 local ok, err = datamanager.store(username, host, "vcard", st.preserialize(vcard));
24 if not ok then 34 if not ok then
25 module:log("error", "Couldn't save vCard data, %s", err); 35 module:log("error", "Couldn't save vCard data, %s", err);
26 end 36 end
27 end 37 end