Comparison

mod_profile/mod_profile.lua @ 1442:253e374824a8

mod_profile: Load profile into PEP on initial presence
author Kim Alvefur <zash@zash.se>
date Sat, 21 Jun 2014 14:58:55 +0200
parent 1441:07c9306c2c1f
child 1446:843769eb40c3
comparison
equal deleted inserted replaced
1441:07c9306c2c1f 1442:253e374824a8
10 local pep_plus; 10 local pep_plus;
11 if module:get_host_type() == "local" and module:get_option_boolean("vcard_to_pep", true) then 11 if module:get_host_type() == "local" and module:get_option_boolean("vcard_to_pep", true) then
12 pep_plus = module:depends"pep_plus"; 12 pep_plus = module:depends"pep_plus";
13 end 13 end
14 14
15 local loaded_pep_for = module:shared"loaded-pep-for";
15 local storage = module:open_store(); 16 local storage = module:open_store();
16 local legacy_storage = module:open_store("vcard"); 17 local legacy_storage = module:open_store("vcard");
17 18
18 local function get_item(vcard, name) 19 local function get_item(vcard, name)
19 local item; 20 local item;
113 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); 114 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
114 end 115 end
115 116
116 if pep_plus and username then 117 if pep_plus and username then
117 update_pep(username, data); 118 update_pep(username, data);
119 loaded_pep_for[username] = true;
118 end 120 end
119 121
120 return origin.send(st.reply(stanza)); 122 return origin.send(st.reply(stanza));
121 end 123 end
122 124
123 module:hook("iq-get/bare/vcard-temp:vCard", handle_get); 125 module:hook("iq-get/bare/vcard-temp:vCard", handle_get);
124 module:hook("iq-get/host/vcard-temp:vCard", handle_get); 126 module:hook("iq-get/host/vcard-temp:vCard", handle_get);
125 127
126 module:hook("iq-set/bare/vcard-temp:vCard", handle_set); 128 module:hook("iq-set/bare/vcard-temp:vCard", handle_set);
127 module:hook("iq-set/host/vcard-temp:vCard", handle_set); 129 module:hook("iq-set/host/vcard-temp:vCard", handle_set);
130
131 module:hook("presence/initial", function (event)
132 local username = event.origin.username
133 if not loaded_pep_for[username] then
134 data = storage:get(username);
135 if data then
136 update_pep(username, data);
137 end
138 loaded_pep_for[username] = true;
139 end
140 end);
128 141
129 -- The vCard4 part 142 -- The vCard4 part
130 if vcard.to_vcard4 then 143 if vcard.to_vcard4 then
131 module:add_feature("urn:ietf:params:xml:ns:vcard-4.0"); 144 module:add_feature("urn:ietf:params:xml:ns:vcard-4.0");
132 145