Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 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 |
parent | 6120:4520439227fc |
child | 6122:44a846744814 |
comparison
equal
deleted
inserted
replaced
6120:4520439227fc | 6121:74bbcef3978e |
---|---|
1007 :text(_reason or "") | 1007 :text(_reason or "") |
1008 :up() | 1008 :up() |
1009 :tag('body') -- Add a plain message for clients which don't support invites | 1009 :tag('body') -- Add a plain message for clients which don't support invites |
1010 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or "")) | 1010 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or "")) |
1011 :up(); | 1011 :up(); |
1012 if self:get_members_only() and not self:get_affiliation(_invitee) then | 1012 module:fire_event("muc-invite-prepared", { room = self, stanza = invite }) |
1013 log("debug", "%s invited %s into members only room %s, granting membership", _from, _invitee, _to); | |
1014 self:set_affiliation(_from, _invitee, "member", nil, "Invited by " .. current_nick) | |
1015 end | |
1016 self:_route_stanza(invite); | 1013 self:_route_stanza(invite); |
1017 return true; | 1014 return true; |
1018 else | 1015 else |
1019 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); | 1016 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
1020 return true; | 1017 return true; |
1021 end | 1018 end |
1022 end | 1019 end |
1020 | |
1021 -- When an invite is sent; add an affiliation for the invitee | |
1022 module:hook("muc-invite-prepared", function(event) | |
1023 local room, stanza = event.room, event.stanza | |
1024 local invitee = stanza.attr.to | |
1025 if room:get_members_only() and not room:get_affiliation(invitee) then | |
1026 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite").attr.from | |
1027 local current_nick = room:get_occupant_jid(from) | |
1028 log("debug", "%s invited %s into members only room %s, granting membership", from, invitee, room.jid); | |
1029 room:set_affiliation(from, invitee, "member", nil, "Invited by " .. current_nick) | |
1030 end | |
1031 end) | |
1023 | 1032 |
1024 function room_mt:handle_mediated_decline(origin, stanza, payload) | 1033 function room_mt:handle_mediated_decline(origin, stanza, payload) |
1025 local declinee = jid_prep(payload.attr.to); | 1034 local declinee = jid_prep(payload.attr.to); |
1026 if declinee then | 1035 if declinee then |
1027 local from, to = stanza.attr.from, stanza.attr.to; | 1036 local from, to = stanza.attr.from, stanza.attr.to; |