Software /
code /
prosody
Comparison
plugins/mod_vcard_legacy.lua @ 10864:1b657605ea29
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Nobody does this. If someone wants to they should go use the PEP method
directly instead.
Additionally, this got in the way of doing multiple avatars The PEP Way,
since it treated each 'data' as a distinct avatar with an optional
corresponding 'metadata', which is not how it works.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 01 Jun 2020 17:37:54 +0200 |
parent | 10549:3e50f86e5a2e |
child | 10865:9c27b2385fad |
comparison
equal
deleted
inserted
replaced
10863:455a151db834 | 10864:1b657605ea29 |
---|---|
124 vcard_temp:text_tag("NICKNAME", nickname); | 124 vcard_temp:text_tag("NICKNAME", nickname); |
125 end | 125 end |
126 end | 126 end |
127 end | 127 end |
128 | 128 |
129 local meta_ok, avatar_meta = pep_service:get_items("urn:xmpp:avatar:metadata", stanza.attr.from); | 129 local ok, avatar_hash, meta = pep_service:get_last_item("urn:xmpp:avatar:metadata", true); |
130 local data_ok, avatar_data = pep_service:get_items("urn:xmpp:avatar:data", stanza.attr.from); | 130 if ok and avatar_hash then |
131 | 131 |
132 if data_ok then | 132 local info = meta.tags[1]:get_child("info"); |
133 for _, hash in ipairs(avatar_data) do | 133 if info then |
134 local meta = meta_ok and avatar_meta[hash]; | |
135 local data = avatar_data[hash]; | |
136 local info = meta and meta.tags[1]:get_child("info"); | |
137 vcard_temp:tag("PHOTO"); | 134 vcard_temp:tag("PHOTO"); |
138 if info and info.attr.type then | 135 |
136 if info.attr.type then | |
139 vcard_temp:text_tag("TYPE", info.attr.type); | 137 vcard_temp:text_tag("TYPE", info.attr.type); |
140 end | 138 end |
141 if data then | 139 |
142 vcard_temp:text_tag("BINVAL", data.tags[1]:get_text()); | 140 if info.attr.url then |
143 elseif info and info.attr.url then | |
144 vcard_temp:text_tag("EXTVAL", info.attr.url); | 141 vcard_temp:text_tag("EXTVAL", info.attr.url); |
142 elseif info.attr.id then | |
143 local data_ok, avatar_data = pep_service:get_items("urn:xmpp:avatar:data", stanza.attr.from, { info.attr.id }); | |
144 if data_ok and avatar_data and avatar_data[info.attr.id] then | |
145 local data = avatar_data[info.attr.id]; | |
146 vcard_temp:text_tag("BINVAL", data.tags[1]:get_text()); | |
147 end | |
145 end | 148 end |
146 vcard_temp:up(); | 149 vcard_temp:up(); |
147 end | 150 end |
148 end | 151 end |
149 | 152 |
155 access_model = "open"; | 158 access_model = "open"; |
156 _defaults_only = true; | 159 _defaults_only = true; |
157 }; | 160 }; |
158 | 161 |
159 function vcard_to_pep(vcard_temp) | 162 function vcard_to_pep(vcard_temp) |
160 local avatars = {}; | 163 local avatar = {}; |
161 | 164 |
162 local vcard4 = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" }) | 165 local vcard4 = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" }) |
163 :tag("vcard", { xmlns = 'urn:ietf:params:xml:ns:vcard-4.0' }); | 166 :tag("vcard", { xmlns = 'urn:ietf:params:xml:ns:vcard-4.0' }); |
164 | 167 |
165 vcard4:tag("fn"):text_tag("text", vcard_temp:get_child_text("FN")):up(); | 168 vcard4:tag("fn"):text_tag("text", vcard_temp:get_child_text("FN")):up(); |
244 | 247 |
245 if avatar_payload then | 248 if avatar_payload then |
246 local avatar_raw = base64_decode(avatar_payload); | 249 local avatar_raw = base64_decode(avatar_payload); |
247 local avatar_hash = sha1(avatar_raw, true); | 250 local avatar_hash = sha1(avatar_raw, true); |
248 | 251 |
249 local avatar_meta = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" }) | 252 avatar.hash = avatar_hash; |
253 | |
254 avatar.meta = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" }) | |
250 :tag("metadata", { xmlns="urn:xmpp:avatar:metadata" }) | 255 :tag("metadata", { xmlns="urn:xmpp:avatar:metadata" }) |
251 :tag("info", { | 256 :tag("info", { |
252 bytes = tostring(#avatar_raw), | 257 bytes = tostring(#avatar_raw), |
253 id = avatar_hash, | 258 id = avatar_hash, |
254 type = avatar_type, | 259 type = avatar_type, |
255 }); | 260 }); |
256 | 261 |
257 local avatar_data = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" }) | 262 avatar.data = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" }) |
258 :tag("data", { xmlns="urn:xmpp:avatar:data" }) | 263 :tag("data", { xmlns="urn:xmpp:avatar:data" }) |
259 :text(avatar_payload); | 264 :text(avatar_payload); |
260 | 265 |
261 table.insert(avatars, { hash = avatar_hash, meta = avatar_meta, data = avatar_data }); | 266 end |
262 end | 267 end |
263 end | 268 end |
264 end | 269 return vcard4, avatar; |
265 return vcard4, avatars; | 270 end |
266 end | 271 |
267 | 272 function save_to_pep(pep_service, actor, vcard4, avatar) |
268 function save_to_pep(pep_service, actor, vcard4, avatars) | 273 if avatar then |
269 if avatars then | |
270 | 274 |
271 if pep_service:purge("urn:xmpp:avatar:metadata", actor) then | 275 if pep_service:purge("urn:xmpp:avatar:metadata", actor) then |
272 pep_service:purge("urn:xmpp:avatar:data", actor); | 276 pep_service:purge("urn:xmpp:avatar:data", actor); |
273 end | 277 end |
274 | 278 |
275 local avatar_defaults = node_defaults; | 279 local ok, err = pep_service:publish("urn:xmpp:avatar:data", actor, avatar.hash, avatar.data, node_defaults); |
276 if #avatars > 1 then | 280 if ok then |
277 avatar_defaults = {}; | 281 ok, err = pep_service:publish("urn:xmpp:avatar:metadata", actor, avatar.hash, avatar.meta, node_defaults); |
278 for k,v in pairs(node_defaults) do | 282 end |
279 avatar_defaults[k] = v; | 283 if not ok then |
280 end | 284 return ok, err; |
281 avatar_defaults.max_items = #avatars; | |
282 end | |
283 for _, avatar in ipairs(avatars) do | |
284 local ok, err = pep_service:publish("urn:xmpp:avatar:data", actor, avatar.hash, avatar.data, avatar_defaults); | |
285 if ok then | |
286 ok, err = pep_service:publish("urn:xmpp:avatar:metadata", actor, avatar.hash, avatar.meta, avatar_defaults); | |
287 end | |
288 if not ok then | |
289 return ok, err; | |
290 end | |
291 end | 285 end |
292 end | 286 end |
293 | 287 |
294 if vcard4 then | 288 if vcard4 then |
295 return pep_service:publish("urn:xmpp:vcard4", actor, "current", vcard4, node_defaults); | 289 return pep_service:publish("urn:xmpp:vcard4", actor, "current", vcard4, node_defaults); |