Mercurial > prosody-modules
annotate mod_pep_vcard_avatar/mod_pep_vcard_avatar.lua @ 2735:b5fae17e4403
mod_csi_battery_saver: correctly handle encrypted message stanzas
Thanks to michel
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Sat, 12 Aug 2017 20:45:11 +0200 |
parents | 724809023c92 |
children | 933049a60ce6 |
rev | line source |
---|---|
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Prosody IM |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2014 Matthew Wild |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2014 Waqas Hussain |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 -- Copyright (C) 2014 Kim Alvefur |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 -- |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local st = require "util.stanza" |
2206
724809023c92
mod_pep_vcard_avatar: Include user field in event
Kim Alvefur <zash@zash.se>
parents:
2151
diff
changeset
|
11 local jid = require "util.jid"; |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local base64 = require"util.encodings".base64; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 local sha1 = require"util.hashes".sha1; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local mod_pep = module:depends"pep"; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local pep_data = mod_pep.module.save().data; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 module:add_feature("http://prosody.im/protocol/vcard-pep-integration"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 module:depends"vcard"; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local vcard_storage = module:open_store("vcard"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local function get_vcard(username) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local vcard, err = vcard_storage:get(username); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 if vcard then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 vcard = st.deserialize(vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 if not vcard then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 vcard = st.stanza("vCard", { xmlns = "vcard-temp" }); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 return vcard, err; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |
2150
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
33 local function replace_tag(s, replacement) |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
34 local once = false; |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
35 s:maptags(function (tag) |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
36 if tag.name == replacement.name and tag.attr.xmlns == replacement.attr.xmlns then |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
37 if not once then |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
38 once = true; |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
39 return replacement; |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
40 else |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
41 return nil; |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
42 end |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
43 end |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
44 return tag; |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
45 end); |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
46 if not once then |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
47 s:add_child(replacement); |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
48 end |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
49 end |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
50 |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 local function set_vcard(username, vcard) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 if vcard then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 vcard = st.preserialize(st.clone(vcard)); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 return vcard_storage:set(username, vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 local function publish(session, node, id, item) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 return module:fire_event("pep-publish-item", { |
2206
724809023c92
mod_pep_vcard_avatar: Include user field in event
Kim Alvefur <zash@zash.se>
parents:
2151
diff
changeset
|
60 actor = true, user = jid.bare(session.full_jid), session = session, node = node, id = id, item = item; |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 }); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 -- vCard -> PEP |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 local function update_pep(session, vcard) |
2149
d9e91240a2dd
mod_pep_vcard_avatar: Return early if no vcard is given
Kim Alvefur <zash@zash.se>
parents:
1591
diff
changeset
|
66 if not vcard then return end |
d9e91240a2dd
mod_pep_vcard_avatar: Return early if no vcard is given
Kim Alvefur <zash@zash.se>
parents:
1591
diff
changeset
|
67 local nickname = vcard:get_child_text("NICKNAME"); |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 if nickname then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 publish(session, "http://jabber.org/protocol/nick", "current", st.stanza("item", {id="current"}) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 :tag("nick", { xmlns="http://jabber.org/protocol/nick" }):text(nickname)); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 |
2149
d9e91240a2dd
mod_pep_vcard_avatar: Return early if no vcard is given
Kim Alvefur <zash@zash.se>
parents:
1591
diff
changeset
|
73 local photo = vcard:get_child("PHOTO"); |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 if photo then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 local photo_type = photo:get_child_text("TYPE"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 local photo_b64 = photo:get_child_text("BINVAL"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 local photo_raw = photo_b64 and base64.decode(photo_b64); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 if photo_raw and photo_type then -- Else invalid data or encoding |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 local photo_hash = sha1(photo_raw, true); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 publish(session, "urn:xmpp:avatar:data", photo_hash, st.stanza("item", {id=photo_hash}) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 :tag("data", { xmlns="urn:xmpp:avatar:data" }):text(photo_b64)); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 publish(session, "urn:xmpp:avatar:metadata", photo_hash, st.stanza("item", {id=photo_hash}) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 :tag("metadata", { xmlns="urn:xmpp:avatar:metadata" }) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 :tag("info", { id = photo_hash, bytes = tostring(#photo_raw), type = photo_type,})); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 local function handle_vcard(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 local session, stanza = event.origin, event.stanza; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 if not stanza.attr.to and stanza.attr.type == "set" then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 return update_pep(session, stanza:get_child("vCard", "vcard-temp")); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 module:hook("iq/bare/vcard-temp:vCard", handle_vcard, 1); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 -- PEP Avatar -> vCard |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 local function on_publish_metadata(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 local username = event.session.username; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 local metadata = event.item:find("{urn:xmpp:avatar:metadata}metadata/info"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 if not metadata then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 module:log("error", "No info found"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 module:log("debug", event.item:top_tag()); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 return; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 module:log("debug", metadata:top_tag()); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 local user_data = pep_data[username.."@"..module.host]; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 local pep_photo = user_data["urn:xmpp:avatar:data"]; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 pep_photo = pep_photo and pep_photo[1] == metadata.attr.id and pep_photo[2]; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 if not pep_photo then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 module:log("error", "No photo found"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 return; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 end -- Publishing in the wrong order? |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 local vcard = get_vcard(username); |
2150
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
117 local new_photo = st.stanza("PHOTO", { xmlns = "vcard-temp" }) |
2151
96aca307964b
mod_pep_vcard_avatar: Fix typo [luacheck]
Kim Alvefur <zash@zash.se>
parents:
2150
diff
changeset
|
118 :tag("TYPE"):text(metadata.attr.type):up() |
2150
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
119 :tag("BINVAL"):text(pep_photo:get_child_text("data", "urn:xmpp:avatar:data")); |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
120 |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
121 replace_tag(vcard, new_photo); |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 set_vcard(username, vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 -- PEP Nickname -> vCard |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 local function on_publish_nick(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 local username = event.session.username; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 local vcard = get_vcard(username); |
2150
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
129 local new_nick = st.stanza("NICKNAME", { xmlns = "vcard-temp" }) |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
130 :text(event.item:get_child_text("nick", "http://jabber.org/protocol/nick")); |
c1ecc3bc88fa
mod_pep_vcard_avatar: Replace PHOTO and NICKNAME tags instead of modifying them in-place
Kim Alvefur <zash@zash.se>
parents:
2149
diff
changeset
|
131 replace_tag(vcard, new_nick); |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 set_vcard(username, vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 local function on_publish(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 if event.actor == true then return end -- Not from a client |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 local node = event.node; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 if node == "urn:xmpp:avatar:metadata" then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 return on_publish_metadata(event); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 elseif node == "http://jabber.org/protocol/nick" then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 return on_publish_nick(event); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 module:hook("pep-publish-item", on_publish, 1); |