Mercurial > prosody-hg
comparison plugins/muc/moderated.lib.lua @ 8853:f84f566dea58
MUC: Reuse the same dataform for voice requests
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 20 Oct 2017 05:45:40 +0200 |
| parents | 5e98d62f3f9b |
| children | 5cd7813d4e94 |
comparison
equal
deleted
inserted
replaced
| 8852:5e98d62f3f9b | 8853:f84f566dea58 |
|---|---|
| 6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
| 7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
| 8 -- | 8 -- |
| 9 | 9 |
| 10 local st = require "util.stanza"; | 10 local st = require "util.stanza"; |
| 11 local dataform = require "util.dataforms"; | |
| 12 | |
| 13 | 11 |
| 14 local function get_moderated(room) | 12 local function get_moderated(room) |
| 15 return room._data.moderated; | 13 return room._data.moderated; |
| 16 end | 14 end |
| 17 | 15 |
| 49 end | 47 end |
| 50 end, 1); | 48 end, 1); |
| 51 | 49 |
| 52 module:hook("muc-voice-request", function(event) | 50 module:hook("muc-voice-request", function(event) |
| 53 if event.occupant.role == "visitor" then | 51 if event.occupant.role == "visitor" then |
| 54 local form = dataform.new({ | 52 local form = event.room:get_voice_form_layout() |
| 55 title = "Voice Request"; | 53 local formdata = { |
| 56 { | 54 ["muc#jid"] = event.stanza.attr.from; |
| 57 name = "FORM_TYPE"; | 55 ["muc#roomnick"] = event.occupant.nick; |
| 58 type = "hidden"; | 56 }; |
| 59 value = "http://jabber.org/protocol/muc#request"; | |
| 60 }, | |
| 61 { | |
| 62 name = "muc#role"; | |
| 63 type = "text-single"; | |
| 64 label = "Requested Role"; | |
| 65 value = "participant"; | |
| 66 }, | |
| 67 { | |
| 68 name = "muc#jid"; | |
| 69 type = "jid-single"; | |
| 70 label = "User ID"; | |
| 71 value = event.stanza.attr.from; | |
| 72 }, | |
| 73 { | |
| 74 name = "muc#roomnick"; | |
| 75 type = "text-single"; | |
| 76 label = "Room Nickname"; | |
| 77 value = event.occupant.nick; | |
| 78 }, | |
| 79 { | |
| 80 name = "muc#request_allow"; | |
| 81 type = "boolean"; | |
| 82 label = "Grant voice to this person?"; | |
| 83 value = false; | |
| 84 } | |
| 85 }); | |
| 86 | 57 |
| 87 local message = st.message({ type = "normal"; from = event.room.jid }):add_child(form:form()):up(); | 58 local message = st.message({ type = "normal"; from = event.room.jid }):add_child(form:form(formdata)):up(); |
| 88 | 59 |
| 89 event.room:broadcast(message, function (_, occupant) | 60 event.room:broadcast(message, function (_, occupant) |
| 90 return occupant.role == "moderator"; | 61 return occupant.role == "moderator"; |
| 91 end); | 62 end); |
| 92 end | 63 end |
