Mercurial > prosody-hg
comparison plugins/muc/moderated.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 |
| parents | |
| children | 84e01dbb739e |
comparison
equal
deleted
inserted
replaced
| 6225:12537f1c1fec | 6226:7582deb85812 |
|---|---|
| 1 -- Prosody IM | |
| 2 -- Copyright (C) 2008-2010 Matthew Wild | |
| 3 -- Copyright (C) 2008-2010 Waqas Hussain | |
| 4 -- Copyright (C) 2014 Daurnimator | |
| 5 -- | |
| 6 -- This project is MIT/X11 licensed. Please see the | |
| 7 -- COPYING file in the source package for more information. | |
| 8 -- | |
| 9 | |
| 10 local function get_moderated(room) | |
| 11 return room._data.moderated; | |
| 12 end | |
| 13 | |
| 14 local function set_moderated(room, moderated) | |
| 15 moderated = moderated and true or nil; | |
| 16 if get_moderated(room) == moderated then return false; end | |
| 17 room._data.moderated = moderated; | |
| 18 if room.save then room:save(true); end | |
| 19 return true; | |
| 20 end | |
| 21 | |
| 22 module:hook("muc-disco#info", function(event) | |
| 23 event.reply:tag("feature", {var = get_moderated(event.room) and "muc_moderated" or "muc_unmoderated"}):up(); | |
| 24 end); | |
| 25 | |
| 26 module:hook("muc-config-form", function(event) | |
| 27 table.insert(event.form, { | |
| 28 name = "muc#roomconfig_moderatedroom"; | |
| 29 type = "boolean"; | |
| 30 label = "Make Room Moderated?"; | |
| 31 value = get_moderated(event.room); | |
| 32 }); | |
| 33 end); | |
| 34 | |
| 35 module:hook("muc-config-submitted", function(event) | |
| 36 local new = event.fields["muc#roomconfig_moderatedroom"]; | |
| 37 if new ~= nil and set_moderated(event.room, new) then | |
| 38 event.status_codes["104"] = true; | |
| 39 end | |
| 40 end); | |
| 41 | |
| 42 module:hook("muc-get-default-role", function(event) | |
| 43 if event.affiliation == nil then | |
| 44 if get_moderated(event.room) then | |
| 45 return "visitor" | |
| 46 end | |
| 47 end | |
| 48 end, 1); | |
| 49 | |
| 50 return { | |
| 51 get = get_moderated; | |
| 52 set = set_moderated; | |
| 53 }; |
