From 3a09673e61b5d394fcade54e8e09dadcc840fdb0 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 17 Jun 2014 15:27:00 -0400 Subject: plugins/muc/muc: Fire broadcast presences event before creating full/anon presences --- plugins/muc/muc.lib.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index c645869e..3ee17b03 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -186,30 +186,32 @@ local function can_see_real_jids(whois, occupant) end end -local function get_base_presence(occupant) +-- Broadcasts an occupant's presence to the whole room +-- Takes the x element that goes into the stanzas +function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason) + -- Build real jid and (optionally) occupant jid template presences + local base_presence; if occupant.role ~= nil then -- Try to use main jid's presence local pr = occupant:get_presence(); if pr ~= nil then - return st.clone(pr); + base_presence = st.clone(pr); end end - return st.presence {from = occupant.nick; type = "unavailable";}; -end + base_presence = base_presence or st.presence {from = occupant.nick; type = "unavailable";}; + + -- Fire event (before full_p and anon_p are created) + module:fire_event("muc-broadcast-presence", {room = self; stanza = base_presence; x = base_x;}); --- Broadcasts an occupant's presence to the whole room --- Takes the x element that goes into the stanzas -function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason) - -- Build real jid and (optionally) occupant jid template presences local function get_presence(is_anonymous) local x = st.clone(base_x); self:build_item_list(occupant, x, is_anonymous, nick, actor, reason); - return get_base_presence(occupant):add_child(x), x; + return st.clone(base_presence):add_child(x), x; end - local full_p, full_x = get_presence(false); - module:fire_event("muc-broadcast-presence", {room = self; stanza = full_p; x = full_x;}); + local full_p, full_x = get_presence(false); + -- Create anon_p lazily local anon_p, anon_x; local function get_anon_p() if anon_p == nil then -- cgit v1.2.3