Changeset

6104:260a18062cb2

plugins/muc/muc: Rename `handle_invite_to_room` to `handle_mediated_invite`; clean up logic
author daurnimator <quae@daurnimator.com>
date Tue, 18 Mar 2014 15:15:14 -0400
parents 6103:25ba4e2b31b3
children 6105:68f53b9a186e
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Tue Mar 18 14:56:20 2014 -0400
+++ b/plugins/muc/muc.lib.lua	Tue Mar 18 15:15:14 2014 -0400
@@ -1031,15 +1031,15 @@
 	return handled;
 end
 
-function room_mt:handle_invite_to_room(origin, stanza, payload)
+function room_mt:handle_mediated_invite(origin, stanza, payload)
 	local _from, _to = stanza.attr.from, stanza.attr.to;
-	if not self._jid_nick[_from] then -- Should be in room to send invite
+	if not self._jid_nick[_from] then -- Should be in room to send invite TODO: allow admins to send at any time
 		origin.send(st.error_reply(stanza, "auth", "forbidden"));
 		return true;
 	end
 	local _invitee = jid_prep(payload.attr.to);
 	if _invitee then
-		local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1];
+		local _reason = payload:get_child_text("reason")
 		local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id})
 			:tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
 				:tag('invite', {from=_from})
@@ -1077,8 +1077,10 @@
 		local x = stanza:get_child("x", "http://jabber.org/protocol/muc#user");
 		if x then
 			local payload = x.tags[1];
-			if payload and payload.name == "invite" and payload.attr.to then
-				return self:handle_invite_to_room(origin, stanza, payload)
+			if payload == nil then
+				-- fallthrough
+			elseif payload.name == "invite" and payload.attr.to then
+				return self:handle_mediated_invite(origin, stanza, payload)
 			end
 			origin.send(st.error_reply(stanza, "cancel", "bad-request"));
 			return true;