Software /
code /
prosody
Annotate
plugins/mod_vcard_legacy.lua @ 13014:06453c564141
util.startup: Add prosody.started promise to easily execute code after startup
To avoid a race where server-started fires before the promise function body is
run (on next tick), I moved server-started to fire on the next tick, which
seems sensible anyway.
Errors are logged, I'm not sure if we ought to be doing something more here.
I'm sure we'll find out.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 01 Apr 2023 11:56:38 +0100 |
parent | 12977:74b9e05af71e |
rev | line source |
---|---|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11944
diff
changeset
|
1 local st = require "prosody.util.stanza"; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11944
diff
changeset
|
2 local jid_split = require "prosody.util.jid".split; |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local mod_pep = module:depends("pep"); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11944
diff
changeset
|
6 local sha1 = require "prosody.util.hashes".sha1; |
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
11944
diff
changeset
|
7 local base64_decode = require "prosody.util.encodings".base64.decode; |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
8 |
9256
12d3d96e3918
mod_vcard_legacy: Respond with old vcard
Kim Alvefur <zash@zash.se>
parents:
9255
diff
changeset
|
9 local vcards = module:open_store("vcard"); |
12d3d96e3918
mod_vcard_legacy: Respond with old vcard
Kim Alvefur <zash@zash.se>
parents:
9255
diff
changeset
|
10 |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 module:add_feature("vcard-temp"); |
9260
0fc6ffc57dc0
mod_vcard_legacy: Announce feature on bare JID per XEP
Kim Alvefur <zash@zash.se>
parents:
9259
diff
changeset
|
12 module:hook("account-disco-info", function (event) |
0fc6ffc57dc0
mod_vcard_legacy: Announce feature on bare JID per XEP
Kim Alvefur <zash@zash.se>
parents:
9259
diff
changeset
|
13 event.reply:tag("feature", { var = "urn:xmpp:pep-vcard-conversion:0" }):up(); |
0fc6ffc57dc0
mod_vcard_legacy: Announce feature on bare JID per XEP
Kim Alvefur <zash@zash.se>
parents:
9259
diff
changeset
|
14 end); |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
9268
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
16 local function handle_error(origin, stanza, err) |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
17 if err == "forbidden" then |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
18 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
19 elseif err == "internal-server-error" then |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
20 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
21 else |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
22 origin.send(st.error_reply(stanza, "modify", "undefined-condition", err)); |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
23 end |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
24 end |
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
25 |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 -- Simple translations |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 -- <foo><text>hey</text></foo> -> <FOO>hey</FOO> |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 local simple_map = { |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 nickname = "text"; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 title = "text"; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 role = "text"; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 categories = "text"; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 note = "text"; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 url = "uri"; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 bday = "date"; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 } |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 module:hook("iq-get/bare/vcard-temp:vCard", function (event) |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 local origin, stanza = event.origin, event.stanza; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 local pep_service = mod_pep.get_pep_service(jid_split(stanza.attr.to) or origin.username); |
10549
3e50f86e5a2e
mod_vcard_legacy: Ignore an unused variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10270
diff
changeset
|
41 local ok, _, vcard4_item = pep_service:get_last_item("urn:xmpp:vcard4", stanza.attr.from); |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 local vcard_temp = st.stanza("vCard", { xmlns = "vcard-temp" }); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 if ok and vcard4_item then |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 local vcard4 = vcard4_item.tags[1]; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 local fn = vcard4:get_child("fn"); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 vcard_temp:text_tag("FN", fn and fn:get_child_text("text")); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 local v4n = vcard4:get_child("n"); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 vcard_temp:tag("N") |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 :text_tag("FAMILY", v4n and v4n:get_child_text("surname")) |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 :text_tag("GIVEN", v4n and v4n:get_child_text("given")) |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 :text_tag("MIDDLE", v4n and v4n:get_child_text("additional")) |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 :text_tag("PREFIX", v4n and v4n:get_child_text("prefix")) |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 :text_tag("SUFFIX", v4n and v4n:get_child_text("suffix")) |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 :up(); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 for tag in vcard4:childtags() do |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 local typ = simple_map[tag.name]; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 if typ then |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 local text = tag:get_child_text(typ); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 if text then |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 vcard_temp:text_tag(tag.name:upper(), text); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 end |
9251
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
66 elseif tag.name == "email" then |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
67 local text = tag:get_child_text("text"); |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
68 if text then |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
69 vcard_temp:tag("EMAIL") |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
70 :text_tag("USERID", text) |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
71 :tag("INTERNET"):up(); |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
72 if tag:find"parameters/type/text#" == "home" then |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
73 vcard_temp:tag("HOME"):up(); |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
74 elseif tag:find"parameters/type/text#" == "work" then |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
75 vcard_temp:tag("WORK"):up(); |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
76 end |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
77 vcard_temp:up(); |
3f31e10e8256
mod_vcard_legacy: Add translation of email field
Kim Alvefur <zash@zash.se>
parents:
9250
diff
changeset
|
78 end |
9252
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
79 elseif tag.name == "tel" then |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
80 local text = tag:get_child_text("uri"); |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
81 if text then |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
82 if text:sub(1, 4) == "tel:" then |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
83 text = text:sub(5) |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
84 end |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
85 vcard_temp:tag("TEL"):text_tag("NUMBER", text); |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
86 if tag:find"parameters/type/text#" == "home" then |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
87 vcard_temp:tag("HOME"):up(); |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
88 elseif tag:find"parameters/type/text#" == "work" then |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
89 vcard_temp:tag("WORK"):up(); |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
90 end |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
91 vcard_temp:up(); |
292d283c7694
mod_vcard_legacy: Add translation of telephone field
Kim Alvefur <zash@zash.se>
parents:
9251
diff
changeset
|
92 end |
9254
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
93 elseif tag.name == "adr" then |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
94 vcard_temp:tag("ADR") |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
95 :text_tag("POBOX", tag:get_child_text("pobox")) |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
96 :text_tag("EXTADD", tag:get_child_text("ext")) |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
97 :text_tag("STREET", tag:get_child_text("street")) |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
98 :text_tag("LOCALITY", tag:get_child_text("locality")) |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
99 :text_tag("REGION", tag:get_child_text("region")) |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
100 :text_tag("PCODE", tag:get_child_text("code")) |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
101 :text_tag("CTRY", tag:get_child_text("country")); |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
102 if tag:find"parameters/type/text#" == "home" then |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
103 vcard_temp:tag("HOME"):up(); |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
104 elseif tag:find"parameters/type/text#" == "work" then |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
105 vcard_temp:tag("WORK"):up(); |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
106 end |
2ffbcad8ec50
mod_vcard_legacy: Add support for address field
Kim Alvefur <zash@zash.se>
parents:
9253
diff
changeset
|
107 vcard_temp:up(); |
10117
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
108 elseif tag.name == "impp" then |
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
109 local uri = tag:get_child_text("uri"); |
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
110 if uri and uri:sub(1, 5) == "xmpp:" then |
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
111 vcard_temp:text_tag("JABBERID", uri:sub(6)) |
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
112 end |
10118
199dae5b6f11
mod_vcard_legacy: Complete roundtrip support for ORG/ORGNAME
Kim Alvefur <zash@zash.se>
parents:
10117
diff
changeset
|
113 elseif tag.name == "org" then |
199dae5b6f11
mod_vcard_legacy: Complete roundtrip support for ORG/ORGNAME
Kim Alvefur <zash@zash.se>
parents:
10117
diff
changeset
|
114 vcard_temp:tag("ORG") |
199dae5b6f11
mod_vcard_legacy: Complete roundtrip support for ORG/ORGNAME
Kim Alvefur <zash@zash.se>
parents:
10117
diff
changeset
|
115 :text_tag("ORGNAME", tag:get_child_text("text")) |
199dae5b6f11
mod_vcard_legacy: Complete roundtrip support for ORG/ORGNAME
Kim Alvefur <zash@zash.se>
parents:
10117
diff
changeset
|
116 :up(); |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 end |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 end |
10215
82abf88db13f
mod_vcard_legacy: Use PEP nickname if vcard4 data is unavailable
Kim Alvefur <zash@zash.se>
parents:
10118
diff
changeset
|
119 else |
82abf88db13f
mod_vcard_legacy: Use PEP nickname if vcard4 data is unavailable
Kim Alvefur <zash@zash.se>
parents:
10118
diff
changeset
|
120 local ok, _, nick_item = pep_service:get_last_item("http://jabber.org/protocol/nick", stanza.attr.from); |
82abf88db13f
mod_vcard_legacy: Use PEP nickname if vcard4 data is unavailable
Kim Alvefur <zash@zash.se>
parents:
10118
diff
changeset
|
121 if ok and nick_item then |
82abf88db13f
mod_vcard_legacy: Use PEP nickname if vcard4 data is unavailable
Kim Alvefur <zash@zash.se>
parents:
10118
diff
changeset
|
122 local nickname = nick_item:get_child_text("nick", "http://jabber.org/protocol/nick"); |
82abf88db13f
mod_vcard_legacy: Use PEP nickname if vcard4 data is unavailable
Kim Alvefur <zash@zash.se>
parents:
10118
diff
changeset
|
123 if nickname then |
82abf88db13f
mod_vcard_legacy: Use PEP nickname if vcard4 data is unavailable
Kim Alvefur <zash@zash.se>
parents:
10118
diff
changeset
|
124 vcard_temp:text_tag("NICKNAME", nickname); |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 end |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 end |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 end |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 |
11944
8b5e646dfaa6
mod_vcard_legacy: Also respect avatar:metadata access restrictions
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
10865
diff
changeset
|
129 local ok, avatar_hash, meta = pep_service:get_last_item("urn:xmpp:avatar:metadata", stanza.attr.from); |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
130 if ok and avatar_hash then |
9273
f2258e9750cf
mod_vcard_legacy: Include avatar data even if metadata can't be loaded
Kim Alvefur <zash@zash.se>
parents:
9272
diff
changeset
|
131 |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
132 local info = meta.tags[1]:get_child("info"); |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
133 if info then |
9257
05bd21c122ae
mod_vcard_legacy: Handle incomplete avatar info
Kim Alvefur <zash@zash.se>
parents:
9256
diff
changeset
|
134 vcard_temp:tag("PHOTO"); |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
135 |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
136 if info.attr.type then |
9257
05bd21c122ae
mod_vcard_legacy: Handle incomplete avatar info
Kim Alvefur <zash@zash.se>
parents:
9256
diff
changeset
|
137 vcard_temp:text_tag("TYPE", info.attr.type); |
05bd21c122ae
mod_vcard_legacy: Handle incomplete avatar info
Kim Alvefur <zash@zash.se>
parents:
9256
diff
changeset
|
138 end |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
139 |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
140 if info.attr.url then |
9285
78673e81243f
mod_vcard_legacy: Fix EXTVAL conversion (thanks pep.)
Kim Alvefur <zash@zash.se>
parents:
9284
diff
changeset
|
141 vcard_temp:text_tag("EXTVAL", info.attr.url); |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
142 elseif info.attr.id then |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
143 local data_ok, avatar_data = pep_service:get_items("urn:xmpp:avatar:data", stanza.attr.from, { info.attr.id }); |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
144 if data_ok and avatar_data and avatar_data[info.attr.id] then |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
145 local data = avatar_data[info.attr.id]; |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
146 vcard_temp:text_tag("BINVAL", data.tags[1]:get_text()); |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
147 end |
9257
05bd21c122ae
mod_vcard_legacy: Handle incomplete avatar info
Kim Alvefur <zash@zash.se>
parents:
9256
diff
changeset
|
148 end |
05bd21c122ae
mod_vcard_legacy: Handle incomplete avatar info
Kim Alvefur <zash@zash.se>
parents:
9256
diff
changeset
|
149 vcard_temp:up(); |
9253
dbe3ae6f9746
mod_vcard_legacy: Include avatar data from XEP-0084 PEP node
Kim Alvefur <zash@zash.se>
parents:
9252
diff
changeset
|
150 end |
dbe3ae6f9746
mod_vcard_legacy: Include avatar data from XEP-0084 PEP node
Kim Alvefur <zash@zash.se>
parents:
9252
diff
changeset
|
151 end |
dbe3ae6f9746
mod_vcard_legacy: Include avatar data from XEP-0084 PEP node
Kim Alvefur <zash@zash.se>
parents:
9252
diff
changeset
|
152 |
9249
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 origin.send(st.reply(stanza):add_child(vcard_temp)); |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 return true; |
506aabdb13bc
mod_vcard_legacy: Responds to vcard-temp queries with translated vcard4 data
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 end); |
9250
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
156 |
9518
a62fa766d8f3
mod_vcard_legacy: Create nodes with open access (fixes #1221)
Kim Alvefur <zash@zash.se>
parents:
9286
diff
changeset
|
157 local node_defaults = { |
a62fa766d8f3
mod_vcard_legacy: Create nodes with open access (fixes #1221)
Kim Alvefur <zash@zash.se>
parents:
9286
diff
changeset
|
158 access_model = "open"; |
a62fa766d8f3
mod_vcard_legacy: Create nodes with open access (fixes #1221)
Kim Alvefur <zash@zash.se>
parents:
9286
diff
changeset
|
159 _defaults_only = true; |
a62fa766d8f3
mod_vcard_legacy: Create nodes with open access (fixes #1221)
Kim Alvefur <zash@zash.se>
parents:
9286
diff
changeset
|
160 }; |
a62fa766d8f3
mod_vcard_legacy: Create nodes with open access (fixes #1221)
Kim Alvefur <zash@zash.se>
parents:
9286
diff
changeset
|
161 |
9808
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
162 function vcard_to_pep(vcard_temp) |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
163 local avatar = {}; |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
164 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
165 local vcard4 = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" }) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
166 :tag("vcard", { xmlns = 'urn:ietf:params:xml:ns:vcard-4.0' }); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
167 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
168 vcard4:tag("fn"):text_tag("text", vcard_temp:get_child_text("FN")):up(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
169 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
170 local N = vcard_temp:get_child("N"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
171 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
172 vcard4:tag("n") |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
173 :text_tag("surname", N and N:get_child_text("FAMILY")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
174 :text_tag("given", N and N:get_child_text("GIVEN")) |
9284
161f604e14fa
mod_vcard_legacy: Fix uppercase tag name (thanks pep.)
Kim Alvefur <zash@zash.se>
parents:
9273
diff
changeset
|
175 :text_tag("additional", N and N:get_child_text("MIDDLE")) |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
176 :text_tag("prefix", N and N:get_child_text("PREFIX")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
177 :text_tag("suffix", N and N:get_child_text("SUFFIX")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
178 :up(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
179 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
180 for tag in vcard_temp:childtags() do |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
181 local typ = simple_map[tag.name:lower()]; |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
182 if typ then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
183 local text = tag:get_text(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
184 if text then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
185 vcard4:tag(tag.name:lower()):text_tag(typ, text):up(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
186 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
187 elseif tag.name == "EMAIL" then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
188 local text = tag:get_child_text("USERID"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
189 if text then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
190 vcard4:tag("email") |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
191 vcard4:text_tag("text", text) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
192 vcard4:tag("parameters"):tag("type"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
193 if tag:get_child("HOME") then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
194 vcard4:text_tag("text", "home"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
195 elseif tag:get_child("WORK") then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
196 vcard4:text_tag("text", "work"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
197 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
198 vcard4:up():up():up(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
199 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
200 elseif tag.name == "TEL" then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
201 local text = tag:get_child_text("NUMBER"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
202 if text then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
203 vcard4:tag("tel"):text_tag("uri", "tel:"..text); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
204 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
205 vcard4:tag("parameters"):tag("type"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
206 if tag:get_child("HOME") then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
207 vcard4:text_tag("text", "home"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
208 elseif tag:get_child("WORK") then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
209 vcard4:text_tag("text", "work"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
210 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
211 vcard4:up():up():up(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
212 elseif tag.name == "ORG" then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
213 local text = tag:get_child_text("ORGNAME"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
214 if text then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
215 vcard4:tag("org"):text_tag("text", text):up(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
216 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
217 elseif tag.name == "DESC" then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
218 local text = tag:get_text(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
219 if text then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
220 vcard4:tag("note"):text_tag("text", text):up(); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
221 end |
9286
992e986589b8
mod_vcard_legacy: Add some notes
Kim Alvefur <zash@zash.se>
parents:
9285
diff
changeset
|
222 -- <note> gets mapped into <NOTE> in the other direction |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
223 elseif tag.name == "ADR" then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
224 vcard4:tag("adr") |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
225 :text_tag("pobox", tag:get_child_text("POBOX")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
226 :text_tag("ext", tag:get_child_text("EXTADD")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
227 :text_tag("street", tag:get_child_text("STREET")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
228 :text_tag("locality", tag:get_child_text("LOCALITY")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
229 :text_tag("region", tag:get_child_text("REGION")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
230 :text_tag("code", tag:get_child_text("PCODE")) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
231 :text_tag("country", tag:get_child_text("CTRY")); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
232 vcard4:tag("parameters"):tag("type"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
233 if tag:get_child("HOME") then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
234 vcard4:text_tag("text", "home"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
235 elseif tag:get_child("WORK") then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
236 vcard4:text_tag("text", "work"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
237 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
238 vcard4:up():up():up(); |
10117
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
239 elseif tag.name == "JABBERID" then |
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
240 vcard4:tag("impp") |
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
241 :text_tag("uri", "xmpp:" .. tag:get_text()) |
8643b784626c
mod_vcard_legacy: Add support for JABBERID - impp/uri conversion
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
242 :up(); |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
243 elseif tag.name == "PHOTO" then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
244 local avatar_type = tag:get_child_text("TYPE"); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
245 local avatar_payload = tag:get_child_text("BINVAL"); |
9286
992e986589b8
mod_vcard_legacy: Add some notes
Kim Alvefur <zash@zash.se>
parents:
9285
diff
changeset
|
246 -- Can EXTVAL be translated? No way to know the sha1 of the data? |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
247 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
248 if avatar_payload then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
249 local avatar_raw = base64_decode(avatar_payload); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
250 local avatar_hash = sha1(avatar_raw, true); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
251 |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
252 avatar.hash = avatar_hash; |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
253 |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
254 avatar.meta = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" }) |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
255 :tag("metadata", { xmlns="urn:xmpp:avatar:metadata" }) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
256 :tag("info", { |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
257 bytes = tostring(#avatar_raw), |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
258 id = avatar_hash, |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
259 type = avatar_type, |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
260 }); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
261 |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
262 avatar.data = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" }) |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
263 :tag("data", { xmlns="urn:xmpp:avatar:data" }) |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
264 :text(avatar_payload); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
265 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
266 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
267 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
268 end |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
269 return vcard4, avatar; |
9808
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
270 end |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
271 |
10864
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
272 function save_to_pep(pep_service, actor, vcard4, avatar) |
1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Kim Alvefur <zash@zash.se>
parents:
10549
diff
changeset
|
273 if avatar then |
9808
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
274 |
9814
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
275 if pep_service:purge("urn:xmpp:avatar:metadata", actor) then |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
276 pep_service:purge("urn:xmpp:avatar:data", actor); |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
277 end |
9808
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
278 |
10865
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
279 if avatar.data and avatar.meta then |
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
280 local ok, err = assert(pep_service:publish("urn:xmpp:avatar:data", actor, avatar.hash, avatar.data, node_defaults)); |
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
281 if ok then |
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
282 ok, err = assert(pep_service:publish("urn:xmpp:avatar:metadata", actor, avatar.hash, avatar.meta, node_defaults)); |
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
283 end |
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
284 if not ok then |
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
285 return ok, err; |
9c27b2385fad
mod_vcard_legacy: Fix publishing vcard without avatar
Kim Alvefur <zash@zash.se>
parents:
10864
diff
changeset
|
286 end |
9808
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
287 end |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
288 end |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
289 |
9814
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
290 if vcard4 then |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
291 return pep_service:publish("urn:xmpp:vcard4", actor, "current", vcard4, node_defaults); |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
292 end |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
293 |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
294 return true; |
9808
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
295 end |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
296 |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
297 module:hook("iq-set/self/vcard-temp:vCard", function (event) |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
298 local origin, stanza = event.origin, event.stanza; |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
299 local pep_service = mod_pep.get_pep_service(origin.username); |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
300 |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
301 local vcard_temp = stanza.tags[1]; |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
302 |
00d210deea28
mod_vcard_legacy: Factor out conversion from vcard-temp to 4
Kim Alvefur <zash@zash.se>
parents:
9672
diff
changeset
|
303 local ok, err = save_to_pep(pep_service, origin.full_jid, vcard_to_pep(vcard_temp)); |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
304 if ok then |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
305 origin.send(st.reply(stanza)); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
306 else |
9268
628b99811301
mod_vcard_legacy: Factor out error handling into a function
Kim Alvefur <zash@zash.se>
parents:
9267
diff
changeset
|
307 handle_error(origin, stanza, err); |
9255
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
308 end |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
309 |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
310 return true; |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
311 end); |
2aa40526df7b
mod_vcard_legacy: Respond to attempts to set the legacy vcard-temp
Kim Alvefur <zash@zash.se>
parents:
9254
diff
changeset
|
312 |
9250
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
313 local function inject_xep153(event) |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
314 local origin, stanza = event.origin, event.stanza; |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
315 local username = origin.username; |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
316 if not username then return end |
9672
e71484c210fb
mod_vcard_legacy: Limit injection of XEP-0153 to normal presence (fixes #1252)
Kim Alvefur <zash@zash.se>
parents:
9520
diff
changeset
|
317 if stanza.attr.type then return end |
9270
b024fae6919e
mod_vcard_legacy: Rename variable for consistency
Kim Alvefur <zash@zash.se>
parents:
9269
diff
changeset
|
318 local pep_service = mod_pep.get_pep_service(username); |
9250
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
319 |
10269
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
320 local x_update = stanza:get_child("x", "vcard-temp:x:update"); |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
321 if not x_update then |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
322 x_update = st.stanza("x", { xmlns = "vcard-temp:x:update" }):tag("photo"); |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
323 stanza:add_direct_child(x_update); |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
324 elseif x_update:get_child("photo") then |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
325 return; -- XEP implies that these should be left alone |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
326 else |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
327 x_update:tag("photo"); |
4701415f5b0e
mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
Kim Alvefur <zash@zash.se>
parents:
10268
diff
changeset
|
328 end |
9270
b024fae6919e
mod_vcard_legacy: Rename variable for consistency
Kim Alvefur <zash@zash.se>
parents:
9269
diff
changeset
|
329 local ok, avatar_hash = pep_service:get_last_item("urn:xmpp:avatar:metadata", true); |
9250
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
330 if ok and avatar_hash then |
10268
210278d5f995
mod_vcard_legacy: Advertise lack of avatar correctly (fixes #1431) (thanks lovetox)
Kim Alvefur <zash@zash.se>
parents:
9814
diff
changeset
|
331 x_update:text(avatar_hash); |
9250
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
332 end |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
333 end |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
334 |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
335 module:hook("pre-presence/full", inject_xep153, 1); |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
336 module:hook("pre-presence/bare", inject_xep153, 1); |
9a8006f9e983
mod_vcard_legacy: Attach vcard-temp avatar hash to outgoing presence
Kim Alvefur <zash@zash.se>
parents:
9249
diff
changeset
|
337 module:hook("pre-presence/host", inject_xep153, 1); |
9810
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
338 |
9813
071aaaa5cb34
mod_vcard_legacy: Allow disabling vcard conversion
Kim Alvefur <zash@zash.se>
parents:
9812
diff
changeset
|
339 if module:get_option_boolean("upgrade_legacy_vcards", true) then |
9810
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
340 module:hook("resource-bind", function (event) |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
341 local session = event.session; |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
342 local username = session.username; |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
343 local vcard_temp = vcards:get(username); |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
344 if not vcard_temp then |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
345 session.log("debug", "No legacy vCard to migrate or already migrated"); |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
346 return; |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
347 end |
9812
330a937e085e
mod_vcard_legacy: Don't overwrite existing PEP data
Kim Alvefur <zash@zash.se>
parents:
9811
diff
changeset
|
348 local pep_service = mod_pep.get_pep_service(username); |
9814
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
349 vcard_temp = st.deserialize(vcard_temp); |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
350 local vcard4, avatars = vcard_to_pep(vcard_temp); |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
351 if pep_service:get_last_item("urn:xmpp:vcard4", true) then |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
352 vcard4 = nil; |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
353 end |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
354 if pep_service:get_last_item("urn:xmpp:avatar:metadata", true) |
9812
330a937e085e
mod_vcard_legacy: Don't overwrite existing PEP data
Kim Alvefur <zash@zash.se>
parents:
9811
diff
changeset
|
355 or pep_service:get_last_item("urn:xmpp:avatar:data", true) then |
9814
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
356 avatars = nil; |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
357 end |
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
358 if not (vcard4 or avatars) then |
9812
330a937e085e
mod_vcard_legacy: Don't overwrite existing PEP data
Kim Alvefur <zash@zash.se>
parents:
9811
diff
changeset
|
359 session.log("debug", "Already PEP data, not overwriting with migrated data"); |
330a937e085e
mod_vcard_legacy: Don't overwrite existing PEP data
Kim Alvefur <zash@zash.se>
parents:
9811
diff
changeset
|
360 vcards:set(username, nil); |
330a937e085e
mod_vcard_legacy: Don't overwrite existing PEP data
Kim Alvefur <zash@zash.se>
parents:
9811
diff
changeset
|
361 return; |
330a937e085e
mod_vcard_legacy: Don't overwrite existing PEP data
Kim Alvefur <zash@zash.se>
parents:
9811
diff
changeset
|
362 end |
9814
5eb4ef537e98
mod_vcard_legacy: Handle partial migration
Kim Alvefur <zash@zash.se>
parents:
9813
diff
changeset
|
363 local ok, err = save_to_pep(pep_service, true, vcard4, avatars); |
9810
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
364 if ok and vcards:set(username, nil) then |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
365 session.log("info", "Migrated vCard-temp to PEP"); |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
366 else |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
367 session.log("info", "Failed to migrate vCard-temp to PEP: %s", err or "problem emptying 'vcard' store"); |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
368 end |
2d8e2de36654
mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
Kim Alvefur <zash@zash.se>
parents:
9809
diff
changeset
|
369 end); |
9813
071aaaa5cb34
mod_vcard_legacy: Allow disabling vcard conversion
Kim Alvefur <zash@zash.se>
parents:
9812
diff
changeset
|
370 end |