1201 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
1201 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
1202 return true; |
1202 return true; |
1203 end |
1203 end |
1204 local _invitee = jid_prep(payload.attr.to); |
1204 local _invitee = jid_prep(payload.attr.to); |
1205 if _invitee then |
1205 if _invitee then |
1206 local _reason = payload:get_child_text("reason"); |
|
1207 if self:get_whois() == "moderators" then |
|
1208 _from = current_nick; |
|
1209 end |
|
1210 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) |
1206 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) |
1211 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
1207 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
1212 :tag('invite', {from=_from}) |
1208 :tag('invite', {from=_from}) |
1213 :tag('reason'):text(_reason or ""):up() |
1209 :tag('reason'):text(payload:get_child_text("reason")):up() |
1214 :up(); |
1210 :up() |
1215 local password = self:get_password(); |
|
1216 if password then |
|
1217 invite:tag("password"):text(password):up(); |
|
1218 end |
|
1219 invite:up() |
|
1220 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this |
|
1221 :text(_reason or "") |
|
1222 :up() |
|
1223 :tag('body') -- Add a plain message for clients which don't support invites |
|
1224 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or "")) |
|
1225 :up(); |
1211 :up(); |
1226 module:fire_event("muc-invite", {room = self, stanza = invite, origin = origin, incoming = stanza}); |
1212 if not module:fire_event("muc-invite", {room = self, stanza = invite, origin = origin, incoming = stanza}) then |
|
1213 self:route_stanza(invite); |
|
1214 end |
1227 return true; |
1215 return true; |
1228 else |
1216 else |
1229 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
1217 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
1230 return true; |
1218 return true; |
1231 end |
1219 end |
1232 end |
1220 end |
1233 |
1221 |
|
1222 -- Add password to outgoing invite |
1234 module:hook("muc-invite", function(event) |
1223 module:hook("muc-invite", function(event) |
1235 event.room:route_stanza(event.stanza); |
1224 local password = event.room:get_password(); |
1236 return true; |
1225 if password then |
1237 end, -1) |
1226 local x = event.stanza:get_child("x", "http://jabber.org/protocol/muc#user"); |
|
1227 x:tag("password"):text(password):up(); |
|
1228 end |
|
1229 end); |
|
1230 |
|
1231 -- COMPAT: Some older clients expect this |
|
1232 module:hook("muc-invite", function(event) |
|
1233 local room, stanza = event.room, event.stanza; |
|
1234 local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
|
1235 local reason = invite:get_child_text("reason"); |
|
1236 stanza:tag('x', {xmlns = "jabber:x:conference"; jid = room.jid;}) |
|
1237 :text(reason or "") |
|
1238 :up(); |
|
1239 end); |
|
1240 |
|
1241 -- Add a plain message for clients which don't support invites |
|
1242 module:hook("muc-invite", function(event) |
|
1243 local room, stanza = event.room, event.stanza; |
|
1244 local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
|
1245 local reason = invite:get_child_text("reason") or ""; |
|
1246 stanza:tag("body") |
|
1247 :text(invite.attr.from.." invited you to the room "..room.jid..(reason == "" and (" ("..reason..")") or "")) |
|
1248 :up(); |
|
1249 end); |
|
1250 |
|
1251 -- Mask 'from' jid as occupant jid if room is anonymous |
|
1252 module:hook("muc-invite", function(event) |
|
1253 local room, stanza = event.room, event.stanza; |
|
1254 if room:get_whois() == "moderators" and room:get_default_role(room:get_affiliation(stanza.attr.to)) ~= "moderator" then |
|
1255 local invite = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite"); |
|
1256 local occupant_jid = room:get_occupant_jid(invite.attr.from); |
|
1257 if occupant_jid ~= nil then -- FIXME: This will expose real jid if inviter is not in room |
|
1258 invite.attr.from = occupant_jid; |
|
1259 end |
|
1260 end |
|
1261 end, 50); |
1238 |
1262 |
1239 -- When an invite is sent; add an affiliation for the invitee |
1263 -- When an invite is sent; add an affiliation for the invitee |
1240 module:hook("muc-invite", function(event) |
1264 module:hook("muc-invite", function(event) |
1241 local room, stanza = event.room, event.stanza |
1265 local room, stanza = event.room, event.stanza |
1242 local invitee = stanza.attr.to |
1266 local invitee = stanza.attr.to |