Mercurial > prosody-hg
comparison plugins/muc/hidden.lib.lua @ 6233:f400a4cdf352
Merge with daurnimator
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 17 May 2014 18:17:34 +0100 |
| parents | 12537f1c1fec |
| children | 84e01dbb739e |
comparison
equal
deleted
inserted
replaced
| 6178:e12b13a46878 | 6233:f400a4cdf352 |
|---|---|
| 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_hidden(room) | |
| 11 return room._data.hidden; | |
| 12 end | |
| 13 | |
| 14 local function set_hidden(room, hidden) | |
| 15 hidden = hidden and true or nil; | |
| 16 if get_hidden(room) == hidden then return false; end | |
| 17 room._data.hidden = hidden; | |
| 18 if room.save then room:save(true); end | |
| 19 return true; | |
| 20 end | |
| 21 | |
| 22 module:hook("muc-config-form", function(event) | |
| 23 table.insert(event.form, { | |
| 24 name = "muc#roomconfig_publicroom"; | |
| 25 type = "boolean"; | |
| 26 label = "Make Room Publicly Searchable?"; | |
| 27 value = not get_hidden(event.room); | |
| 28 }); | |
| 29 end); | |
| 30 | |
| 31 module:hook("muc-config-submitted", function(event) | |
| 32 local new = event.fields["muc#roomconfig_publicroom"]; | |
| 33 if new ~= nil and set_hidden(event.room, not new) then | |
| 34 event.status_codes["104"] = true; | |
| 35 end | |
| 36 end); | |
| 37 | |
| 38 module:hook("muc-disco#info", function(event) | |
| 39 event.reply:tag("feature", {var = get_hidden(event.room) and "muc_hidden" or "muc_public"}):up(); | |
| 40 end); | |
| 41 | |
| 42 return { | |
| 43 get = get_hidden; | |
| 44 set = set_hidden; | |
| 45 }; |
