comparison mod_profile/mod_profile.lua @ 1515:f367d7cbfaa6

mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
author Kim Alvefur <zash@zash.se>
date Sat, 27 Sep 2014 19:11:04 +0200
parents c4c9ccc6e6c9
children 48d95ab404c7
comparison
equal deleted inserted replaced
1514:18349533c44d 1515:f367d7cbfaa6
11 local pep_plus; 11 local pep_plus;
12 if module:get_host_type() == "local" and module:get_option_boolean("vcard_to_pep", true) then 12 if module:get_host_type() == "local" and module:get_option_boolean("vcard_to_pep", true) then
13 pep_plus = module:depends"pep_plus"; 13 pep_plus = module:depends"pep_plus";
14 end 14 end
15 15
16 local loaded_pep_for = module:shared"loaded-pep-for";
17 local storage = module:open_store(); 16 local storage = module:open_store();
18 local legacy_storage = module:open_store("vcard"); 17 local legacy_storage = module:open_store("vcard");
19 18
20 local function get_item(vcard, name) 19 local function get_item(vcard, name)
21 local item; 20 local item;
41 end 40 end
42 end 41 end
43 return "application/octet-stream"; 42 return "application/octet-stream";
44 end 43 end
45 44
46 local function update_pep(username, data) 45 local function update_pep(username, data, pep)
47 local pep = pep_plus.get_pep_service(username.."@"..module.host); 46 pep = pep or pep_plus.get_pep_service(username.."@"..module.host);
48 local photo, p = get_item(data, "PHOTO"); 47 local photo, p = get_item(data, "PHOTO");
49 if vcard.to_vcard4 then 48 if vcard.to_vcard4 then
50 if p then t_remove(data, p); end 49 if p then t_remove(data, p); end
51 pep:purge("urn:xmpp:vcard4", true); 50 pep:purge("urn:xmpp:vcard4", true);
52 pep:publish("urn:xmpp:vcard4", true, "current", st.stanza("item", {id="current"}) 51 pep:publish("urn:xmpp:vcard4", true, "current", st.stanza("item", {id="current"})
117 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); 116 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
118 end 117 end
119 118
120 if pep_plus and username then 119 if pep_plus and username then
121 update_pep(username, data); 120 update_pep(username, data);
122 loaded_pep_for[username] = true;
123 end 121 end
124 122
125 return origin.send(st.reply(stanza)); 123 return origin.send(st.reply(stanza));
126 end 124 end
127 125
129 module:hook("iq-get/host/vcard-temp:vCard", handle_get); 127 module:hook("iq-get/host/vcard-temp:vCard", handle_get);
130 128
131 module:hook("iq-set/bare/vcard-temp:vCard", handle_set); 129 module:hook("iq-set/bare/vcard-temp:vCard", handle_set);
132 module:hook("iq-set/host/vcard-temp:vCard", handle_set); 130 module:hook("iq-set/host/vcard-temp:vCard", handle_set);
133 131
134 module:hook("presence/initial", function (event) 132 local function pep_service_added(event)
135 local username = event.origin.username 133 local item = event.item;
136 if not loaded_pep_for[username] then 134 local service, username = item.service, jid_split(item.jid);
137 local data = storage:get(username); 135 local data = storage:get(username);
138 if data then 136 if data then
139 update_pep(username, data); 137 update_pep(username, data, service);
140 end
141 loaded_pep_for[username] = true;
142 end 138 end
143 end); 139 end
140
141 local function pep_service_removed()
142 -- This would happen when mod_pep_plus gets unloaded, but this module gets unloaded before that
143 end
144
145 function module.load()
146 module:handle_items("pep-service", pep_service_added, pep_service_removed, true);
147 end
144 148
145 -- The vCard4 part 149 -- The vCard4 part
146 if vcard.to_vcard4 then 150 if vcard.to_vcard4 then
147 module:add_feature("urn:ietf:params:xml:ns:vcard-4.0"); 151 module:add_feature("urn:ietf:params:xml:ns:vcard-4.0");
148 152