Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 8865:2a8bbfcb6868
MUC: Move voice request into its own lib
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 02 Jun 2018 20:15:32 +0200 |
| parents | 2a48255f889b |
| children | cbcac5b9b7ce |
comparison
equal
deleted
inserted
replaced
| 8864:cf2f66b233d1 | 8865:2a8bbfcb6868 |
|---|---|
| 777 } | 777 } |
| 778 }); | 778 }); |
| 779 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; | 779 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
| 780 end | 780 end |
| 781 | 781 |
| 782 function room_mt:get_voice_form_layout() -- luacheck: ignore 212/self | |
| 783 local form = dataform.new({ | |
| 784 title = "Voice Request"; | |
| 785 { | |
| 786 name = "FORM_TYPE"; | |
| 787 type = "hidden"; | |
| 788 value = "http://jabber.org/protocol/muc#request"; | |
| 789 }, | |
| 790 { | |
| 791 name = "muc#jid"; | |
| 792 type = "jid-single"; | |
| 793 label = "User ID"; | |
| 794 }, | |
| 795 { | |
| 796 name = "muc#roomnick"; | |
| 797 type = "text-single"; | |
| 798 label = "Room Nickname"; | |
| 799 }, | |
| 800 { | |
| 801 name = "muc#role"; | |
| 802 type = "list-single"; | |
| 803 label = "Requested Role"; | |
| 804 value = "participant"; | |
| 805 options = { | |
| 806 "none", | |
| 807 "visitor", | |
| 808 "participant", | |
| 809 "moderator", | |
| 810 }; | |
| 811 }, | |
| 812 { | |
| 813 name = "muc#request_allow"; | |
| 814 type = "boolean"; | |
| 815 label = "Grant voice to this person?"; | |
| 816 value = false; | |
| 817 } | |
| 818 }); | |
| 819 | |
| 820 return form; | |
| 821 end | |
| 822 | |
| 823 function room_mt:process_form(origin, stanza) | 782 function room_mt:process_form(origin, stanza) |
| 824 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); | 783 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); |
| 825 if form.attr.type == "cancel" then | 784 if form.attr.type == "cancel" then |
| 826 origin.send(st.reply(stanza)); | 785 origin.send(st.reply(stanza)); |
| 827 elseif form.attr.type == "submit" then | 786 elseif form.attr.type == "submit" then |
| 1185 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | 1144 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
| 1186 return true; | 1145 return true; |
| 1187 end | 1146 end |
| 1188 | 1147 |
| 1189 local form = stanza:get_child("x", "jabber:x:data"); | 1148 local form = stanza:get_child("x", "jabber:x:data"); |
| 1190 if form and form.attr.type == "submit" then | 1149 local form_type = dataform.get_type(form); |
| 1191 local fields, errors, present = self:get_voice_form_layout():data(form); | 1150 if form_type == "http://jabber.org/protocol/muc#request" then |
| 1192 | 1151 self:handle_role_request(origin, stanza, form); |
| 1193 if fields.FORM_TYPE == "http://jabber.org/protocol/muc#request" then | 1152 return true; |
| 1194 local occupant = self:get_occupant_by_real_jid(stanza.attr.from); | |
| 1195 local event = { | |
| 1196 room = self; | |
| 1197 origin = origin; | |
| 1198 stanza = stanza; | |
| 1199 fields = fields; | |
| 1200 occupant = occupant; | |
| 1201 }; | |
| 1202 if occupant.role == "moderator" then | |
| 1203 module:log("debug", "%s responded to a voice request in %s", jid_resource(occupant.nick), self.jid); | |
| 1204 module:fire_event("muc-voice-response", event); | |
| 1205 else | |
| 1206 module:log("debug", "%s requested voice in %s", jid_resource(occupant.nick), self.jid); | |
| 1207 module:fire_event("muc-voice-request", event); | |
| 1208 end | |
| 1209 return true; | |
| 1210 end | |
| 1211 end | 1153 end |
| 1212 end | 1154 end |
| 1213 end | 1155 end |
| 1214 | 1156 |
| 1215 function room_mt:route_stanza(stanza) -- luacheck: ignore 212 | 1157 function room_mt:route_stanza(stanza) -- luacheck: ignore 212 |
