Changeset

6121:74bbcef3978e

plugins/muc/muc.lib: Add muc-invite-prepared event; Use it for granting affiliations in members only rooms
author daurnimator <quae@daurnimator.com>
date Wed, 19 Mar 2014 16:19:31 -0400
parents 6120:4520439227fc
children 6122:44a846744814
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Wed Mar 19 15:01:18 2014 -0400
+++ b/plugins/muc/muc.lib.lua	Wed Mar 19 16:19:31 2014 -0400
@@ -1009,10 +1009,7 @@
 			: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 @@
 	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