Software /
code /
prosody-modules
Annotate
mod_pep_vcard_avatar/mod_pep_vcard_avatar.lua @ 2151:96aca307964b
mod_pep_vcard_avatar: Fix typo [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 03 Apr 2016 00:21:16 +0200 |
parent | 2150:c1ecc3bc88fa |
child | 2206:724809023c92 |
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" |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 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
|
12 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
|
13 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 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
|
15 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
|
16 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 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
|
18 module:depends"vcard"; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 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
|
20 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 local function get_vcard(username) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 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
|
23 if vcard then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 vcard = st.deserialize(vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 if not vcard then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 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
|
28 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 return vcard, err; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 |
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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
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 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
|
44 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
|
45 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
|
46 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
|
47 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
|
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 |
1591
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 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
|
51 if vcard then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 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
|
53 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 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
|
55 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 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
|
58 return module:fire_event("pep-publish-item", { |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 actor = true, session = session, node = node, id = id, item = item; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 }); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 -- vCard -> PEP |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 if nickname then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 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
|
69 :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
|
70 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 |
2149
d9e91240a2dd
mod_pep_vcard_avatar: Return early if no vcard is given
Kim Alvefur <zash@zash.se>
parents:
1591
diff
changeset
|
72 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
|
73 if photo then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 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
|
81 :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
|
82 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
|
83 :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
|
84 :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
|
85 end |
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 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 local function handle_vcard(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 end |
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 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 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
|
97 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 -- PEP Avatar -> vCard |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 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
|
100 local username = event.session.username; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 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
|
102 if not metadata then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 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
|
104 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
|
105 return; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 if not pep_photo then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 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
|
113 return; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 :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
|
118 :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
|
119 |
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 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
|
121 set_vcard(username, vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 -- PEP Nickname -> vCard |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 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
|
126 local username = event.session.username; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 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
|
128 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
|
129 :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
|
130 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
|
131 set_vcard(username, vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 local function on_publish(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 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
|
136 local node = event.node; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 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
|
138 return on_publish_metadata(event); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 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
|
140 return on_publish_nick(event); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 end |
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 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 module:hook("pep-publish-item", on_publish, 1); |