diff options
author | daurnimator <quae@daurnimator.com> | 2014-03-19 16:19:31 -0400 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2014-03-19 16:19:31 -0400 |
commit | 19dd45441f0a534547d81a51bfdf0ce7da973fed (patch) | |
tree | dee15c9609ef7041819a7d607ab3de65fb731c57 /plugins | |
parent | dde1ed8455c6affd2b967c8fcf3d79aaa874f32b (diff) | |
download | prosody-19dd45441f0a534547d81a51bfdf0ce7da973fed.tar.gz prosody-19dd45441f0a534547d81a51bfdf0ce7da973fed.zip |
plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/muc/muc.lib.lua | 17 |
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 |