comparison mod_profile/mod_profile.lua @ 3190:76a2aca48b4f

mod_profile: Refactor wrapping of payloads in <item>
author Kim Alvefur <zash@zash.se>
date Tue, 24 Jul 2018 16:27:59 +0200
parents 7c450c27d4ba
children a1c92d62b861
comparison
equal deleted inserted replaced
3189:57332ea0c1c7 3190:76a2aca48b4f
48 end 48 end
49 end 49 end
50 return "application/octet-stream"; 50 return "application/octet-stream";
51 end 51 end
52 52
53 local function item_container(id, payload)
54 return id, st.stanza("item", { id = "current" })
55 :add_child(payload);
56 end
57
53 local function update_pep(username, data, pep) 58 local function update_pep(username, data, pep)
54 pep = pep or pep_plus.get_pep_service(username); 59 pep = pep or pep_plus.get_pep_service(username);
55 local photo, p = get_item(data, "PHOTO"); 60 local photo, p = get_item(data, "PHOTO");
56 if vcard.to_vcard4 then 61 if vcard.to_vcard4 then
57 if p then t_remove(data, p); end 62 if p then t_remove(data, p); end
58 pep:purge("urn:xmpp:vcard4", true); 63 pep:purge("urn:xmpp:vcard4", true)
59 pep:publish("urn:xmpp:vcard4", true, "current", st.stanza("item", {id="current"}) 64 pep:publish("urn:xmpp:vcard4", true, item_container("current", vcard.to_vcard4(data)));
60 :add_child(vcard.to_vcard4(data)));
61 if p then t_insert(data, p, photo); end 65 if p then t_insert(data, p, photo); end
62 end 66 end
63 67
64 local nickname = get_item(data, "NICKNAME"); 68 local nickname = get_item(data, "NICKNAME");
65 if nickname and nickname[1] then 69 if nickname and nickname[1] then
66 pep:purge("http://jabber.org/protocol/nick", true); 70 pep:purge("http://jabber.org/protocol/nick", true);
67 pep:publish("http://jabber.org/protocol/nick", true, "current", st.stanza("item", {id="current"}) 71 pep:publish("http://jabber.org/protocol/nick", true, item_container("current",
68 :tag("nick", { xmlns="http://jabber.org/protocol/nick" }):text(nickname[1])); 72 st.stanza("nick", { xmlns="http://jabber.org/protocol/nick" }):text(nickname[1])));
69 end 73 end
70 74
71 if photo and photo[1] then 75 if photo and photo[1] then
72 local photo_raw = base64.decode(photo[1]); 76 local photo_raw = base64.decode(photo[1]);
73 local photo_hash = sha1(photo_raw, true); 77 local photo_hash = sha1(photo_raw, true);
74 78
75 pep:purge("urn:xmpp:avatar:metadata", true); 79 pep:purge("urn:xmpp:avatar:metadata", true);
76 pep:purge("urn:xmpp:avatar:data", true); 80 pep:purge("urn:xmpp:avatar:data", true);
77 pep:publish("urn:xmpp:avatar:metadata", true, photo_hash, st.stanza("item", {id=photo_hash}) 81 pep:publish("urn:xmpp:avatar:metadata", true, item_container(photo_hash,
78 :tag("metadata", { xmlns="urn:xmpp:avatar:metadata" }) 82 st.stanza("metadata", { xmlns="urn:xmpp:avatar:metadata" })
79 :tag("info", { 83 :tag("info", {
80 bytes = tostring(#photo_raw), 84 bytes = tostring(#photo_raw),
81 id = photo_hash, 85 id = photo_hash,
82 type = identify(photo_raw), 86 type = identify(photo_raw),
83 })); 87 })));
84 pep:publish("urn:xmpp:avatar:data", true, photo_hash, st.stanza("item", {id=photo_hash}) 88 pep:publish("urn:xmpp:avatar:data", true, item_container(photo_hash,
85 :tag("data", { xmlns="urn:xmpp:avatar:data" }):text(photo[1])); 89 st.stanza("data", { xmlns="urn:xmpp:avatar:data" }):text(photo[1])));
86 end 90 end
87 end 91 end
88 92
89 -- The "temporary" vCard XEP-0054 part 93 -- The "temporary" vCard XEP-0054 part
90 module:add_feature("vcard-temp"); 94 module:add_feature("vcard-temp");