Comparison

plugins/muc/moderated.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
parent 7401:e16b3fd0bd80
child 8852:5e98d62f3f9b
comparison
equal deleted inserted replaced
8850:26f1a49fa9c0 8851:ab5f678f1376
4 -- Copyright (C) 2014 Daurnimator 4 -- Copyright (C) 2014 Daurnimator
5 -- 5 --
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
10 local st = require "util.stanza";
11 local dataform = require "util.dataforms";
12
9 13
10 local function get_moderated(room) 14 local function get_moderated(room)
11 return room._data.moderated; 15 return room._data.moderated;
12 end 16 end
13 17
43 return "visitor" 47 return "visitor"
44 end 48 end
45 end 49 end
46 end, 1); 50 end, 1);
47 51
52 module:hook("muc-voice-request", function(event)
53 if event.occupant.role == "visitor" then
54 local form = dataform.new({
55 title = "Voice Request";
56 {
57 name = "FORM_TYPE";
58 type = "hidden";
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
87 local message = st.message({ type = "normal"; from = event.room.jid }):add_child(form:form()):up();
88
89 event.room:broadcast(message, function (nick, occupant)
90 return occupant.role == "moderator";
91 end);
92 end
93 end);
94
95 module:hook("muc-voice-response", function(event)
96 local actor = event.stanza.attr.from;
97 local affected_occupant = event.room:get_occupant_by_real_jid(event.fields["muc#jid"]);
98
99 if event.occupant.role ~= "moderator" then
100 return;
101 end
102
103 if not event.fields["muc#request_allow"] then
104 return;
105 end
106
107 if not affected_occupant then
108 return;
109 end
110
111 if affected_occupant.role == "visitor" then
112 event.room:set_role(actor, affected_occupant.nick, "participant", "Voice granted");
113 end
114 end);
115
116
48 return { 117 return {
49 get = get_moderated; 118 get = get_moderated;
50 set = set_moderated; 119 set = set_moderated;
51 }; 120 };