Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 8851:ab5f678f1376
MUC: Support MUC voice requests and approvals in moderated rooms (closes #655) (thanks to Lance Stout)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 20 Oct 2017 05:19:25 +0200 |
| parents | 041ddc670934 |
| children | 5e98d62f3f9b |
comparison
equal
deleted
inserted
replaced
| 8850:26f1a49fa9c0 | 8851:ab5f678f1376 |
|---|---|
| 776 } | 776 } |
| 777 }); | 777 }); |
| 778 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; | 778 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
| 779 end | 779 end |
| 780 | 780 |
| 781 function room_mt:get_voice_form_layout() | |
| 782 local form = dataform.new({ | |
| 783 { | |
| 784 name = "FORM_TYPE"; | |
| 785 type = "hidden"; | |
| 786 value = "http://jabber.org/protocol/muc#request"; | |
| 787 }, | |
| 788 { | |
| 789 name = "muc#jid"; | |
| 790 type = "jid-single"; | |
| 791 }, | |
| 792 { | |
| 793 name = "muc#roomnick"; | |
| 794 type = "text-single"; | |
| 795 }, | |
| 796 { | |
| 797 name = "muc#role"; | |
| 798 type = "text-single"; | |
| 799 }, | |
| 800 { | |
| 801 name = "muc#request_allow"; | |
| 802 type = "boolean"; | |
| 803 } | |
| 804 }); | |
| 805 | |
| 806 return form; | |
| 807 end | |
| 808 | |
| 781 function room_mt:process_form(origin, stanza) | 809 function room_mt:process_form(origin, stanza) |
| 782 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); | 810 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); |
| 783 if form.attr.type == "cancel" then | 811 if form.attr.type == "cancel" then |
| 784 origin.send(st.reply(stanza)); | 812 origin.send(st.reply(stanza)); |
| 785 elseif form.attr.type == "submit" then | 813 elseif form.attr.type == "submit" then |
| 1140 elseif payload.name == "decline" and payload.attr.to then | 1168 elseif payload.name == "decline" and payload.attr.to then |
| 1141 return self:handle_mediated_decline(origin, stanza) | 1169 return self:handle_mediated_decline(origin, stanza) |
| 1142 end | 1170 end |
| 1143 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | 1171 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
| 1144 return true; | 1172 return true; |
| 1173 end | |
| 1174 | |
| 1175 local form = stanza:get_child("x", "jabber:x:data"); | |
| 1176 if form and form.attr.type == "submit" then | |
| 1177 local fields, errors, present = self:get_voice_form_layout():data(form); | |
| 1178 | |
| 1179 if fields.FORM_TYPE == "http://jabber.org/protocol/muc#request" then | |
| 1180 local occupant = self:get_occupant_by_real_jid(stanza.attr.from); | |
| 1181 local event = { | |
| 1182 room = self; | |
| 1183 origin = origin; | |
| 1184 stanza = stanza; | |
| 1185 fields = fields; | |
| 1186 occupant = occupant; | |
| 1187 }; | |
| 1188 if occupant.role == "moderator" then | |
| 1189 module:fire_event("muc-voice-response", event); | |
| 1190 else | |
| 1191 module:fire_event("muc-voice-request", event); | |
| 1192 end | |
| 1193 return true; | |
| 1194 end | |
| 1145 end | 1195 end |
| 1146 end | 1196 end |
| 1147 end | 1197 end |
| 1148 | 1198 |
| 1149 function room_mt:route_stanza(stanza) -- luacheck: ignore 212 | 1199 function room_mt:route_stanza(stanza) -- luacheck: ignore 212 |
