aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2014-03-19 16:19:31 -0400
committerdaurnimator <quae@daurnimator.com>2014-03-19 16:19:31 -0400
commit74fb113acd8f4c6c20c7ebb5df7ab9ac0de5932e (patch)
treedee15c9609ef7041819a7d607ab3de65fb731c57
parent4bbb266dab17014d2d8f25b1d8180e38c4a8a233 (diff)
downloadprosody-74fb113acd8f4c6c20c7ebb5df7ab9ac0de5932e.tar.gz
prosody-74fb113acd8f4c6c20c7ebb5df7ab9ac0de5932e.zip
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
-rw-r--r--plugins/muc/muc.lib.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index f3c72e26..7dfb0611 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1009,10 +1009,7 @@ function room_mt:handle_mediated_invite(origin, stanza, payload)
:tag('body') -- Add a plain message for clients which don't support invites
:text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or ""))
:up();
- if self:get_members_only() and not self:get_affiliation(_invitee) then
- log("debug", "%s invited %s into members only room %s, granting membership", _from, _invitee, _to);
- self:set_affiliation(_from, _invitee, "member", nil, "Invited by " .. current_nick)
- end
+ module:fire_event("muc-invite-prepared", { room = self, stanza = invite })
self:_route_stanza(invite);
return true;
else
@@ -1021,6 +1018,18 @@ function room_mt:handle_mediated_invite(origin, stanza, payload)
end
end
+-- When an invite is sent; add an affiliation for the invitee
+module:hook("muc-invite-prepared", function(event)
+ local room, stanza = event.room, event.stanza
+ local invitee = stanza.attr.to
+ if room:get_members_only() and not room:get_affiliation(invitee) then
+ local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite").attr.from
+ local current_nick = room:get_occupant_jid(from)
+ log("debug", "%s invited %s into members only room %s, granting membership", from, invitee, room.jid);
+ room:set_affiliation(from, invitee, "member", nil, "Invited by " .. current_nick)
+ end
+end)
+
function room_mt:handle_mediated_decline(origin, stanza, payload)
local declinee = jid_prep(payload.attr.to);
if declinee then