Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6226:7582deb85812
plugins/muc: Move 'moderated' code to seperate file; changes default "muc-get-default-role" behaviour
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Fri, 18 Apr 2014 12:19:04 -0400 |
parent | 6225:12537f1c1fec |
child | 6227:bb75c011b15e |
comparison
equal
deleted
inserted
replaced
6225:12537f1c1fec | 6226:7582deb85812 |
---|---|
47 return role, valid_roles[role or "none"]; | 47 return role, valid_roles[role or "none"]; |
48 end | 48 end |
49 module:hook("muc-get-default-role", function(event) | 49 module:hook("muc-get-default-role", function(event) |
50 if event.affiliation_rank >= valid_affiliations.admin then | 50 if event.affiliation_rank >= valid_affiliations.admin then |
51 return "moderator"; | 51 return "moderator"; |
52 elseif event.affiliation_rank >= valid_affiliations.member then | 52 elseif event.affiliation_rank >= valid_affiliations.none then |
53 return "participant"; | 53 return "participant"; |
54 end | 54 end |
55 end); | 55 end); |
56 module:hook("muc-get-default-role", function(event) | |
57 if not event.affiliation then | |
58 return event.room:get_moderated() and "visitor" or "participant"; | |
59 end | |
60 end, -1); | |
61 | 56 |
62 --- Occupant functions | 57 --- Occupant functions |
63 function room_mt:new_occupant(bare_real_jid, nick) | 58 function room_mt:new_occupant(bare_real_jid, nick) |
64 local occupant = occupant_lib.new(bare_real_jid, nick); | 59 local occupant = occupant_lib.new(bare_real_jid, nick); |
65 local affiliation = self:get_affiliation(bare_real_jid); | 60 local affiliation = self:get_affiliation(bare_real_jid); |
276 end | 271 end |
277 module:hook("muc-disco#info", function(event) | 272 module:hook("muc-disco#info", function(event) |
278 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up(); | 273 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up(); |
279 end); | 274 end); |
280 module:hook("muc-disco#info", function(event) | 275 module:hook("muc-disco#info", function(event) |
281 event.reply:tag("feature", {var = event.room:get_moderated() and "muc_moderated" or "muc_unmoderated"}):up(); | |
282 end); | |
283 module:hook("muc-disco#info", function(event) | |
284 local count = iterators.count(event.room:each_occupant()); | 276 local count = iterators.count(event.room:each_occupant()); |
285 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); | 277 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); |
286 end); | 278 end); |
287 | 279 |
288 function room_mt:get_disco_items(stanza) | 280 function room_mt:get_disco_items(stanza) |
309 :tag("status", {code = "307"}) | 301 :tag("status", {code = "307"}) |
310 self:publicise_occupant_status(occupant, x); | 302 self:publicise_occupant_status(occupant, x); |
311 return true; | 303 return true; |
312 end | 304 end |
313 | 305 |
314 function room_mt:set_moderated(moderated) | |
315 moderated = moderated and true or nil; | |
316 if self._data.moderated ~= moderated then | |
317 self._data.moderated = moderated; | |
318 if self.save then self:save(true); end | |
319 end | |
320 end | |
321 function room_mt:get_moderated() | |
322 return self._data.moderated; | |
323 end | |
324 | |
325 -- Give the room creator owner affiliation | 306 -- Give the room creator owner affiliation |
326 module:hook("muc-room-pre-create", function(event) | 307 module:hook("muc-room-pre-create", function(event) |
327 event.room:set_affiliation(true, jid_bare(event.stanza.attr.from), "owner"); | 308 event.room:set_affiliation(true, jid_bare(event.stanza.attr.from), "owner"); |
328 end, -1); | 309 end, -1); |
329 | |
330 | 310 |
331 -- check if user is banned | 311 -- check if user is banned |
332 module:hook("muc-occupant-pre-join", function(event) | 312 module:hook("muc-occupant-pre-join", function(event) |
333 local room, stanza = event.room, event.stanza; | 313 local room, stanza = event.room, event.stanza; |
334 local affiliation = room:get_affiliation(stanza.attr.from); | 314 local affiliation = room:get_affiliation(stanza.attr.from); |
600 value = 'http://jabber.org/protocol/muc#roomconfig' | 580 value = 'http://jabber.org/protocol/muc#roomconfig' |
601 } | 581 } |
602 }); | 582 }); |
603 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; | 583 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
604 end | 584 end |
605 module:hook("muc-config-form", function(event) | |
606 table.insert(event.form, { | |
607 name = 'muc#roomconfig_moderatedroom', | |
608 type = 'boolean', | |
609 label = 'Make Room Moderated?', | |
610 value = event.room:get_moderated() | |
611 }); | |
612 end); | |
613 | 585 |
614 function room_mt:process_form(origin, stanza) | 586 function room_mt:process_form(origin, stanza) |
615 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); | 587 local form = stanza.tags[1]:get_child("x", "jabber:x:data"); |
616 if form.attr.type == "cancel" then | 588 if form.attr.type == "cancel" then |
617 origin.send(st.reply(stanza)); | 589 origin.send(st.reply(stanza)); |
649 else | 621 else |
650 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); | 622 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); |
651 end | 623 end |
652 return true; | 624 return true; |
653 end | 625 end |
654 module:hook("muc-config-submitted", function(event) | |
655 event.update_option("moderated", "muc#roomconfig_moderatedroom"); | |
656 end); | |
657 | 626 |
658 -- Removes everyone from the room | 627 -- Removes everyone from the room |
659 function room_mt:clear(x) | 628 function room_mt:clear(x) |
660 x = x or st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); | 629 x = x or st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); |
661 local occupants_updated = {}; | 630 local occupants_updated = {}; |
1117 | 1086 |
1118 local members_only = module:require "muc/members_only"; | 1087 local members_only = module:require "muc/members_only"; |
1119 room_mt.get_members_only = members_only.get; | 1088 room_mt.get_members_only = members_only.get; |
1120 room_mt.set_members_only = members_only.set; | 1089 room_mt.set_members_only = members_only.set; |
1121 | 1090 |
1091 local moderated = module:require "muc/moderated"; | |
1092 room_mt.get_moderated = moderated.get; | |
1093 room_mt.set_moderated = moderated.set; | |
1094 | |
1122 local persistent = module:require "muc/persistent"; | 1095 local persistent = module:require "muc/persistent"; |
1123 room_mt.get_persistent = persistent.get; | 1096 room_mt.get_persistent = persistent.get; |
1124 room_mt.set_persistent = persistent.set; | 1097 room_mt.set_persistent = persistent.set; |
1125 | 1098 |
1126 local subject = module:require "muc/subject"; | 1099 local subject = module:require "muc/subject"; |