Mercurial > prosody-modules
annotate mod_pep_vcard_avatar/mod_pep_vcard_avatar.lua @ 1837:6a3b48eded35
mod_s2s_auth_dane/README: Describe DANE uses
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 09 Sep 2015 17:00:41 +0200 |
parents | 21e439ca7208 |
children | d9e91240a2dd |
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 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 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
|
33 if vcard then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 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
|
35 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 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
|
37 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 }); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 -- vCard -> PEP |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 local function update_pep(session, vcard) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 local nickname = vcard and vcard:get_child_text("NICKNAME"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 if nickname then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 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
|
50 :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
|
51 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 local photo = vcard and vcard:get_child("PHOTO"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 if photo then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 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
|
62 :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
|
63 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
|
64 :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
|
65 :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
|
66 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 local function handle_vcard(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 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
|
78 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 -- PEP Avatar -> vCard |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 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
|
81 local username = event.session.username; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 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
|
83 if not metadata then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 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
|
85 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
|
86 return; |
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 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
|
89 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
|
90 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
|
91 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
|
92 if not pep_photo then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 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
|
94 return; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 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
|
96 local vcard = get_vcard(username); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 local old_photo = vcard:get_child("PHOTO"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 if old_photo then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 local photo_type = old_photo:get_child("TYPE"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 photo_type[1] = metadata.attr.type; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 local photo_b64 = old_photo:get_child("BINVAL"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 photo_b64[1] = pep_photo:get_child_text("data", "urn:xmpp:avatar:data"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 set_vcard(username, vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 -- PEP Nickname -> vCard |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 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
|
109 local username = event.session.username; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 local vcard = get_vcard(username); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 local new_nick = event.item:get_child_text("nick", "http://jabber.org/protocol/nick"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 local old_nick = vcard:get_child("NICKNAME"); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 if not old_nick then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 vcard:tag("NICKNAME"):text(new_nick); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 elseif old_nick[1] ~= new_nick then |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 old_nick[1] = new_nick; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 else |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 return -- no change |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 set_vcard(username, vcard); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 local function on_publish(event) |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 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
|
125 local node = event.node; |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 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
|
127 return on_publish_metadata(event); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 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
|
129 return on_publish_nick(event); |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 end |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 |
21e439ca7208
mod_pep_vcard_avatar: Syncs avatars between PEP and vCard
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 module:hook("pep-publish-item", on_publish, 1); |