Comparison

plugins/muc/muc.lib.lua @ 6278:fcc3ef191293

plugins/muc/muc: Fire broadcast presences event before creating full/anon presences
author daurnimator <quae@daurnimator.com>
date Tue, 17 Jun 2014 15:27:00 -0400
parent 6277:f2c9c36979b3
child 6317:ec57067c1e0d
comparison
equal deleted inserted replaced
6277:f2c9c36979b3 6278:fcc3ef191293
184 elseif whois == "moderators" then 184 elseif whois == "moderators" then
185 return valid_roles[occupant.role or "none"] >= valid_roles.moderator; 185 return valid_roles[occupant.role or "none"] >= valid_roles.moderator;
186 end 186 end
187 end 187 end
188 188
189 local function get_base_presence(occupant) 189 -- Broadcasts an occupant's presence to the whole room
190 -- Takes the x element that goes into the stanzas
191 function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason)
192 -- Build real jid and (optionally) occupant jid template presences
193 local base_presence;
190 if occupant.role ~= nil then 194 if occupant.role ~= nil then
191 -- Try to use main jid's presence 195 -- Try to use main jid's presence
192 local pr = occupant:get_presence(); 196 local pr = occupant:get_presence();
193 if pr ~= nil then 197 if pr ~= nil then
194 return st.clone(pr); 198 base_presence = st.clone(pr);
195 end 199 end
196 end 200 end
197 return st.presence {from = occupant.nick; type = "unavailable";}; 201 base_presence = base_presence or st.presence {from = occupant.nick; type = "unavailable";};
198 end 202
199 203 -- Fire event (before full_p and anon_p are created)
200 -- Broadcasts an occupant's presence to the whole room 204 module:fire_event("muc-broadcast-presence", {room = self; stanza = base_presence; x = base_x;});
201 -- Takes the x element that goes into the stanzas 205
202 function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason)
203 -- Build real jid and (optionally) occupant jid template presences
204 local function get_presence(is_anonymous) 206 local function get_presence(is_anonymous)
205 local x = st.clone(base_x); 207 local x = st.clone(base_x);
206 self:build_item_list(occupant, x, is_anonymous, nick, actor, reason); 208 self:build_item_list(occupant, x, is_anonymous, nick, actor, reason);
207 return get_base_presence(occupant):add_child(x), x; 209 return st.clone(base_presence):add_child(x), x;
208 end 210 end
211
209 local full_p, full_x = get_presence(false); 212 local full_p, full_x = get_presence(false);
210 213
211 module:fire_event("muc-broadcast-presence", {room = self; stanza = full_p; x = full_x;}); 214 -- Create anon_p lazily
212
213 local anon_p, anon_x; 215 local anon_p, anon_x;
214 local function get_anon_p() 216 local function get_anon_p()
215 if anon_p == nil then 217 if anon_p == nil then
216 anon_p, anon_x = get_presence(true); 218 anon_p, anon_x = get_presence(true);
217 end 219 end